[Python-apps-commits] r5989 - in packages/sabnzbdplus/trunk/debian (2 files)

jcfp-guest at users.alioth.debian.org jcfp-guest at users.alioth.debian.org
Sun Aug 22 17:36:12 UTC 2010


    Date: Sunday, August 22, 2010 @ 17:36:09
  Author: jcfp-guest
Revision: 5989

Init script cleanup

Modified:
  packages/sabnzbdplus/trunk/debian/changelog
  packages/sabnzbdplus/trunk/debian/sabnzbdplus.init

Modified: packages/sabnzbdplus/trunk/debian/changelog
===================================================================
--- packages/sabnzbdplus/trunk/debian/changelog	2010-08-21 16:17:51 UTC (rev 5988)
+++ packages/sabnzbdplus/trunk/debian/changelog	2010-08-22 17:36:09 UTC (rev 5989)
@@ -1,6 +1,7 @@
 sabnzbdplus (0.5.3-2) UNRELEASED; urgency=low
 
   * Bumped Standards-Version to 3.9.1 (no changes needed).
+  * Init script: moved start and stop procedures into functions.
 
  -- JCF Ploemen (jcfp) <linux at jp.pp.ru>  Sat, 31 Jul 2010 13:49:31 +0200
 

Modified: packages/sabnzbdplus/trunk/debian/sabnzbdplus.init
===================================================================
--- packages/sabnzbdplus/trunk/debian/sabnzbdplus.init	2010-08-21 16:17:51 UTC (rev 5988)
+++ packages/sabnzbdplus/trunk/debian/sabnzbdplus.init	2010-08-22 17:36:09 UTC (rev 5989)
@@ -29,6 +29,7 @@
 DEFOPTS="--daemon"
 PYTHONEXEC="^$(sed -n '1s/^#\!\([a-z0-9\.\/]\+\)\(.*\)/\1(\2)?/p' $DAEMON)"
 PIDFILE=/var/run/sabnzbdplus.pid
+SETTINGS_LOADED=FALSE
 
 # these are only accepted from the settings file
 unset USER CONFIG HOST PORT EXTRAOPTS
@@ -53,52 +54,63 @@
 }
 
 load_settings() {
-	. $SETTINGS
+	if [ $SETTINGS_LOADED != "TRUE" ]; then
+		. $SETTINGS
 
-	[ -z "$USER" ] && {
-		log_warning_msg "$DESC: not configured, aborting. See $SETTINGS";
-		return 1; }
+		[ -z "$USER" ] && {
+			log_warning_msg "$DESC: not configured, aborting. See $SETTINGS";
+			return 1; }
 
-	OPTIONS="$DEFOPTS"
-	[ -n "$CONFIG" ] && OPTIONS="$OPTIONS --config-file $CONFIG"
-	[ -n "$HOST" ] && SERVER="$HOST" || SERVER=
-	[ -n "$PORT" ] && SERVER="$SERVER:$PORT"
-	[ -n "$SERVER" ] && OPTIONS="$OPTIONS --server $SERVER"
-	[ -n "$EXTRAOPTS" ] && OPTIONS="$OPTIONS $EXTRAOPTS"
+		OPTIONS="$DEFOPTS"
+		[ -n "$CONFIG" ] && OPTIONS="$OPTIONS --config-file $CONFIG"
+		[ -n "$HOST" ] && SERVER="$HOST" || SERVER=
+		[ -n "$PORT" ] && SERVER="$SERVER:$PORT"
+		[ -n "$SERVER" ] && OPTIONS="$OPTIONS --server $SERVER"
+		[ -n "$EXTRAOPTS" ] && OPTIONS="$OPTIONS $EXTRAOPTS"
+		SETTINGS_LOADED=TRUE
+	fi
 	return 0
 }
 
+start_sab() {
+	load_settings || exit 0
+	if ! is_running; then
+		log_daemon_msg "Starting $DESC"
+		start-stop-daemon --quiet --chuid $USER --start --exec $DAEMON -- $OPTIONS
+		check_retval
+		# create a pidfile; we don't use it but some monitoring app likes to have one
+		[ -w $(dirname $PIDFILE) ] && \
+			pgrep -f -x -n -u $USER "$PYTHONEXEC $DAEMON $OPTIONS" > $PIDFILE
+	else
+		log_success_msg "$DESC: already running (pid $PID)"
+	fi
+}
+
+stop_sab() {
+	load_settings || exit 0
+	if is_running; then
+		TMPFILE=$(mktemp /tmp/sabnzbdplus.XXXXXXXXXX || exit 1)
+		trap '[ -f $TMPFILE ] && rm -f $TMPFILE' EXIT
+		echo "$PID" > $TMPFILE
+		log_daemon_msg "Stopping $DESC"
+		start-stop-daemon --stop --user $USER --pidfile $TMPFILE --retry 30
+		check_retval
+	else
+		log_success_msg "$DESC: not running"
+	fi
+	[ -f $PIDFILE ] && rm -f $PIDFILE
+}
+
 case "$1" in
 	start)
-		load_settings || exit 0
-		if ! is_running; then
-			log_daemon_msg "Starting $DESC"
-			start-stop-daemon --quiet --chuid $USER --start --exec $DAEMON -- $OPTIONS
-			check_retval
-			# create a pidfile; we don't use it but some monitoring app likes to have one
-			[ -w $(dirname $PIDFILE) ] && \
-				pgrep -f -x -n -u $USER "$PYTHONEXEC $DAEMON $OPTIONS" > $PIDFILE
-		else
-			log_success_msg "$DESC: already running (pid $PID)"
-		fi
+		start_sab
 	;;
 	stop)
-		load_settings || exit 0
-		if is_running; then
-			TMPFILE=$(mktemp /tmp/sabnzbdplus.XXXXXXXXXX || exit 1)
-			trap '[ -f $TMPFILE ] && rm -f $TMPFILE' EXIT
-			echo "$PID" > $TMPFILE
-			log_daemon_msg "Stopping $DESC"
-			start-stop-daemon --stop --user $USER --pidfile $TMPFILE --retry 30
-			check_retval
-		else
-			log_success_msg "$DESC: not running"
-		fi
-		[ -f $PIDFILE ] && rm -f $PIDFILE
+		stop_sab
 	;;
 	force-reload|restart)
-		$0 stop || exit $?
-		$0 start || exit $?
+		stop_sab
+		start_sab
 	;;
 	status)
 		load_settings || exit 4




More information about the Python-apps-commits mailing list