From: seb Date: Mon, 3 Sep 2012 14:26:33 +0000 (+0200) Subject: Sysstat init script updated to make it more conforming to LSB. X-Git-Tag: v10.1.2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0d9d19c5c4cf7a104a9c66122314db1a9808519f;p=sysstat Sysstat init script updated to make it more conforming to LSB. Sysstat init script updated: * instead of temp file, use /var/run/sysstat.pid file * check user privileges on start and stop (even though stop does nothing) * status command works "correctly" (of course it will always return 3 - service is not running, but for the love of the standards..) Mail from Peter Schiffer (pschiffe@redhat.com) 08/08/2012: I was looking into sysstats init script, and here are few things I found out: * init scripts are usually run with root privileges (at least on system start). But then: mktemp command is run under root (line 24 in init script), and if @SU_C_OWNER@ is set and sa1 script fails, then @SU_C_OWNER@ won't have privileges to remove the temp file. example: $ sudo mktemp /tmp/sysstat-XXXXXX /tmp/sysstat-PcSXFW $ rm -f /tmp/sysstat-PcSXFW rm: cannot remove `/tmp/sysstat-PcSXFW': Operation not permitted Also, in this case, condition on line 31 is useless. * it looks like, that comment starting on line 28 is no true (or, at least, anymore). I did a little test (which is attached). In one script, there is command "exit 17", and another script is calling the first via exec. Now, just run: $ whoami schiffer $ su schiffer -c ./sc Password: $ echo $? 17 So, you can see two things: the exit code is not lost, and even I call "su user -c" on myself, I need to enter my password. The latter can be confusing if @SU_C_OWNER@ is not me, etc.. So.. what I am trying to show: * command "service sysstat start" should only be called with root privileges * we can use exit code of command run under "su foo -c ..." (...) Now, the init script should be more conforming to LSB (according to the [1]). I'm also attaching output of our internal LSB init script test. --- diff --git a/CHANGES b/CHANGES index 073c319..df98806 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ Changes: xxxx/xx/xx: Version 10.1.2 - Sebastien Godard (sysstat orange.fr) + * [Peter Schiffer]: Sysstat init script updated to make it + more conforming to LSB. * sar and sadf manual pages updated. 2012/07/29: Version 10.1.1 - Sebastien Godard (sysstat orange.fr) diff --git a/sysstat.in b/sysstat.in index 301f6d9..a16b8ba 100644 --- a/sysstat.in +++ b/sysstat.in @@ -1,6 +1,8 @@ #!/bin/sh # # chkconfig: 12345 01 99 +# description: Reset the system activity logs +# # @INIT_DIR@/sysstat # (C) 2000-2011 Sebastien Godard (sysstat orange.fr) # @@ -8,7 +10,8 @@ # Provides: sysstat # Required-Start: # Required-Stop: -# Default-Stop: +# Default-Start: 1 2 3 4 5 +# Default-Stop: 0 6 # Description: Reset the system activity logs # Short-Description: Reset the system activity logs ### END INIT INFO @@ -17,29 +20,35 @@ #@(#) This indicates that the counters have restarted from 0. RETVAL=0 +PIDFILE=/var/run/sysstat.pid # See how we were called. case "$1" in start) - exitCodeIndicator="$(mktemp /tmp/sysstat-XXXXXX)" || exit 1 - echo -n "Calling the system activity data collector (sadc): " - @SU_C_OWNER@ @QUOTE@ @SA_LIB_DIR@/sa1 --boot || rm -f ${exitCodeIndicator} @QUOTE@ - - # Try to guess if sadc was successfully launched. The difficulty - # here is that the exit code is lost when the above command is - # run via "su foo -c ..." - if [ -f "${exitCodeIndicator}" ]; then - rm -f ${exitCodeIndicator} - else - RETVAL=2 - fi + [ $UID -eq 0 ] || exit 4 + echo $$ > $PIDFILE || exit 1 + echo -n "Calling the system activity data collector (sadc)... " + @SU_C_OWNER@ @QUOTE@ @SA_LIB_DIR@/sa1 --boot @QUOTE@ + [ $? -eq 0 ] || RETVAL=1 + rm -f $PIDFILE echo ;; - stop|status|restart|reload|force-reload|condrestart|try-restart) + + status) + [ -f $PIDFILE ] || RETVAL=3 + ;; + + stop) + [ $UID -eq 0 ] || exit 4 + ;; + + restart|reload|force-reload|condrestart|try-restart) ;; + *) echo "Usage: sysstat {start|stop|status|restart|reload|force-reload|condrestart|try-restart}" - exit 2 + RETVAL=2 esac + exit ${RETVAL}