[Pkg-sysvinit-commits] r210 - in sysvinit/trunk/debian: . initscripts/etc/init.d

Thomas Hood jdthood-guest at costa.debian.org
Tue Nov 22 23:31:33 UTC 2005


Author: jdthood-guest
Date: 2005-11-22 23:31:31 +0000 (Tue, 22 Nov 2005)
New Revision: 210

Modified:
   sysvinit/trunk/debian/changelog
   sysvinit/trunk/debian/initscripts/etc/init.d/skeleton
Log:
Improve skeleton initscript

Modified: sysvinit/trunk/debian/changelog
===================================================================
--- sysvinit/trunk/debian/changelog	2005-11-22 23:02:26 UTC (rev 209)
+++ sysvinit/trunk/debian/changelog	2005-11-22 23:31:31 UTC (rev 210)
@@ -13,6 +13,7 @@
   * Clean up indentation and formatting of all initscripts
   * Eliminate use of dir_writable from checkroot.sh and mountvirtfs in
     order to please selinux  (Closes: #333836)
+  * Improve skeleton initscript
 
  -- Petter Reinholdtsen <pere at debian.org>  Sat, 19 Nov 2005 21:11:34 +0100
 

Modified: sysvinit/trunk/debian/initscripts/etc/init.d/skeleton
===================================================================
--- sysvinit/trunk/debian/initscripts/etc/init.d/skeleton	2005-11-22 23:02:26 UTC (rev 209)
+++ sysvinit/trunk/debian/initscripts/etc/init.d/skeleton	2005-11-22 23:31:31 UTC (rev 210)
@@ -15,92 +15,132 @@
 # Please remove the "Author" lines above and replace them
 # with your own name if you copy and modify this script.
 
-set -e
-
-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-DESC="some daemon"
-NAME=daemon
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+DESC="Description of the service"
+NAME=daemonexecutablename
 DAEMON=/usr/sbin/$NAME
+DAEMON_ARGS="--options touse"
 PIDFILE=/var/run/$NAME.pid
 SCRIPTNAME=/etc/init.d/$NAME
 
-# Gracefully exit if the package has been removed.
+# Exit if the package is not installed
 test -x $DAEMON || exit 0
 
-# Read config file if it is present.
+# Read configuration variable file if it is present
 #if [ -r /etc/default/$NAME ]
 #then
 #	. /etc/default/$NAME
 #fi
 
 #
-# Function that starts the daemon/service.
+# Function that starts the daemon/service
 #
-d_start() {
-	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
-		|| echo -n " already running"
+do_start()
+{
+	# Return
+	#   0 if daemon has been started
+	#   1 if daemon was already running
+	#   2 if daemon could not be started
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 1
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
+		$DAEMON_ARGS
+		|| return 2
+	# Add code here, if necessary, that waits for the process to be ready
+	# to handle requests from services started subsequently which depend
+	# on this one.  As a last resort, sleep for some time.
 }
 
 #
-# Function that stops the daemon/service.
+# Function that stops the daemon/service
 #
-d_stop() {
-	start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME \
-		|| echo -n " not running"
+do_stop()
+{
+	# Return
+	#   0 if daemon has been stopped
+	#   1 if daemon was already stopped
+	#   2 if daemon could not be stopped
+	#   other if a failure occurred
+	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+	RETVAL="$?"
+	[ "$RETVAL" = 2 ] && return 2
+	# Wait for children to finish too if this is a daemon that forks
+	# and if the daemon is only ever run from this initscript.
+	# If the above conditions are not satisfied then add some other code
+	# that waits for the process to drop all resources that could be
+	# needed by services started subsequently.  A last resort is to
+	# sleep for some time.
+	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+	[ "$?" = 2 ] && return 2
+	# Many daemons don't delete their pidfiles when they exit.
+	rm -f $PIDFILE
+	return "$RETVAL"
 }
 
 #
-# Function that sends a SIGHUP to the daemon/service.
+# Function that sends a SIGHUP to the daemon/service
 #
-d_reload() {
+do_reload() {
+	#
+	# If the daemon can reload its configuration without
+	# restarting (for example, when it is sent a SIGHUP),
+	# then implement that here.
+	#
 	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
+	return 0
 }
 
 case "$1" in
   start)
-	echo -n "Starting $DESC: $NAME"
-	d_start
-	echo "."
+	log_daemon_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0|1) log_end_msg 0 ;;
+		2) log_end_msg 1 ;;
+	esac
 	;;
   stop)
-	echo -n "Stopping $DESC: $NAME"
-	d_stop
-	echo "."
+	log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0|1) log_end_msg 0 ;;
+		2) log_end_msg 1 ;;
+	esac
 	;;
-  #reload)
+  #reload|force-reload)
 	#
-	# If the daemon can reload its configuration without
-	# restarting (for example, when it is sent a SIGHUP),
-	# then implement that here.
+	# If do_reload() is not implemented then leave this commented out
+	# and leave 'force-reload' as an alias for 'restart'.
 	#
-	# If the daemon responds to changes in its config file
-	# directly anyway, make this an "exit 0".
-	#
-	#echo -n "Reloading $DESC configuration..."
-	#d_reload
-	#echo "done."
+	#log_daemon_msg "Reloading $DESC" "$NAME"
+	#do_reload
+	#log_end_msg $?
 	#;;
   restart|force-reload)
 	#
-	# If the "reload" option is implemented, move the "force-reload"
-	# option to the "reload" entry above. If not, "force-reload" is
-	# just the same as "restart".
+	# If the "reload" option is implemented then remove the
+	# 'force-reload' alias
 	#
-	echo -n "Restarting $DESC: $NAME"
-	d_stop
-	# One second might not be time enough for a daemon to stop, 
-	# if this happens, d_start will fail (and dpkg will break if 
-	# the package is being upgraded). Change the timeout if needed
-	# be, or change d_stop to have start-stop-daemon use --retry. 
-	# Notice that using --retry slows down the shutdown process somewhat.
-	sleep 1
-	d_start
-	echo "."
+	log_daemon_msg "Restarting $DESC" "$NAME"
+	do_stop
+	case "$?" in
+	  0|1)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			1) log_end_msg 1 ;; # Old process is still running
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+		log_end_msg 1 ;; # Failed to stop
+		;;
+	esac
 	;;
   *)
+	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
 	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
 	exit 3
 	;;
 esac
 
-exit 0




More information about the Pkg-sysvinit-commits mailing list