]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - rc.d/init.d/template.init
- sample for status with pidfile
[projects/rc-scripts.git] / rc.d / init.d / template.init
index 7c454f5af2045d8ad24c23d96dee7c29a13a8d07..7123df9a78531271ee8253171a67b3e03aa53cd8 100644 (file)
@@ -6,15 +6,28 @@
 #
 # description: <service> long service description
 #
+# processname: <service>
+# config:
+# pidfile:
+#
 # $Id$
 
-
 # Source function library
 . /etc/rc.d/init.d/functions
 
 # Get network config
 . /etc/sysconfig/network
 
+# Check that networking is up.
+if is_yes "${NETWORKING}"; then
+       if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+               msg_network_down "<service_name>"
+               exit 1
+       fi
+else
+       exit 0
+fi
+
 # Set defaults
 OPTION1=""     # Strings
 OPTION2="-q"   #
@@ -24,82 +37,134 @@ OPTION4=5  #
 # Get service config - may override defaults
 [ -f /etc/sysconfig/<service> ] && . /etc/sysconfig/<service>
 
-# Check that networking is up.
-if is_yes "${NETWORKING}"; then
-       if [ ! -f /var/lock/subsys/network ]; then
-               # nls "ERROR: Networking is down. %s can't be run." <service>
-               msg_network_down <service>
-               exit 1
+# configtest itself
+# must return non-zero if check failed
+# output is discarded if checkconfig is ran without details
+configtest() {
+       /usr/sbin/<service> -t
+       return $?
+}
+
+# wrapper for configtest
+checkconfig() {
+       local details=${1:-0}
+
+       if [ $details = 1 ]; then
+               # run config test and display report (status action)
+               show "Checking %s configuration" "<service_name>"; busy
+               local out
+               out=$(configtest 2>&1)
+               RETVAL=$?
+               if [ $RETVAL = 0 ]; then
+                       ok
+               else
+                       fail
+               fi
+               [ "$out" ] && echo >&2 "$out"
+       else
+               # run config test and abort with nice message if failed
+               # (for actions checking status before action).
+               configtest >/dev/null 2>&1
+               RETVAL=$?
+               if [ $RETVAL != 0 ]; then
+                       show "Checking %s configuration" "<service_name>"; fail
+                       nls 'Configuration test failed. See details with %s "checkconfig"' $0
+                       exit $RETVAL
+               fi
+       fi
+}
+
+start() {
+       # Check if the service is already running?
+       if [ -f /var/lock/subsys/<service> ]; then
+               msg_already_running "<service_name>"
+               return
+       fi
+
+       checkconfig
+       msg_starting "<service_name>"
+       daemon /usr/sbin/<service>
+       RETVAL=$?
+       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/<service>
+}
+
+stop() {
+       if [ ! -f /var/lock/subsys/<service> ]; then
+               msg_not_running "<service_name>"
+               return
+       fi
+
+       # Stop daemons.
+       msg_stopping "<service_name>"
+       killproc <service>
+       killproc --pidfile /var/run/<service>.pid <service> -TERM
+       rm -f /var/lock/subsys/<service>
+}
+
+reload() {
+       if [ ! -f /var/lock/subsys/<service> ]; then
+               msg_not_running "<service_name>"
+               RETVAL=7
+               return
        fi
-else
-       exit 0
-fi
 
+       checkconfig
+       msg_reloading "<service_name>"
+       killproc <service> -HUP
+       killproc --pidfile /var/run/<service>.pid <service> -HUP
+       RETVAL=$?
+}
 
+condrestart() {
+       if [ ! -f /var/lock/subsys/<service> ]; then
+               msg_not_running "<service_name>"
+               RETVAL=$1
+               return
+       fi
+
+       checkconfig
+       stop
+       start
+}
+
+RETVAL=0
 # See how we were called.
 case "$1" in
   start)
-       # Check if the service is already running?
-       if [ ! -f /var/lock/subsys/<service> ]; then
-               # show "Starting %s service" <service>
-               msg_starting <service>
-               daemon <service>
-               RETVAL=$?
-               [ $RETVAL -eq 0 ] && touch /var/lock/subsys/<service>
-       else
-               # show "%s service is already running." <service>
-               msg_already_running <service>
-       fi
+       start
        ;;
   stop)
-       if [ -f /var/lock/subsys/<service> ]; then
-               # Stop daemons.
-               # show "Stopping %s service" <service>
-               msg_stopping <service>
-               killproc <service>
-               rm -f /var/lock/subsys/<service>
-       else
-               # show "%s service is not running." <service>
-               msg_not_running <service>
-       fi
+       stop
        ;;
   restart)
-       $0 stop
-       $0 start
-       exit $?
+       checkconfig
+       stop
+       start
        ;;
-  reload)
-       if [ -f /var/lock/subsys/<service> ]; then
-               # show "Reload %s service" <service>
-               msg_reloading <service>
-               killproc <service> -HUP
-               RETVAL=$?
-       else
-               # show "%s service is not running." <service>
-               msg_not_running <service> >&2
-               RETVAL=7
-       fi
+  try-restart)
+       condrestart 0
        ;;
+# include force-reload here if program allows reloading without restart
+# otherwise remove reload action and support force-reload as restart if running
+  reload|force-reload)
+       reload
+       ;;
+# use this one if program doesn't support reloading without restart
   force-reload)
-       # if program allows reloading without stopping
-       $0 reload
-
-       # or if it doesn't
-       $0 restart
-
-       exit $?
+       condrestart 7
+       ;;
+  checkconfig|configtest)
+       checkconfig 1
        ;;
   status)
        status <service>
+       status --pidfile /var/run/<service>.pid <service>
+       status --pidfile /var/run/<service>.pid <service> <procname>
        RETVAL=$?
        ;;
   *)
-       # show "Usage: %s {start|stop|restart|reload|force-reload|status}"
-       msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
+       msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
        exit 3
 esac
 
 exit $RETVAL
-
-# This must be last line !
-# vi:syntax=sh:ts=8:sw=4
This page took 0.036524 seconds and 4 git commands to generate.