From ed5d7dda53a706438d5e09d26d46114676bed320 Mon Sep 17 00:00:00 2001 From: Benjamin Runnels Date: Mon, 17 Dec 2012 07:34:23 -0600 Subject: [PATCH 1/5] Update linux init script to be inline with other tools like sickbeard, couchpotato, marachino, etc... --- init.ubuntu | 209 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 175 insertions(+), 34 deletions(-) diff --git a/init.ubuntu b/init.ubuntu index 36102575..c5bbf6a5 100644 --- a/init.ubuntu +++ b/init.ubuntu @@ -1,5 +1,44 @@ -#! /bin/sh - +#!/bin/sh +# +## Don't edit this file +## Edit user configuation in /etc/default/headphones to change +## +## Make sure init script is executable +## sudo chmod +x /opt/headphones/init.ubuntu +## +## Install the init script +## sudo ln -s /opt/headphones/init.ubuntu /etc/init.d/headphones +## +## Create the headphones daemon user: +## sudo adduser --system --no-create-home headphones +## +## Make sure /opt/headphones is owned by the headphones user +## sudo chown headphones:nogroup -R /opt/headphones +## +## Touch the default file to stop the warning message when starting +## sudo touch /etc/default/headphones +## +## To start Headphones automatically +## sudo update-rc.d headphones defaults +## +## To start/stop/restart Headphones +## sudo service headphones start +## sudo service headphones stop +## sudo service headphones restart +## +## HP_USER= #$RUN_AS, username to run headphones under, the default is headphones +## HP_HOME= #$APP_PATH, the location of Headphones.py, the default is /opt/headphones +## HP_DATA= #$DATA_DIR, the location of headphones.db, cache, logs, the default is /opt/headphones +## HP_PIDFILE= #$PID_FILE, the location of headphones.pid, the default is /var/run/headphones/headphones.pid +## PYTHON_BIN= #$DAEMON, the location of the python binary, the default is /usr/bin/python +## HP_OPTS= #$EXTRA_DAEMON_OPTS, extra cli option for headphones, i.e. " --config=/home/headphones/config.ini" +## SSD_OPTS= #$EXTRA_SSD_OPTS, extra start-stop-daemon option like " --group=users" +## HP_PORT= #$PORT_OPTS, hardcoded port for the webserver, overrides value in config.ini +## +## EXAMPLE if want to run as different user +## add HP_USER=username to /etc/default/headphones +## otherwise default headphones is used +# ### BEGIN INIT INFO # Provides: headphones # Required-Start: $local_fs $network $remote_fs @@ -12,50 +51,152 @@ # Description: starts instance of Headphones using start-stop-daemon ### END INIT INFO -############### EDIT ME ################## -# path to app -APP_PATH=/usr/local/sbin/headphones - -# path to python bin -DAEMON=/usr/bin/python - -# startup args -DAEMON_OPTS=" Headphones.py -q" - -# script name +# Script name NAME=headphones -# app name -DESC=headphones +# App name +DESC=Headphones -# user -RUN_AS=root +SETTINGS_LOADED=FALSE -PID_FILE=/var/run/headphones.pid +. /lib/lsb/init-functions -############### END EDIT ME ################## +# Source Headphones configuration +if [ -f /etc/default/headphones ]; then + SETTINGS=/etc/default/headphones +else + log_warning_msg "/etc/default/headphones not found using default settings."; +fi -test -x $DAEMON || exit 0 +check_retval() { + if [ $? -eq 0 ]; then + log_end_msg 0 + return 0 + else + log_end_msg 1 + exit 1 + fi +} -set -e +load_settings() { + if [ $SETTINGS_LOADED != "TRUE" ]; then + . $SETTINGS + + ## The defaults + # Run as username + RUN_AS=${HP_USER-headphones} + + # Path to app HP_HOME=path_to_app_Headphones.py + APP_PATH=${HP_HOME-/opt/headphones} + + # Data directory where headphones.db, cache and logs are stored + DATA_DIR=${HP_DATA-/opt/headphones} + + # Path to store PID file + PID_FILE=${HP_PIDFILE-/var/run/headphones/headphones.pid} + + # Path to python bin + DAEMON=${PYTHON_BIN-/usr/bin/python} + + # Extra daemon option like: HP_OPTS=" --config=/home/headphones/config.ini" + EXTRA_DAEMON_OPTS=${HP_OPTS-} + + # Extra start-stop-daemon option like START_OPTS=" --group=users" + EXTRA_SSD_OPTS=${SSD_OPTS-} + + # Hardcoded port to run on, overrides config.ini settings + [ -n "$HP_PORT" ] && { + PORT_OPTS=" --port=${HP_PORT} " + } + + DAEMON_OPTS=" Headphones.py --quiet --daemon --nolaunch --pidfile=${PID_FILE} --datadir=${DATA_DIR} ${PORT_OPTS}${EXTRA_DAEMON_OPTS}" + + SETTINGS_LOADED=TRUE + fi + + [ -x $DAEMON ] || { + log_warning_msg "$DESC: Can't execute daemon, aborting. See $DAEMON"; + return 1;} + + return 0 +} + +load_settings || exit 0 + +is_running () { + # returns 1 when running, else 0. + if [ -e $PID_FILE ]; then + PID=`cat $PID_FILE` + + RET=$? + [ $RET -gt 1 ] && exit 1 || return $RET + else + return 1 + fi +} + +handle_pid () { + PID_PATH=`dirname $PID_FILE` + [ -d $PID_PATH ] || mkdir -p $PID_PATH && chown -R $RUN_AS $PID_PATH > /dev/null || { + log_warning_msg "$DESC: Could not create $PID_FILE, See $SETTINGS, aborting."; + return 1;} + + if [ -e $PID_FILE ]; then + PID=`cat $PID_FILE` + if ! kill -0 $PID > /dev/null 2>&1; then + log_warning_msg "Removing stale $PID_FILE" + rm $PID_FILE + fi + fi +} + +handle_datadir () { + [ -d $DATA_DIR ] || mkdir -p $DATA_DIR && chown -R $RUN_AS $DATA_DIR > /dev/null || { + log_warning_msg "$DESC: Could not create $DATA_DIR, See $SETTINGS, aborting."; + return 1;} +} + +handle_updates () { + chown -R $RUN_AS $APP_PATH > /dev/null || { + log_warning_msg "$DESC: $APP_PATH not writable by $RUN_AS for web-updates"; + return 0; } +} + +start_headphones () { + handle_pid + handle_datadir + handle_updates + if ! is_running; then + log_daemon_msg "Starting $DESC" + start-stop-daemon -o -d $APP_PATH -c $RUN_AS --start $EXTRA_SSD_OPTS --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS + check_retval + else + log_success_msg "$DESC: already running (pid $PID)" + fi +} + +stop_headphones () { + if is_running; then + log_daemon_msg "Stopping $DESC" + start-stop-daemon -o --stop --pidfile $PID_FILE --retry 15 + check_retval + else + log_success_msg "$DESC: not running" + fi +} case "$1" in - start) - echo "Starting $DESC" - start-stop-daemon -d $APP_PATH -c $RUN_AS --start --background --pidfile $PID_FILE --make-pidfile --exec $DAEMON -- $DAEMON_OPTS + start) + start_headphones ;; - stop) - echo "Stopping $DESC" - start-stop-daemon --stop --pidfile $PID_FILE + stop) + stop_headphones ;; - - restart|force-reload) - echo "Restarting $DESC" - start-stop-daemon --stop --pidfile $PID_FILE - sleep 15 - start-stop-daemon -d $APP_PATH -c $RUN_AS --start --background --pidfile $PID_FILE --make-pidfile --exec $DAEMON -- $DAEMON_OPTS + restart|force-reload) + stop_headphones + start_headphones ;; - *) + *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|force-reload}" >&2 exit 1 From 4bc40a3218e1a50dd58ff89c741427783c7a73d0 Mon Sep 17 00:00:00 2001 From: Benjamin Runnels Date: Mon, 17 Dec 2012 08:27:48 -0600 Subject: [PATCH 2/5] Fixed a hardcoded url to AdeHub github in update check message. Created new GIT_USER and GIT_BRANCH globals and config options. Moved hardcoded user and branch variables to globals in versioncheck. --- data/interfaces/default/base.html | 24 +-- headphones/__init__.py | 246 +++++++++++++++--------------- headphones/versioncheck.py | 109 +++++++------ 3 files changed, 191 insertions(+), 188 deletions(-) diff --git a/data/interfaces/default/base.html b/data/interfaces/default/base.html index 152f9311..783f4f36 100644 --- a/data/interfaces/default/base.html +++ b/data/interfaces/default/base.html @@ -11,19 +11,19 @@ - + Headphones - ${title} - + - + ${next.headIncludes()} - + @@ -31,16 +31,16 @@
% if not headphones.CURRENT_VERSION:
- You're running an unknown version of Headphones. Update or + You're running an unknown version of Headphones. Update or Close
% elif headphones.CURRENT_VERSION != headphones.LATEST_VERSION and headphones.INSTALL_TYPE != 'win':
- A newer version is available. You're ${headphones.COMMITS_BEHIND} commits behind. Update or Close + A newer version is available. You're ${headphones.COMMITS_BEHIND} commits behind. Update or Close
% endif - -
+ +
- +
@@ -91,16 +91,16 @@ %if version.HEADPHONES_VERSION != 'master': (${version.HEADPHONES_VERSION}) %endif - + Back to top - + ${next.javascriptIncludes()} - +