From c06a19f9ff66b59402c2d2465e9a8c0a602893aa Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 26 Jul 2011 17:13:40 +0200 Subject: [PATCH] replace SysV initscript with systemd service (#717419) --- gpsd.init | 93 ---------------------------------------------------- gpsd.service | 12 +++++++ gpsd.spec | 27 ++++++++------- 3 files changed, 27 insertions(+), 105 deletions(-) delete mode 100644 gpsd.init create mode 100644 gpsd.service diff --git a/gpsd.init b/gpsd.init deleted file mode 100644 index 85fab36..0000000 --- a/gpsd.init +++ /dev/null @@ -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 diff --git a/gpsd.service b/gpsd.service new file mode 100644 index 0000000..c481908 --- /dev/null +++ b/gpsd.service @@ -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 diff --git a/gpsd.spec b/gpsd.spec index 3825e7f..afab223 100644 --- a/gpsd.spec +++ b/gpsd.spec @@ -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*