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

jcfp-guest at users.alioth.debian.org jcfp-guest at users.alioth.debian.org
Sun Dec 15 19:25:06 UTC 2013


    Date: Sunday, December 15, 2013 @ 19:25:05
  Author: jcfp-guest
Revision: 10259

Rework init script to use new upstream --pidfile option.

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

Modified: packages/sabnzbdplus/trunk/debian/changelog
===================================================================
--- packages/sabnzbdplus/trunk/debian/changelog	2013-12-15 19:20:18 UTC (rev 10258)
+++ packages/sabnzbdplus/trunk/debian/changelog	2013-12-15 19:25:05 UTC (rev 10259)
@@ -1,8 +1,9 @@
 sabnzbdplus (0.7.17-1) unstable; urgency=low
 
   * New upstream release.
+  * Rework init script to use new upstream --pidfile option.
 
- -- JCF Ploemen (jcfp) <linux at jcf.pm>  Sun, 15 Dec 2013 19:33:59 +0100
+ -- JCF Ploemen (jcfp) <linux at jcf.pm>  Sun, 15 Dec 2013 20:23:35 +0100
 
 sabnzbdplus (0.7.16-1) unstable; urgency=low
 

Modified: packages/sabnzbdplus/trunk/debian/sabnzbdplus.init
===================================================================
--- packages/sabnzbdplus/trunk/debian/sabnzbdplus.init	2013-12-15 19:20:18 UTC (rev 10258)
+++ packages/sabnzbdplus/trunk/debian/sabnzbdplus.init	2013-12-15 19:25:05 UTC (rev 10259)
@@ -31,9 +31,9 @@
 ([ -x "$DAEMON" ] && [ -r "$SETTINGS" ]) || exit 0
 
 DESC="SABnzbd+ binary newsgrabber"
-DEFOPTS="--daemon"
-PYTHONEXEC="^$(sed -n '1s/^#\! \?\([a-z0-9\.\/]\+\)\(.*\)/\1(\2)?/p' "$DAEMON")"
-PIDFILE="/var/run/$NAME.pid"
+PIDFILE="/var/run/$NAME/pid"
+DEFOPTS="--daemon --pidfile '$PIDFILE'"
+PYTHONEXEC="$(readlink -f '/usr/bin/python')"
 
 # these are only accepted from the settings file
 unset USER CONFIG HOST PORT EXTRAOPTS
@@ -51,10 +51,10 @@
 }
 
 is_running() {
-	# returns 0 when running, 1 otherwise
-	PID="$(pgrep -f -x -u ${USER%:*} "$PYTHONEXEC $DAEMON $DEFOPTS.*")"
+	# don't try to match --name: it changes after restarting via the web interface
+	start-stop-daemon --status --quiet --user "${USER%:*}" --pidfile "$PIDFILE" --exec "$PYTHONEXEC"
 	RET=$?
-	[ $RET -gt 1 ] && exit 1 || return $RET
+	[ $RET -gt 3 ] && exit 1 || return $RET
 }
 
 load_settings() {
@@ -62,46 +62,46 @@
 		. "$SETTINGS"
 
 		[ -z "${USER%:*}" ] && {
-			log_warning_msg "$DESC: service not enabled; edit $SETTINGS";
+			log_action_msg "$DESC: service not enabled, edit $SETTINGS";
 			return 1;
 		}
 
 		OPTIONS="$DEFOPTS"
-		[ -n "$CONFIG" ] && OPTIONS="$OPTIONS --config-file $CONFIG"
+		[ -n "$CONFIG" ] && OPTIONS="$OPTIONS --config-file '$CONFIG'"
 		[ -n "$HOST" ] && SERVER="$HOST" || SERVER=
 		[ -n "$PORT" ] && SERVER="$SERVER:$PORT"
-		[ -n "$SERVER" ] && OPTIONS="$OPTIONS --server $SERVER"
+		[ -n "$SERVER" ] && OPTIONS="$OPTIONS --server '$SERVER'"
 		[ -n "$EXTRAOPTS" ] && OPTIONS="$OPTIONS $EXTRAOPTS"
 	fi
 	return 0
 }
 
+prep_pid() {
+	PIDDIR="$(dirname "$PIDFILE")"
+	[ ! -d "$PIDDIR" ] && (mkdir -p -m 0750 "$PIDDIR" || exit 1)
+	chown "${USER%:*}" "$PIDDIR" || exit 1
+}
+
 start_sab() {
 	load_settings || exit 0
 	if ! is_running; then
+		prep_pid
 		log_daemon_msg "Starting $DESC"
-		start-stop-daemon --quiet --chuid $USER --start --exec $DAEMON -- $OPTIONS
+		eval start-stop-daemon --start --quiet --chuid "$USER" --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)"
+		log_action_msg "$DESC: already running (pid $(head -c5 "$PIDFILE"))";
 	fi
 }
 
 stop_sab() {
 	load_settings || exit 0
 	if is_running; then
-		TMPFILE="$(mktemp --tmpdir sabnzbdplus.XXXXXXXXXX)"
-		[ $? -eq 0 ] || 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
+		start-stop-daemon --stop --quiet --user "${USER%:*}" --pidfile "$PIDFILE" --exec "$PYTHONEXEC" --retry 30
 		check_retval
 	else
-		log_success_msg "$DESC: not running"
+		log_action_msg "$DESC: not running"
 	fi
 	[ -f "$PIDFILE" ] && rm -f "$PIDFILE"
 }
@@ -118,16 +118,14 @@
 		start_sab
 	;;
 	status)
+		# load_settings isn't strictly necessary here but does print a nice
+		# warning in case the service isn't enabled/configured at all
 		load_settings || exit 4
-		if is_running; then
-			log_success_msg "$DESC: running (pid $PID)"
-		else
-			log_success_msg "$DESC: not running"
-			[ -f "$PIDFILE" ] && exit 1 || exit 3
-		fi
+		status_of_proc -p "$PIDFILE" "$DAEMON" "$DESC"
+		exit $?
 	;;
 	*)
-		log_failure_msg "Usage: $0 {start|stop|restart|force-reload|status}"
+		echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
 		exit 3
 	;;
 esac




More information about the Python-apps-commits mailing list