My first step was creating a file the script could touch before every cycle. There are probably files that could serve this purpose within the standard newznab configuration, but I struggled to find one that was easy to identify. I created this:

[email protected]:/$ cat /var/www/newznab/misc/monitor.txt This file will be “touch"ed to show updates are happening. [email protected]:/$

Next I edited this script:

[email protected]:/$ cat/var/www/newznab/misc/update_scripts/nix_scripts/newznab/newznab_ubuntu.sh

!/bin/bash # # 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=”/var/www/newznab/misc/update_scripts" NN_BINUP=“update_binaries.php” NN_RELUP=“update_releases.php” NN_OPTIMISE=“optimise_db.php” NN_UPDATETV=“update_tvschedule.php” NN_UPDATETH=“update_theaters.php” NN_SLEEP_TIME=“60” # in seconds . 10sec is good for 100s of groups. 600sec might be a good start for fewer. NN_PID_PATH=“/var/run/” NN_LOGFILE=“/var/log/newznab_ubuntu.log” PIDFILE=“newznab_binup.pid” LOOPCOUNTER=0 test -f /lib/lsb/init-functions || exit 1 . /lib/lsb/init-functions case “$1” in start) [ -f $NN_PID_PATH$PIDFILE ] && { echo -e “$0 is already ruNNing.\n”; false; } echo “Starting Newznab binaries update” >> $NN_LOGFILE 2>&1 cd $NN_PATH ( set -e LASTOPTIMIZE=date +%s echo “Last optimize is $LASTOPTIMIZE” >> $NN_LOGFILE 2>&1 while : do echo “Touching ${NN_PATH}/../monitor.txt” >> $NN_LOGFILE 2>&1 touch ${NN_PATH}/../monitor.txt LOOPCOUNTER=$((LOOPCOUNTER+1)) cd $NN_PATH echo “Updating binaries” >> $NN_LOGFILE 2>&1 php $NN_BINUP >> $NN_LOGFILE 2>&1 echo “Updating releases” >> $NN_LOGFILE 2>&1 php $NN_RELUP >> $NN_LOGFILE 2>&1 echo “Sleeping for $NN_SLEEP_TIME” >> $NN_LOGFILE 2>&1 sleep $NN_SLEEP_TIME CURRTIME=date +%s echo “Current time is $CURRTIME” >> $NN_LOGFILE 2>&1 DIFF=$(($CURRTIME-$LASTOPTIMIZE)) echo “Last optimize is $LASTOPTIMIZE” >> $NN_LOGFILE 2>&1 echo “Difference is $DIFF” >> $NN_LOGFILE 2>&1 if [ “$DIFF” -gt 43200 ] || [ “$DIFF” -lt 1 ] then echo “Last optimize is $LASTOPTIMIZE” >> $NN_LOGFILE 2>&1 LASTOPTIMIZE=date +%s echo “Optimizing stuff” >> $NN_LOGFILE 2>&1 php $NN_OPTIMISE >> $NN_LOGFILE 2>&1 php $NN_UPDATETV >> $NN_LOGFILE 2>&1 php $NN_UPDATETH >> $NN_LOGFILE 2>&1 fi echo “Loop $LOOPCOUNTER” >> $NN_LOGFILE done) & PID=echo $! echo $PID > $NN_PID_PATH$PIDFILE echo “pid is $PID” >> $NN_LOGFILE 2>&1 echo “Started Newznab binaries update” ;; stop) echo “Stopping Newznab binaries update” | tee -a $NN_LOGFILE kill -9 cat $NN_PID_PATH$PIDFILE rm $NN_PID_PATH$PIDFILE ;; *) echo “Usage: $0 [start|stop]” exit 1 esac

[email protected]:/$ sudo ln -s /var/www/newznab/misc/update_scripts/nix_scripts/newznab_ubuntu.sh /etc/init.d/newznab_ubuntu

[email protected]:/$ sudo update-rc.d newznab_ubuntu defaults

[email protected]:/$

One thing to note in the script above: I set NN_SLEEP_TIME to 60 seconds. This seems to decrease the number of script freezes.

Be sure to set the right parameters for the script:

[email protected]:/$ sudo chmod a+rwx /etc/init.d/newznab_ubuntu

[email protected]:/$ sudo chown root:root /etc/init.d/newznab_ubuntu

This script will create a log file, /var/log/newznab_ubuntu.log. If you want this log to get rotated and compressed daly (and you probably do want that) you need to create this file:

[email protected]:~$ cat /etc/logrotate.d/newznab_ubuntu /var/log/newznab_ubuntu.log { missingok notifempty compress size 20k daily create 0666 root root } echo “Stopping Newznab binaries update” | tee -a $NN_LOGFILE kill -9 cat $NN_PID_PATH$PIDFILE rm $NN_PID_PATH$PIDFILE

To start and stop the service use:

[email protected]:/$ sudo service newznab_ubuntu start [email protected]:/$ sudo service newznab_ubuntu stop