]> granicus.if.org Git - sysstat/commitdiff
Sysstat init script updated to make it more conforming to LSB.
authorseb <seb@kluane.home>
Mon, 3 Sep 2012 14:26:33 +0000 (16:26 +0200)
committerseb <seb@kluane.home>
Mon, 3 Sep 2012 14:26:33 +0000 (16:26 +0200)
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.

CHANGES
sysstat.in

diff --git a/CHANGES b/CHANGES
index 073c319ae4de2e3ddb5dfbb58250e6eec4a028ef..df98806166845337a8e344f074afb034523f4701 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
 Changes:
 
 xxxx/xx/xx: Version 10.1.2 - Sebastien Godard (sysstat <at> 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 <at> orange.fr)
index 301f6d9408478182797973733dac7dd0f83a4a4b..a16b8ba28d26fc9bcfad6f16ccbce60f6376ba1a 100644 (file)
@@ -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 <at> 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
 #@(#)   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}