#!/bin/bash ### BEGIN INIT INFO # Provides: huck-youtube monitor for lxle0 # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/stop youtube monitor daemon ### END INIT INFO # http://ubuntuforums.org/showthread.php?t=2231702 # https://github.com/mjsilva/rtorrent-screen-debian-init-script/blob/master/rtorrent # sudo update-rc.d youhuckmon defaults 99 # sudo /etc/init.d/youhuckmon start MYLOG="/home/active/you-huck/apiv3/base/huck4you-startup.log.lst" echo `date` $1 >> $MYLOG ## Username to run under ## home directory of this user! USER="phuck" ## start with a cd here CDTO="/home/active/you-huck/apiv3" ## Absolute path to the binary. RUNME="/home/huck/cvs/you-perl/go-you-huck" ## Absolute path to the screen binary. SCREEN="/usr/bin/screen" ## Name of the screen session, you can then "screen -r " to get it back ## to the forground and work with it on your shell. SCREEN_NAME="youtubemon" # Absolute path to PID file. PIDFILE="/var/run/youtube-huck4you.pid" case "$1" in ## Start screen in the background. start) cd $CDTO echo "Starting screen $SCREEN_NAME" | tee -a $MYLOG start-stop-daemon --start --background --oknodo \ --pidfile "$PIDFILE" --make-pidfile \ --chuid $USER \ --chdir $CDTO \ --exec $SCREEN -- -DmUS $SCREEN_NAME $RUNME # --exec $SCREEN -- -LDmUS $SCREEN_NAME $RUNME if [[ $? -ne 0 ]]; then echo "Error: screen $SCREEN_NAME failed to start." | tee -a $MYLOG exit 1 fi echo "screen $SCREEN_NAME started successfully. " | tee -a $MYLOG ;; ## Stop . stop) echo "Stopping screen $SCREEN_NAME." | tee -a $MYLOG start-stop-daemon --stop --oknodo --pidfile "$PIDFILE" if [[ $? -ne 0 ]]; then echo "Error: failed to stop $SCREEN_NAME process." | tee -a $MYLOG exit 1 fi echo "$SCREEN_NAME stopped successfully." | tee -a $MYLOG ;; ## Restart restart) "$0" stop sleep 1 "$0" start || exit 1 ;; ## Print usage information if the user gives an invalid option. *) echo "Usage: $0 [start|stop|restart]" exit 1 ;; esac