[Debpool-commits] [SCM] Debpool Project Repository branch, master, updated. 0.2.3-63-g38a32aa

ceros-guest ceros-guest at alioth.debian.org
Tue Jun 3 07:06:58 UTC 2008


The following commit has been merged in the master branch:
commit 6aae732d73fd7210fb08181302740c59131a4b6a
Author: ceros-guest <ceros-guest>
Date:   Wed Jan 9 20:41:07 2008 +0000

    Rewrote init scripts to base them off of /etc/init.d/skeleton

diff --git a/debian/changelog b/debian/changelog
index abd20dd..cf90fc0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -28,8 +28,8 @@ debpool (0.2.4~unreleased0) experimental; urgency=low
   * Added init script for running debpool. Closes: #415639
     + Thanks Magnus Holmgren.
     + Also added option for debpool to print lockfile path.
-    + Also adding logs to /var/log/debpool.log.
     + init scripts needed slight modification to get them running with root.
+    + Scripts were rewritten to base them off of /etc/init.d/skeleton.
   * Fixed problem where debpool doesn't recover from power failure.
     + Closes: #412090
   * Fixed problem with debpool not reaping its gzip children. Closes: #415204
diff --git a/debian/debpool.default b/debian/debpool.default
index debfd34..a5fcc76 100644
--- a/debian/debpool.default
+++ b/debian/debpool.default
@@ -1,28 +1,19 @@
 # Configuration file for debpool init script. This is a shell script
 # sourced from /etc/init.d/debpool
 
-# Change to 1 to enable running debpool as a daemon.
-
-ENABLED=0
+# Change to anything except "0" to enable running debpool as a daemon.
+ENABLED="0"
 
 # Parameters passed to debpool. See DebPool::Config(5). You don't have
 # to specify --daemon.
-
 OPTIONS=""
 
 # User or user:group to run debpool as. If you leave it empty, debpool
 # will run as root.
-
-USER=""
+DEBPOOL_USER=""
 
 # Specify a path for the log file
-# For example: LOGFILE="--log_file /var/log/debpool.log"
-
-LOGFILE="--log_file /var/log/debpool.log"
-
-# Specify a path to use for the lockfile.
-# For example: LOCKPATH="--lock_file /var/run/debpool.pid"
-# If you leave this empty, debpool will use the default path set by
-# DebPool::Config.pm.
+LOGFILE="/var/log/debpool/$NAME.log"
 
-LOCKPATH=""
+# Specify a path for the lock file
+LOCKFILE="/var/run/debpool/$NAME.pid"
diff --git a/debian/debpool.init b/debian/debpool.init
index ab3eecc..4405cc8 100644
--- a/debian/debpool.init
+++ b/debian/debpool.init
@@ -6,84 +6,181 @@
 # Required-Stop:   $local_fs $remote_fs
 # Default-Start:   2 3 4 5
 # Default-Stop:    0 1 6
-# Short-Description: Start Debian package archiver
+# Short-Description: Debian package archiver
 ### END INIT INFO
 
-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+# Basing script off of /etc/init.d/skeleton
+
+PATH=/usr/sbin:/usr/bin:/sbin:/bin
+DESC="Debian package archiver"
 NAME=debpool
 DAEMON=/usr/bin/$NAME
+SCRIPTNAME=/etc/init.d/$NAME
 DEFAULT=/etc/default/$NAME
-DESC="Debian package archiver"
-test -x $DAEMON || exit 0
 
-. /lib/lsb/init-functions
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
 
-# Include debpool defaults if available
-if [ -f $DEFAULT ]; then
-	. $DEFAULT
-fi
+# Read configuration variable file if it is present
+[ -r $DEFAULT ] && . $DEFAULT
+
+# Define LSB log_* functions.
+. /lib/lsb/init-functions
 
+# Check if daemon is enabled in default configuration
 if [ "$ENABLED" = "0" ]; then
-	test "$1" = "start" && echo "Not starting $DESC; disabled in $DEFAULT."
+	test "$1" = "start" && \
+	{
+		log_warning_msg "$NAME: Not starting $DESC."
+		log_warning_msg "$NAME: Disabled in $DEFAULT."
+	}
 	exit 0
 fi
 
-# Run as root if USER not specified
-if [ ! $USER ]; then
-	USER=root
+# Run as root if DEBPOOL_USER not specified
+if [ ! $DEBPOOL_USER ]; then
+	DEBPOOL_USER=root
 fi
 
-eval USERHOME=~$USER
+# Check for an invalid user or one without a home directory
+eval USERHOME=~$DEBPOOL_USER
 if [ "${USERHOME#/}" = "${USERHOME}" ]; then
-	echo "$NAME: The user '$USER' specified in $DEFAULT is invalid."
-	log_failure_msg "$NAME: The user '$USER' specified in $DEFAULT is invalid."
+	log_failure_msg "$NAME: The user '$DEBPOOL_USER' specified in $DEFAULT is invalid."
 	exit 1
 fi
 
-PIDFILE=$(HOME=$USERHOME debpool --get_lock_path $LOCKPATH) || {
-	log_failure_msg "$NAME: could not determine lockfile path."
-	exit 1
-}
+# Run as $DEBPOOL_USER if not running as root
+if [ "$DEBPOOL_USER" != "root" ]; then
+	CHUID="--chuid $DEBPOOL_USER"
+fi
 
-if [ -n "$USER" ]; then
-	CHUID="--chuid $USER"
+# If lock file specified, pass it to debpool with --lock_file
+# else try to determine lock file using Debpool::Config
+if [ "$LOCKFILE" ]; then
+	PIDFILE=$LOCKFILE
+	LOCKFILE="--lock_file $LOCKFILE"
+else
+	LOCKFILE=$(HOME=$USERHOME debpool --get_lock_path) || \
+		{
+			log_failure_msg "$NAME: could not determine lock file path."
+			exit 1
+		}
+	PIDFILE=$LOCKFILE
+	LOCKFILE="--lock_file $LOCKFILE"
 fi
 
+# If log file specified, pass it to debpool with --log_file option
+if [ "$LOGFILE" ]; then
+	LOGFILE="--log_file $LOGFILE"
+fi
+
+# Specify all options to use for debpool
+DAEMON_ARGS="--daemon $LOGFILE $LOCKFILE $OPTIONS"
+
+#
+# Function that starts the daemon/service
+#
+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 \
+		--startas $DAEMON $CHUID --test > /dev/null || \
+		return 1
+	start-stop-daemon --start --quiet --pidfile $PIDFILE \
+		--startas $DAEMON $CHUID -- $DAEMON_ARGS || \
+		return 2
+}
+
+#
+# Function that stops the daemon/service
+#
+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
+	return "$RETVAL"
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+# TODO: Handling a proper reload of debpool will be supported someday.
+# Until then, debpool will just be stopped and restarted.
+#
+# 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)
-		log_daemon_msg "Starting $DESC" "$NAME"
-		start-stop-daemon --start --quiet --pidfile $PIDFILE \
-			--exec $DAEMON $CHUID -- --daemon $LOGFILE $LOCKPATH $OPTIONS
-		log_end_msg $?
-		;;
-	stop)
-		log_daemon_msg "Stopping $DESC" "$NAME"
-		start-stop-daemon --stop --quiet --pidfile $PIDFILE \
-			--oknodo --name $NAME
-		log_end_msg $?
-		;;
-	force-reload)
-		# check wether $DAEMON is running. If so, restart
-		start-stop-daemon --stop --test --quiet --pidfile \
-			$PIDFILE --name $NAME \
-			&& exec $0 restart \
-			exit 0
-		;;
-	restart)
-		log_daemon_msg "Restarting $DESC" "$NAME"
-		start-stop-daemon --stop --quiet --pidfile $PIDFILE \
-			--oknodo --name $NAME
-		sleep 1
-		start-stop-daemon --start --quiet --pidfile $PIDFILE \
-			--exec $DAEMON $CHUID -- --daemon $LOGFILE $LOCKPATH $OPTIONS
-		log_end_msg $?
+  start)
+	log_daemon_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0) log_end_msg 0 ;;
+		1) log_warning_msg "$DESC" "'$NAME'" "was already started" ;;
+		2) log_end_msg 1 ;;
+	esac
+	;;
+  stop)
+	log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0) log_end_msg 0 ;;
+		1) log_warning_msg "$DESC" "'$NAME'" "was already stopped" ;;
+		2) log_end_msg 1 ;;
+	esac
+	;;
+  #reload|force-reload)
+	#
+	# If do_reload() is not implemented then leave this commented out
+	# and leave 'force-reload' as an alias for 'restart'.
+	#
+	#log_daemon_msg "Reloading $DESC" "$NAME"
+	#do_reload
+	#log_end_msg $?
+	#;;
+  restart|force-reload)
+	#
+	# If the "reload" option is implemented then remove the
+	# 'force-reload' alias
+	#
+	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
 		;;
-	*)
-		N=/etc/init.d/$NAME
-		# echo usage information
-		echo "Usage: $N {start|stop|restart|force-reload}" >&2
-		exit 2
+	  *)
+	  	# Failed to stop
+		log_end_msg 1
 		;;
+	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
+:

-- 
Debpool Project Repository



More information about the Debpool-commits mailing list