Skip to content

Instantly share code, notes, and snippets.

@Thermionix
Last active September 3, 2016 23:06
Show Gist options
  • Save Thermionix/4499412 to your computer and use it in GitHub Desktop.
Save Thermionix/4499412 to your computer and use it in GitHub Desktop.
start-stop-daemon version of the newznab update script
#!/bin/sh
#
# Ian - 16/11/2011
# /etc/init.d/newznab: start and stop the newznab update script
#
# run update-rc.d newznab_ubuntu.sh defaults
### BEGIN INIT INFO
# Provides: Newznab
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start newznab at boot time
# Description: Enable newznab service provided by daemon.
### END INIT INFO
# Newznab variables
NN_PATH="/usr/share/newznab/misc/update_scripts"
NN_BINUP="update_binaries.php"
NN_RELUP="update_releases.php"
NN_SLEEP_TIME="600" # in seconds . 10sec is good for 100s of groups. 600sec might be a good start for fewer.
DESC="Newznab binaries update"
PHP_BIN="/usr/bin/php"
DAEMON=`while (true);do ${PHP_BIN} ${NN_BINUP} && ${PHP_BIN} ${NN_RELUP} ; sleep ${NN_SLEEP_TIME} ; done`
PID_FILE="/var/run/newznab_binup.pid"
RUN_AS="www-data"
test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions
case "$1" in
start)
echo -n "Starting $DESC"
# --quiet --background
start-stop-daemon -d $NN_PATH -c $RUN_AS --start --make-pidfile --pidfile $PID_FILE --exec $DAEMON
;;
stop)
echo -n "Stopping $DESC"
start-stop-daemon --stop --pidfile $PID_FILE --retry 15
;;
*)
echo "Usage: $0 [start|stop]"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment