Change sickbeard variables to sickgear variables in init-scripts

This commit is contained in:
Adam 2015-11-19 12:40:31 +08:00
parent 503f7d715f
commit 6b129c9eee
8 changed files with 186 additions and 185 deletions

View file

@ -75,6 +75,7 @@
* Add version to anime renaming pattern
* Add Code Climate configuration files
* Change to move init-scripts to single folder
* Change sickbeard variables to sickgear variables in init-scripts
[develop changelog]
Enable Alpha Ratio again now that the secure login page over https is fixed

View file

@ -1,15 +1,15 @@
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: sickbeard
# Provides: sickgear
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Should-Start: $NetworkManager
# Should-Stop: $NetworkManager
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts instance of SickBeard
# Description: starts instance of SickBeard using start-stop-daemon
# Short-Description: starts instance of SickGear
# Description: starts instance of SickGear using start-stop-daemon
### END INIT INFO
# Load the VERBOSE setting and other rcS variables
@ -19,57 +19,57 @@
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# Source SickBeard configuration
if [ -f /etc/default/sickbeard ]; then
. /etc/default/sickbeard
# Source SickGear configuration
if [ -f /etc/default/sickgear ]; then
. /etc/default/sickgear
else
[ "${VERBOSE}" != no ] && echo "/etc/default/sickbeard not found. Using default settings.";
[ "${VERBOSE}" != no ] && echo "/etc/default/sickgear not found. Using default settings.";
fi
## Don't set -e
## Don't edit this file!
## Edit user configuation in /etc/default/sickbeard to change
## Edit user configuation in /etc/default/sickgear to change
##
## SB_USER= #$RUN_AS, username to run sickbeard under, the default is sickbeard
## SB_GROUP= #$RUN_GROUP, group to run sickbeard under, the default is sickbeard
## SB_HOME= #$APP_PATH, the location of SickBeard.py, the default is /opt/sickbeard
## SB_DATA= #$DATA_DIR, the location of sickbeard.db, cache, logs, the default is /opt/sickbeard
## SB_PIDFILE= #$PID_FILE, the location of sickbeard.pid, the default is /var/run/sickbeard/sickbeard.pid
## SG_USER= #$RUN_AS, username to run sickgear under, the default is sickgear
## SG_GROUP= #$RUN_GROUP, group to run sickgear under, the default is sickgear
## SG_HOME= #$APP_PATH, the location of SickBeard.py, the default is /opt/sickgear
## SG_DATA= #$DATA_DIR, the location of sickbeard.db, cache, logs, the default is /opt/sickgear
## SG_PIDFILE= #$PID_FILE, the location of sickgear.pid, the default is /var/run/sickgear/sickgear.pid
## PYTHON_BIN= #$DAEMON, the location of the python binary, the default is /usr/bin/python
## SB_OPTS= #$EXTRA_DAEMON_OPTS, extra cli option for sickbeard, i.e. " --config=/home/sickbeard/config.ini"
## SG_OPTS= #$EXTRA_DAEMON_OPTS, extra cli option for sickgear, i.e. " --config=/home/sickgear/config.ini"
## SSD_OPTS= #$EXTRA_SSD_OPTS, extra start-stop-daemon option like " --group=users"
##
## EXAMPLE if want to run as different user
## add SB_USER=username to /etc/default/sickbeard
## otherwise default sickbeard is used
## add SG_USER=username to /etc/default/sickgear
## otherwise default sickgear is used
# Script name
NAME=$(basename "$0")
# App name
DESC=SickBeard
DESC=SickGear
## The defaults
# Run as username
RUN_AS=${SB_USER-sickbeard}
# Run as username
RUN_AS=${SG_USER-sickgear}
# Run as group
RUN_GROUP=${SB_GROUP-sickbeard}
RUN_GROUP=${SG_GROUP-sickgear}
# Path to app SB_HOME=path_to_app_SickBeard.py
APP_PATH=${SB_HOME-/opt/sickbeard}
# Path to app SG_HOME=path_to_app_SickBeard.py
APP_PATH=${SG_HOME-/opt/sickgear}
# Data directory where sickbeard.db, cache and logs are stored
DATA_DIR=${SB_DATA-/opt/sickbeard}
DATA_DIR=${SG_DATA-/opt/sickgear}
# Path to store PID file
PID_FILE=${SB_PIDFILE-/var/run/sickbeard/sickbeard.pid}
PID_FILE=${SG_PIDFILE-/var/run/sickgear/sickgear.pid}
# path to python bin
DAEMON=${PYTHON_BIN-/usr/bin/python}
# Extra daemon option like: SB_OPTS=" --config=/home/sickbeard/config.ini"
EXTRA_DAEMON_OPTS=${SB_OPTS-}
# Extra daemon option like: SG_OPTS=" --config=/home/sickgear/config.ini"
EXTRA_DAEMON_OPTS=${SG_OPTS-}
# Extra start-stop-daemon option like START_OPTS=" --group=users"
EXTRA_SSD_OPTS=${SSD_OPTS-}
@ -82,7 +82,7 @@ DAEMON_OPTS=" SickBeard.py -q --daemon --nolaunch --pidfile=${PID_FILE} --datadi
test -x $DAEMON || exit 0
# Create PID directory if not exist and ensure the SickBeard user can write to it
# Create PID directory if not exist and ensure the SickGear user can write to it
if [ ! -d $PID_PATH ]; then
mkdir -p $PID_PATH
chown $RUN_AS $PID_PATH
@ -101,9 +101,9 @@ if [ -e $PID_FILE ]; then
fi
fi
start_sickbeard() {
start_sickgear() {
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
start-stop-daemon -d $APP_PATH -c $RUN_AS --group=${RUN_GROUP} $EXTRA_SSD_OPTS --start --quiet --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
start-stop-daemon -d $APP_PATH -c $RUN_AS --group=${RUN_GROUP} $EXTRA_SSD_OPTS --start --quiet --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
RETVAL="$?"
case "${RETVAL}" in
# Service was started or was running already
@ -115,7 +115,7 @@ start_sickbeard() {
return 0
}
stop_sickbeard() {
stop_sickgear() {
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
start-stop-daemon --stop --pidfile $PID_FILE --quiet --retry TERM/30/KILL/5
RETVAL="$?"
@ -127,23 +127,23 @@ stop_sickbeard() {
esac
[ "${RETVAL}" = 2 ] && return 2
[ -f "${PID_FILE}" ] && rm -f ${PID_FILE}
return 0
return 0
}
case "$1" in
start)
start_sickbeard
start_sickgear
exit $?
;;
stop)
stop_sickbeard
stop_sickgear
exit $?
;;
restart|force-reload)
stop_sickbeard
stop_sickgear
sleep 2
start_sickbeard
start_sickgear
return $?
;;
status)

View file

@ -1,7 +1,7 @@
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: sickbeard
# Provides: sickgear
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
@ -13,27 +13,27 @@
# Source function library.
. /etc/init.d/functions
# Source SickBeard configuration
if [ -f /etc/sysconfig/sickbeard ]; then
. /etc/sysconfig/sickbeard
# Source SickGear configuration
if [ -f /etc/sysconfig/sickgear ]; then
. /etc/sysconfig/sickgear
fi
prog=sickbeard
prog=sickgear
lockfile=/var/lock/subsys/$prog
## Edit user configuation in /etc/sysconfig/sickbeard to change
## Edit user configuation in /etc/sysconfig/sickgear to change
## the defaults
username=${SB_USER-sickbeard}
homedir=${SB_HOME-/opt/sickbeard}
datadir=${SB_DATA-/opt/sickbeard}
pidfile=${SB_PIDFILE-/var/run/sickbeard/sickbeard.pid}
nice=${SB_NICE-}
username=${SG_USER-sickgear}
homedir=${SG_HOME-/opt/sickgear}
datadir=${SG_DATA-/opt/sickgear}
pidfile=${SG_PIDFILE-/var/run/sickgear/sickgear.pid}
nice=${SG_NICE-}
##
pidpath=`dirname ${pidfile}`
options=" --daemon --nolaunch --pidfile=${pidfile} --datadir=${datadir}"
# create PID directory if not exist and ensure the SickBeard user can write to it
# create PID directory if not exist and ensure the SickGear user can write to it
if [ ! -d $pidpath ]; then
mkdir -p $pidpath
chown $username $pidpath

View file

@ -1,66 +1,66 @@
#!/bin/sh
#
# PROVIDE: sickbeard
# PROVIDE: sickgear
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# sickbeard_enable (bool): Set to NO by default.
# sickgear_enable (bool): Set to NO by default.
# Set it to YES to enable it.
# sickbeard_user: The user account SickGear daemon runs as what
# sickgear_user: The user account SickGear daemon runs as what
# you want it to be. It uses '_sabnzbd' user by
# default. Do not sets it as empty or it will run
# as root.
# sickbeard_dir: Directory where SickGear lives.
# Default: /usr/local/sickbeard
# sickbeard_chdir: Change to this directory before running SickGear.
# Default is same as sickbeard_dir.
# sickbeard_datadir: Data directory for Sick Beard (DB, Logs, config)
# Default is same as sickbeard_chdir
# sickbeard_pid: The name of the pidfile to create.
# Default is sickbeard.pid in sickbeard_dir.
# sickbeard_host: The hostname or IP SickGear is listening on
# sickgear_dir: Directory where SickGear lives.
# Default: /usr/local/sickgear
# sickgear_chdir: Change to this directory before running SickGear.
# Default is same as sickgear_dir.
# sickgear_datadir: Data directory for Sick Beard (DB, Logs, config)
# Default is same as sickgear_chdir
# sickgear_pid: The name of the pidfile to create.
# Default is sickgear.pid in sickgear_dir.
# sickgear_host: The hostname or IP SickGear is listening on
# Default is 127.0.0.1
# sickbeard_port: The port SickGear is listening on
# sickgear_port: The port SickGear is listening on
# Default is 8081
# sickbeard_web_user: Username to authenticate to the SickGear web interface
# sickgear_web_user: Username to authenticate to the SickGear web interface
# Default is an empty string (no username)
# sickbeard_web_password: Password to authenticate to the SickGear web interface
# sickgear_web_password: Password to authenticate to the SickGear web interface
# Default is an empty string (no password)
# sickbeard_webroot: Set to value of web_root in config (for proxies etc)
# sickgear_webroot: Set to value of web_root in config (for proxies etc)
# Default is an empty string (if set must start with a "/")
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
. /etc/rc.subr
name="sickbeard"
name="sickgear"
rcvar=${name}_enable
load_rc_config ${name}
: ${sickbeard_enable:="NO"}
: ${sickbeard_user:="_sabnzbd"}
: ${sickbeard_dir:="/usr/local/sickbeard"}
: ${sickbeard_chdir:="${sickbeard_dir}"}
: ${sickbeard_datadir:="${sickbeard_chdir}"}
: ${sickbeard_pid:="${sickbeard_dir}/sickbeard.pid"}
: ${sickbeard_host:="127.0.0.1"}
: ${sickbeard_port:="8081"}
: ${sickbeard_web_user:=""}
: ${sickbeard_web_password:=""}
: ${sickbeard_webroot:=""}
: ${sickgear_enable:="NO"}
: ${sickgear_user:="_sabnzbd"}
: ${sickgear_dir:="/usr/local/sickgear"}
: ${sickgear_chdir:="${sickgear_dir}"}
: ${sickgear_datadir:="${sickgear_chdir}"}
: ${sickgear_pid:="${sickgear_dir}/sickgear.pid"}
: ${sickgear_host:="127.0.0.1"}
: ${sickgear_port:="8081"}
: ${sickgear_web_user:=""}
: ${sickgear_web_password:=""}
: ${sickgear_webroot:=""}
status_cmd="${name}_status"
stop_cmd="${name}_stop"
command="/usr/sbin/daemon"
command_args="-f -p ${sickbeard_pid} python ${sickbeard_dir}/SickBeard.py --quiet --nolaunch"
command_args="-f -p ${sickgear_pid} python ${sickgear_dir}/SickBeard.py --quiet --nolaunch"
# Add datadir to the command if set
[ ! -z "${sickbeard_datadir}" ] && \
command_args="${command_args} --datadir ${sickbeard_datadir}"
[ ! -z "${sickgear_datadir}" ] && \
command_args="${command_args} --datadir ${sickgear_datadir}"
# Ensure user is root when running this script.
if [ `id -u` != "0" ]; then
@ -68,31 +68,31 @@ if [ `id -u` != "0" ]; then
exit 1
fi
verify_sickbeard_pid() {
verify_sickgear_pid() {
# Make sure the pid corresponds to the SickGear process.
pid=`cat ${sickbeard_pid} 2>/dev/null`
ps -p ${pid} 2>/dev/null | grep -q "python ${sickbeard_dir}/SickBeard.py"
pid=`cat ${sickgear_pid} 2>/dev/null`
ps -p ${pid} 2>/dev/null | grep -q "python ${sickgear_dir}/SickBeard.py"
return $?
}
# Try to stop SickGear cleanly by calling shutdown over http.
sickbeard_stop() {
sickgear_stop() {
echo "Stopping $name"
verify_sickbeard_pid
sickbeard_url="${sickbeard_host}:${sickbeard_port}"
[ ! -z "${sickbeard_web_user}" ] && \
sickbeard_url="${sickbeard_web_user}:${sickbeard_web_password}@${sickbeard_url}"
[ ! -z "${sickbeard_webroot}" ] && \
sickbeard_url="${sickbeard_url}${sickbeard_webroot}"
fetch -o - -q "http://${sickbeard_url}/home/shutdown/?pid=${pid}" >/dev/null
verify_sickgear_pid
sickgear_url="${sickgear_host}:${sickgear_port}"
[ ! -z "${sickgear_web_user}" ] && \
sickgear_url="${sickgear_web_user}:${sickgear_web_password}@${sickgear_url}"
[ ! -z "${sickgear_webroot}" ] && \
sickgear_url="${sickgear_url}${sickgear_webroot}"
fetch -o - -q "http://${sickgear_url}/home/shutdown/?pid=${pid}" >/dev/null
if [ -n "${pid}" ]; then
wait_for_pids ${pid}
echo "Stopped"
fi
}
sickbeard_status() {
verify_sickbeard_pid && echo "$name is running as ${pid}" || echo "$name is not running"
sickgear_status() {
verify_sickgear_pid && echo "$name is running as ${pid}" || echo "$name is not running"
}
run_rc_command "$1"

View file

@ -9,15 +9,15 @@
# You will need to create a configuration file in order for this script
# to work properly. Please create /etc/conf.d/sickbeard with the following:
#
# SICKBEARD_USER=<user you want sickbeard to run under>
# SICKBEARD_GROUP=<group you want sickbeard to run under>
# SICKBEARD_DIR=<path to Sickbeard.py>
# SICKGEAR_USER=<user you want sickgear to run under>
# SICKGEAR_GROUP=<group you want sickgear to run under>
# SICKGEAR_DIR=<path to Sickbeard.py>
# PATH_TO_PYTHON_2=/usr/bin/python2
# SICKBEARD_DATADIR=<directory that contains sickbeard.db file>
# SICKBEARD_CONFDIR=<directory that contains Sickbeard's config.ini file>
# SICKGEAR_DATADIR=<directory that contains sickbeard.db file>
# SICKGEAR_CONFDIR=<directory that contains SickGear's config.ini file>
#
RUNDIR=/var/run/sickbeard
RUNDIR=/var/run/sickgear
depend() {
need net
@ -30,32 +30,32 @@ get_pidfile() {
-e 's/[[:space:]]*$//' \
-e 's/^[[:space:]]*//' \
-e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
< ${SICKBEARD_CONFDIR}/config.ini \
< ${SICKGEAR_CONFDIR}/config.ini \
| sed -n -e "/^\[General\]/,/^\s*\[/{/^[^;].*\=.*/p;}"`
echo "${RUNDIR}/sickbeard-${web_port}.pid"
echo "${RUNDIR}/sickgear-${web_port}.pid"
}
start() {
ebegin "Starting Sickbeard"
ebegin "Starting SickGear"
checkpath -q -d -o ${SICKBEARD_USER}:${SICKBEARD_GROUP} -m 0770 "${RUNDIR}"
checkpath -q -d -o ${SICKGEAR_USER}:${SICKGEAR_GROUP} -m 0770 "${RUNDIR}"
start-stop-daemon \
--quiet \
--start \
--user ${SICKBEARD_USER} \
--group ${SICKBEARD_GROUP} \
--name sickbeard \
--user ${SICKGEAR_USER} \
--group ${SICKGEAR_GROUP} \
--name sickgear \
--background \
--pidfile $(get_pidfile) \
--exec ${PATH_TO_PYTHON_2} \
-- \
${SICKBEARD_DIR}/SickBeard.py \
${SICKGEAR_DIR}/SickBeard.py \
-d \
--pidfile $(get_pidfile) \
--config ${SICKBEARD_CONFDIR}/config.ini \
--datadir ${SICKBEARD_DATADIR}
--config ${SICKGEAR_CONFDIR}/config.ini \
--datadir ${SICKGEAR_DATADIR}
eend $?
}
@ -74,5 +74,5 @@ stop() {
local pidfile=$(get_pidfile)
local rc
ebegin "Stopping Sickbeard"
ebegin "Stopping SickGear"
}

View file

@ -1,35 +1,35 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
Assumes user=sickbeard group=other
Assumes /opt/sickbeard is installation directory
Assumes user=sickgear group=other
Assumes /opt/sickgear is installation directory
See http://www.sun.com/bigadmin/content/selfheal/sdev_intro.jsp for more information
To install (see http://docs.sun.com/app/docs/doc/819-2379/fgour?l=en&a=view for more information)
svccfg import sickbeard.smf
svccfg import sickgear.smf
To enable/disable
svcadm enable sickbeard
svcadm disable sickbeard
svcadm enable sickgear
svcadm disable sickgear
To check if failures
svcs -xv
To check logs
tail /var/svc/log/network-sickbeard\:default.log
tail /var/svc/log/network-sickgear\:default.log
-->
<service_bundle type='manifest' name='sickbeard'>
<service_bundle type='manifest' name='sickgear'>
<service
name='network/sickbeard'
name='network/sickgear'
type='service'
version='1'>
<create_default_instance enabled='false' />
<single_instance />
<!--
Only start in muti-user mode
-->
@ -39,7 +39,7 @@
type='service'>
<service_fmri value='svc:/milestone/multi-user' />
</dependency>
<!--
Wait for network interfaces to be initialized.
-->
@ -49,7 +49,7 @@
type='service'>
<service_fmri value='svc:/milestone/network:default'/>
</dependency>
<!--
Wait for all local filesystems to be mounted.
-->
@ -59,37 +59,37 @@
type='service'>
<service_fmri value='svc:/system/filesystem/local:default'/>
</dependency>
<!-- execute as user sickbeard -->
<!-- execute as user sickgear -->
<method_context>
<method_credential user='sickbeard' group='other' />
<method_credential user='sickgear' group='other' />
</method_context>
<exec_method
type='method'
name='start'
exec='/opt/sickbeard/SickBeard.py --daemon'
exec='/opt/sickgear/SickBeard.py --daemon'
timeout_seconds='60'>
</exec_method>
<exec_method
type='method'
name='stop'
exec=':kill'
timeout_seconds='2'>
</exec_method>
<template>
<common_name>
<loctext xml:lang='C'>Sickbeard</loctext>
<loctext xml:lang='C'>SickGear</loctext>
</common_name>
<documentation>
<doc_link name='sickbeard'
uri='http://www.sickbeard.com/' />
<doc_link name='sickgear'
uri='https://github.com/SickGear/SickGear/' />
</documentation>
</template>
</service>
</service_bundle>

View file

@ -4,54 +4,54 @@
#
# - Option names (e.g. ExecStart=, Type=) are case-sensitive)
#
# - Adjust User= and Group= to the user/group you want Sickbeard to run as.
# - Adjust User= and Group= to the user/group you want SickGear to run as.
#
# - Optional adjust EnvironmentFile= path to configuration file
# Can ONLY be used for configuring extra options used in ExecStart.
# Putting a minus (-) in front of file means no error warning if the file doesn't exist
#
# - Adjust ExecStart= to point to your python and SickBeard executables.
# - Adjust ExecStart= to point to your python and SickGear executables.
# The FIRST token of the command line must be an ABSOLUTE FILE NAME,
# then followed by arguments for the process.
# If no --datadir is given, data is stored in same dir as SickBeard.py
# Arguments can also be set in EnvironmentFile (except python)
#
# - WantedBy= specifies which target (i.e. runlevel) to start Sickbeard for.
# - WantedBy= specifies which target (i.e. runlevel) to start SickGear for.
# multi-user.target equates to runlevel 3 (multi-user text mode)
# graphical.target equates to runlevel 5 (multi-user X11 graphical mode)
#
### Example Using SickBeard as daemon with pid file
### Example Using SickGear as daemon with pid file
# Type=forking
# PIDFile=/var/run/sickbeard/sickbeard.pid
# ExecStart=/usr/bin/python /opt/sickbeard/SickBeard.py -q --daemon --nolaunch --pidfile=/var/run/sickbeard/sickbeard.pid --datadir=/opt/sickbeard
# PIDFile=/var/run/sickgear/sickgear.pid
# ExecStart=/usr/bin/python /opt/sickgear/SickBeard.py -q --daemon --nolaunch --pidfile=/var/run/sickgear/sickgear.pid --datadir=/opt/sickgear
## Example Using SickBeard as daemon without pid file
## Example Using SickGear as daemon without pid file
# Type=forking
# GuessMainPID=no
# ExecStart=/usr/bin/python /opt/sickbeard/SickBeard.py -q --daemon --nolaunch --datadir=/opt/sickbeard
# ExecStart=/usr/bin/python /opt/sickgear/SickBeard.py -q --daemon --nolaunch --datadir=/opt/sickgear
### Example Using simple
# Type=simple
# ExecStart=/usr/bin/python /opt/sickbeard/SickBeard.py -q --nolaunch
# ExecStart=/usr/bin/python /opt/sickgear/SickBeard.py -q --nolaunch
### Example Using simple with EnvironmentFile where SB_DATA=/home/sickbeard/.sickbeard in /etc/sickbeard.conf
### Example Using simple with EnvironmentFile where SB_DATA=/home/sickgear/.sickgear in /etc/sickgear.conf
# Type=simple
# EnvironmentFile=/etc/sickbeard.conf
# ExecStart=/usr/bin/python /opt/sickbeard/SickBeard.py -q --nolaunch --datadir=${SB_DATA}
# EnvironmentFile=/etc/sickgear.conf
# ExecStart=/usr/bin/python /opt/sickgear/SickBeard.py -q --nolaunch --datadir=${SB_DATA}
### Configuration
[Unit]
Description=SickBeard Daemon
Description=SickGear Daemon
[Service]
User=sickbeard
Group=sickbeard
User=sickgear
Group=sickgear
Type=forking
GuessMainPID=no
ExecStart=/usr/bin/python /opt/sickbeard/SickBeard.py -q --daemon --nolaunch --datadir=/opt/sickbeard
ExecStart=/usr/bin/python /opt/sickgear/SickBeard.py -q --daemon --nolaunch --datadir=/opt/sickgear
[Install]
WantedBy=multi-user.target

View file

@ -1,7 +1,7 @@
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: sickbeard
# Provides: sickgear
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Should-Start: $NetworkManager
@ -12,55 +12,55 @@
# Description: starts instance of SickGear using start-stop-daemon
### END INIT INFO
# Source SickBeard configuration
if [ -f /etc/default/sickbeard ]; then
. /etc/default/sickbeard
# Source SickGear configuration
if [ -f /etc/default/sickgear ]; then
. /etc/default/sickgear
else
echo "/etc/default/sickbeard not found using default settings.";
echo "/etc/default/sickgear not found using default settings.";
fi
# Source init functions
. /lib/lsb/init-functions
# Script name
NAME=sickbeard
NAME=sickgear
# App name
DESC=SickBeard
DESC=SickGear
## Don't edit this file
## Edit user configuation in /etc/default/sickbeard to change
## Edit user configuation in /etc/default/sickgear to change
##
## SB_USER= #$RUN_AS, username to run sickbeard under, the default is sickbeard
## SB_HOME= #$APP_PATH, the location of SickBeard.py, the default is /opt/sickbeard
## SB_DATA= #$DATA_DIR, the location of sickbeard.db, cache, logs, the default is /opt/sickbeard
## SB_PIDFILE= #$PID_FILE, the location of sickbeard.pid, the default is /var/run/sickbeard/sickbeard.pid
## SG_USER= #$RUN_AS, username to run sickgear under, the default is sickgear
## SG_HOME= #$APP_PATH, the location of SickBeard.py, the default is /opt/sickgear
## SG_DATA= #$DATA_DIR, the location of sickbeard.db, cache, logs, the default is /opt/sickgear
## SG_PIDFILE= #$PID_FILE, the location of sickgear.pid, the default is /var/run/sickgear/sickgear.pid
## PYTHON_BIN= #$DAEMON, the location of the python binary, the default is /usr/bin/python
## SB_OPTS= #$EXTRA_DAEMON_OPTS, extra cli option for sickbeard, i.e. " --config=/home/sickbeard/config.ini"
## SG_OPTS= #$EXTRA_DAEMON_OPTS, extra cli option for sickgear, i.e. " --config=/home/sickgear/config.ini"
## SSD_OPTS= #$EXTRA_SSD_OPTS, extra start-stop-daemon option like " --group=users"
##
## EXAMPLE if want to run as different user
## add SB_USER=username to /etc/default/sickbeard
## otherwise default sickbeard is used
## add SG_USER=username to /etc/default/sickgear
## otherwise default sickgear is used
## The defaults
# Run as username
RUN_AS=${SB_USER-sickbeard}
# Run as username
RUN_AS=${SG_USER-sickgear}
# Path to app SB_HOME=path_to_app_SickBeard.py
APP_PATH=${SB_HOME-/opt/sickbeard}
# Path to app SG_HOME=path_to_app_SickBeard.py
APP_PATH=${SG_HOME-/opt/sickgear}
# Data directory where sickbeard.db, cache and logs are stored
DATA_DIR=${SB_DATA-/opt/sickbeard}
DATA_DIR=${SG_DATA-/opt/sickgear}
# Path to store PID file
PID_FILE=${SB_PIDFILE-/var/run/sickbeard/sickbeard.pid}
PID_FILE=${SG_PIDFILE-/var/run/sickgear/sickgear.pid}
# path to python bin
DAEMON=${PYTHON_BIN-/usr/bin/python}
# Extra daemon option like: SB_OPTS=" --config=/home/sickbeard/config.ini"
EXTRA_DAEMON_OPTS=${SB_OPTS-}
# Extra daemon option like: SG_OPTS=" --config=/home/sickgear/config.ini"
EXTRA_DAEMON_OPTS=${SG_OPTS-}
# Extra start-stop-daemon option like START_OPTS=" --group=users"
EXTRA_SSD_OPTS=${SSD_OPTS-}
@ -75,7 +75,7 @@ test -x $DAEMON || exit 0
set -e
# Create PID directory if not exist and ensure the SickBeard user can write to it
# Create PID directory if not exist and ensure the SickGear user can write to it
if [ ! -d $PID_PATH ]; then
mkdir -p $PID_PATH
chown $RUN_AS $PID_PATH
@ -94,28 +94,28 @@ if [ -e $PID_FILE ]; then
fi
fi
start_sickbeard() {
start_sickgear() {
echo "Starting $DESC"
start-stop-daemon -d $APP_PATH -c $RUN_AS $EXTRA_SSD_OPTS --start --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
}
stop_sickbeard() {
stop_sickgear() {
echo "Stopping $DESC"
start-stop-daemon --stop --pidfile $PID_FILE --retry 15
}
case "$1" in
start)
start_sickbeard
start_sickgear
;;
stop)
stop_sickbeard
stop_sickgear
;;
restart|force-reload)
stop_sickbeard
stop_sickgear
sleep 2
start_sickbeard
start_sickgear
;;
status)
status_of_proc -p "$PID_FILE" "$DAEMON" "$DESC"