]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Provide an initscript targetted at SuSE.
authorVincent Bernat <bernat@luffy.cx>
Sat, 12 Jun 2010 07:29:20 +0000 (09:29 +0200)
committerVincent Bernat <bernat@luffy.cx>
Sat, 12 Jun 2010 08:28:32 +0000 (10:28 +0200)
SysV init scripts are too different between SuSE and
Fedora/RHEL/CentOS to be the same.

Use built-in %_initrddir macro in lldpd.sec.

redhat/lldpd.init
redhat/lldpd.init.suse [new file with mode: 0644]
redhat/lldpd.spec

index dce386ed86565c77c210a7e76c89b59b7951f033..6f518b19f55f58f1f0d6a295f7e322038c40ae16 100644 (file)
 ### END INIT INFO
 
 # source function library
-. /etc/init.d/functions
-
+. /etc/rc.d/init.d/functions
 
 LLDPD_OPTIONS=""
-if [ -e /etc/sysconfig/lldpd ]; then
-  . /etc/sysconfig/lldpd
-fi
+[ -e /etc/sysconfig/lldpd ] && . /etc/sysconfig/lldpd
 
 RETVAL=0
 prog="lldpd"
 binary=/usr/sbin/lldpd
 pidfile=/var/run/lldpd.pid
 chroot=/var/run/lldpd
+lockfile=/var/lock/subsys/$prog
 
 build_chroot()
 {
@@ -54,7 +52,7 @@ start() {
                build_chroot
                 daemon --pidfile=$pidfile $binary $LLDPD_OPTIONS
                 RETVAL=$?
-                [ $RETVAL -eq 0 ] && touch /var/lock/subsys/lldpd
+                [ $RETVAL -eq 0 ] && touch $lockfile
         fi;
         echo 
         return $RETVAL
@@ -68,36 +66,34 @@ stop() {
         else
                 killproc -p $pidfile $binary
                 RETVAL=$?
-                [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/lldpd
+                [ $RETVAL -eq 0 ] && rm -f $lockfile
         fi;
         echo
         return $RETVAL
 }
 
-reload(){
-        echo -n $"Reloading $prog: "
-        killproc -p $pidfile $binary -HUP
-        RETVAL=$?
-        echo
-        return $RETVAL
-}
-
 restart(){
        stop
        start
 }
 
 condrestart(){
-    [ -e /var/lock/subsys/lldpd ] && restart
+    [ -e $lockfile ] && restart
     return 0
 }
 
+rh_status_q(){
+    status $prog >/dev/null 2>&1
+}
+
 case "$1" in
   start)
+       rh_status_q && exit 0
        start
        RETVAL=$?
        ;;
   stop)
+       rh_status_q || exit 0
        stop
        RETVAL=$?
        ;;
@@ -106,19 +102,24 @@ case "$1" in
        RETVAL=$?
         ;;
   reload)
-       reload
+        rh_status_q || exit 7
+       exit 3
+        ;;
+  force-reload)
+       restart
        RETVAL=$?
         ;;
   condrestart|try-restart)
+        rh_status_q || exit 0
        condrestart
        RETVAL=$?
        ;;
   status)
-        status lldpd
+        status $prog
        RETVAL=$?
         ;;
   *)
-       echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
+       echo $"Usage: $0 {start|stop|status|restart|condrestart|force-reload}"
        RETVAL=2
 esac
 
diff --git a/redhat/lldpd.init.suse b/redhat/lldpd.init.suse
new file mode 100644 (file)
index 0000000..ac51e22
--- /dev/null
@@ -0,0 +1,97 @@
+#!/bin/sh
+
+### BEGIN INIT INFO
+# Provides: lldpd
+# Required-Start: $local_fs $remote_fs
+# Required-Stop: $local_fs $remote_fs
+# Should-Start: $syslog $network $net-snmp
+# Should-Stop: $syslog $network $net-snmp
+# Default-Start: 3 5
+# Default-Stop: 0 1 2 6
+# Short-Description: LLDP daemon
+# Description: 802.1ab (LLDP) daemon
+### END INIT INFO
+
+
+# Check for missing binaries (stale symlinks should not happen)
+# Note: Special treatment of stop for LSB conformance
+LLDPD_BIN=/usr/sbin/lldpd
+test -x $LLDPD_BIN || { echo "$LLDPD_BIN not installed"; 
+       if [ "$1" = "stop" ]; then exit 0;
+       else exit 5; fi; }
+
+# Check for existence of needed config file and read it
+LLDPD_CONFIG=/etc/sysconfig/lldpd
+test -r $LLDPD_CONFIG || { echo "$LLDPD_CONFIG not existing";
+       if [ "$1" = "stop" ]; then exit 0;
+       else exit 6; fi; }
+
+# Read config  
+. $LLDPD_CONFIG
+
+. /etc/rc.status
+
+# Reset status of this service
+rc_reset
+
+chroot=/var/run/lldpd
+build_chroot()
+{
+        oldumask=$(umask)
+        umask 022
+        [ -d $chroot/etc ] || mkdir -p $chroot/etc
+        [ -f $chroot/etc/localtime ] || [ ! -f /etc/localtime ] || \
+                cp /etc/localtime $chroot/etc/localtime
+        umask $oldumask
+}
+
+case "$1" in
+    start)
+       echo -n "Starting lldpd "
+       build_chroot
+       /sbin/startproc $LLDPD_BIN
+       rc_status -v
+       ;;
+    stop)
+       echo -n "Shutting down lldpd "
+       /sbin/killproc -TERM $LLDPD_BIN
+       rc_status -v
+       ;;
+    try-restart|condrestart)
+       $0 status
+       if test $? = 0; then
+               $0 restart
+       else
+               rc_reset        # Not running is not a failure.
+       fi
+       rc_status
+       ;;
+    restart)
+       $0 stop
+       $0 start
+
+       rc_status
+       ;;
+    force-reload)
+       $0 try-restart
+       rc_status
+       ;;
+    reload)
+       # Does not support reload
+       rc_failed 3
+       rc_status -v
+       ;;
+    status)
+       echo -n "Checking for service lldpd "
+       /sbin/checkproc $LLDPD_BIN
+       rc_status -v
+       ;;
+    probe)
+       ;;
+    *)
+       echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
+       exit 1
+       ;;
+esac
+rc_exit
+
index d933e3f2a453c365956163a766b236b34766e513..d2f4379c3c131f1b7255bf0365a117d2ccb1689c 100644 (file)
@@ -34,7 +34,7 @@ License: MIT
 Group: System Environment/Daemons
 URL: https://trac.luffy.cx/lldpd/
 Source0: http://www.luffy.cx/lldpd/%{name}-%{version}.tar.gz 
-Source1: lldpd.init
+Source1: lldpd.init%{?suse_version:.suse}
 Source2: lldpd.sysconfig
 
 %if %{with snmp}
@@ -47,6 +47,11 @@ BuildRequires: libxml2-devel
 %endif
 %if 0%{?suse_version}
 PreReq: %fillup_prereq %insserv_prereq pwdutils
+%else
+Requires(post): chkconfig
+Requires(preun): chkconfig
+Requires(preun): initscripts
+Requires(postun): initscripts
 %endif
 
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@@ -119,12 +124,11 @@ protocol. It also handles LLDP-MED extension.
 [ -f /usr/include/net-snmp/agent/struct.h ] || touch src/struct.h
 make %{?_smp_mflags}
 
-%define _initdir %{?suse_version:/etc/init.d}%{!?suse_version:/etc/rc.d/init.d}
 %install
 make install DESTDIR=$RPM_BUILD_ROOT
 install -d -m770  $RPM_BUILD_ROOT/%lldpd_chroot
-install -d $RPM_BUILD_ROOT/%{_initdir}
-install -m755 %{SOURCE1} $RPM_BUILD_ROOT/%{_initdir}/lldpd
+install -d $RPM_BUILD_ROOT/%{_initrddir}
+install -m755 %{SOURCE1} $RPM_BUILD_ROOT/%{_initrddir}/lldpd
 %if 0%{?suse_version}
 mkdir -p ${RPM_BUILD_ROOT}/var/adm/fillup-templates
 install -m700 %{SOURCE2} ${RPM_BUILD_ROOT}/var/adm/fillup-templates/sysconfig.lldpd
@@ -161,10 +165,11 @@ if getent passwd %lldpd_user >/dev/null 2>&1 ; then : ; else \
 /sbin/chkconfig --add lldpd
 %postun
 if [ "$1" -ge  "1" ]; then
-   %{_initdir}/lldpd  condrestart >/dev/null 2>&1
+   /sbin/service lldpd >/dev/null 2>&1 || :
 fi
 %preun
 if [ "$1" = "0" ]; then
+   /sbin/service lldpd stop > /dev/null 2>&1
    /sbin/chkconfig --del lldpd
 fi
 
@@ -182,8 +187,8 @@ rm -rf $RPM_BUILD_ROOT
 %_sbindir/lldpctl
 %doc %_mandir/man8/lldp*
 %dir %attr(750,root,root) %lldpd_chroot
-%config %{_initdir}/lldpd
-%attr(755,root,root) %{_initdir}/*
+%config %{_initrddir}/lldpd
+%attr(755,root,root) %{_initrddir}/*
 %if 0%{?suse_version}
 %attr(644,root,root) /var/adm/fillup-templates/sysconfig.lldpd
 %else
@@ -195,8 +200,9 @@ rm -rf $RPM_BUILD_ROOT
 - New upstream version
 - Define bcond_without and with macros if not defined to be compatible
   with RHEL
-- Requires useradd and groupadd.
+- Requires useradd and groupadd
 - Adapt to make it work with SuSE
+- Provide an init script targetted at SuSE
 - Build require lm_sensors-devel on RHEL
 
 * Fri Mar 12 2010 Vincent Bernat <bernat@luffy.cx> - 0.5.0-1