replace SysV initscript with systemd service (#717419)

This commit is contained in:
Miroslav Lichvar 2011-07-26 17:13:40 +02:00
parent 33666ceafa
commit c06a19f9ff
3 changed files with 27 additions and 105 deletions

View File

@ -1,93 +0,0 @@
#!/bin/sh
#
# gpsd Service daemon for mediating access to a GPS
#
# chkconfig: - 44 66
# description: gpsd is a service daemon that mediates access to a GPS sensor \
# connected to the host computer by serial or USB interface, \
# making its data on the location/course/velocity of the sensor \
# available to be queried on TCP port 2947 of the host computer.
# processname: gpsd
# pidfile: /var/run/gpsd.pid
# http://fedoraproject.org/wiki/FCNewInit/Initscripts
### BEGIN INIT INFO
# Provides: gpsd
# Required-Start: network
# Required-Stop: network
# Should-Start:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Service daemon for mediating access to a GPS
# Description: gpsd is a service daemon that mediates access to a GPS sensor
# connected to the host computer by serial or USB interface, making its
# data on the location/course/velocity of the sensor available to be
# queried on TCP port 2947 of the host computer.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
exec="/usr/sbin/gpsd"
prog=$(basename $exec)
PIDFILE=/var/run/gpsd.pid
CONTROL_SOCKET=/var/run/gpsd.sock
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
: ${OPTIONS:=-n}
: ${DEVICE:=/dev/ttyUSB0}
lockfile=/var/lock/subsys/$prog
start() {
[ "$EUID" != "0" ] && exit 4
echo -n $"Starting $prog: "
daemon $exec -P $PIDFILE -F $CONTROL_SOCKET $OPTIONS $DEVICE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
[ "$EUID" != "0" ] && exit 4
echo -n $"Stopping $prog: "
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
case "$1" in
start|stop|restart)
$1
;;
force-reload)
restart
;;
status)
status $prog
;;
try-restart|condrestart)
if status $prog >/dev/null ; then
restart
fi
;;
reload)
status $prog >/dev/null || exit 7
# If config can be reloaded without restarting, implement it here,
# remove the "exit", and add "reload" to the usage message below.
action $"Service $prog does not support the reload action: " /bin/false
exit 3
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
exit 2
esac

12
gpsd.service Normal file
View File

@ -0,0 +1,12 @@
[Unit]
Description=GPS Service Daemon
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/gpsd.pid
EnvironmentFile=-/etc/sysconfig/gpsd
ExecStart=/usr/sbin/gpsd -P /var/run/gpsd.pid -F /var/run/gpsd.sock $OPTIONS $DEVICE
[Install]
WantedBy=multi-user.target

View File

@ -9,7 +9,7 @@ Group: System Environment/Daemons
License: BSD
URL: http://developer.berlios.de/projects/gpsd/
Source0: http://download.berlios.de/gpsd/%{name}-%{version}.tar.gz
Source10: gpsd.init
Source10: gpsd.service
Source11: gpsd.sysconfig
Patch0: gpsd-2.95-silentmake.patch
Patch1: gpsd-2.95-hotplugvars.patch
@ -24,10 +24,8 @@ BuildRequires: desktop-file-utils
Requires: %{name}-libs = %{version}-%{release}
Requires: udev
Requires(post): /sbin/ldconfig
Requires(post): /sbin/chkconfig
Requires(preun): initscripts
Requires(preun): /sbin/chkconfig
Requires(post): /sbin/ldconfig systemd-units
Requires(preun): systemd-units
Requires(postun): /sbin/ldconfig
%description
@ -97,10 +95,10 @@ make %{?_smp_mflags}
rm -rf %{buildroot}
make DESTDIR=%{buildroot} pythondir=%{python_sitearch} install
# init scripts
%{__install} -d -m 0755 %{buildroot}%{_sysconfdir}/init.d
# service files
%{__install} -d -m 0755 %{buildroot}/lib/systemd/system
%{__install} -p -m 0755 %{SOURCE10} \
%{buildroot}%{_sysconfdir}/init.d/gpsd
%{buildroot}/lib/systemd/system/gpsd.service
%{__install} -d -m 0755 %{buildroot}%{_sysconfdir}/sysconfig
%{__install} -p -m 0644 %{SOURCE11} \
@ -142,13 +140,18 @@ rm -rf %{buildroot}
%post
/sbin/ldconfig
/sbin/chkconfig --add %{name}
/bin/systemctl daemon-reload &> /dev/null
if [ -f %{_initrddir}/%{name} ] && /sbin/chkconfig --level 3 %{name}; then
/bin/systemctl enable %{name}.service &> /dev/null
fi
:
%preun
if [ $1 = 0 ]; then
/sbin/service %{name} stop > /dev/null 2>&1 || true
/sbin/chkconfig --del %{name}
/bin/systemctl --no-reload disable %{name}.service &> /dev/null
/bin/systemctl stop %{name}.service &> /dev/null
fi
:
%postun -p /sbin/ldconfig
@ -156,13 +159,13 @@ fi
%files
%defattr(-,root,root,-)
%doc README INSTALL COPYING
%config(noreplace) %{_sysconfdir}/init.d/%{name}
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%config(noreplace) %{_sysconfdir}/udev/rules.d/*
%{_sbindir}/gpsd
%{_bindir}/gpsprof
%{_bindir}/gpsmon
%{_bindir}/gpsctl
/lib/systemd/system/gpsd.service
/lib/udev/gpsd*
%{_mandir}/man8/gpsd.8*
%{_mandir}/man1/gpsprof.1*