Merge pull request #564 from adam111316/feature/MoveInitScripts

Change sickbeard variables to sickgear variables in init-scripts
This commit is contained in:
adam111316 2015-11-21 09:18:09 +08:00
commit b140770c36
9 changed files with 241 additions and 239 deletions

View file

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

View file

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

View file

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# #
### BEGIN INIT INFO ### BEGIN INIT INFO
# Provides: sickbeard # Provides: sickgear
# Required-Start: $all # Required-Start: $all
# Required-Stop: $all # Required-Stop: $all
# Default-Start: 2 3 4 5 # Default-Start: 2 3 4 5
@ -13,27 +13,27 @@
# Source function library. # Source function library.
. /etc/init.d/functions . /etc/init.d/functions
# Source SickBeard configuration # Source SickGear configuration
if [ -f /etc/sysconfig/sickbeard ]; then if [ -f /etc/sysconfig/sickgear ]; then
. /etc/sysconfig/sickbeard . /etc/sysconfig/sickgear
fi fi
prog=sickbeard prog=sickgear
lockfile=/var/lock/subsys/$prog 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 ## the defaults
username=${SB_USER-sickbeard} username=${SG_USER-sickgear}
homedir=${SB_HOME-/opt/sickbeard} homedir=${SG_HOME-/opt/sickgear}
datadir=${SB_DATA-/opt/sickbeard} datadir=${SG_DATA-/opt/sickgear}
pidfile=${SB_PIDFILE-/var/run/sickbeard/sickbeard.pid} pidfile=${SG_PIDFILE-/var/run/sickgear/sickgear.pid}
nice=${SB_NICE-} nice=${SG_NICE-}
## ##
pidpath=`dirname ${pidfile}` pidpath=`dirname ${pidfile}`
options=" --daemon --nolaunch --pidfile=${pidfile} --datadir=${datadir}" 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 if [ ! -d $pidpath ]; then
mkdir -p $pidpath mkdir -p $pidpath
chown $username $pidpath chown $username $pidpath

98
init-scripts/init.freebsd Executable file
View file

@ -0,0 +1,98 @@
#!/bin/sh
#
# PROVIDE: sickgear
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# sickgear_enable (bool): Set to NO by default.
# Set it to YES to enable it.
# 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.
# 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
# sickgear_port: The port SickGear is listening on
# Default is 8081
# sickgear_web_user: Username to authenticate to the SickGear web interface
# Default is an empty string (no username)
# sickgear_web_password: Password to authenticate to the SickGear web interface
# Default is an empty string (no password)
# 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="sickgear"
rcvar=${name}_enable
load_rc_config ${name}
: ${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 ${sickgear_pid} python ${sickgear_dir}/SickBeard.py --quiet --nolaunch"
# Add datadir to the command if set
[ ! -z "${sickgear_datadir}" ] && \
command_args="${command_args} --datadir ${sickgear_datadir}"
# Ensure user is root when running this script.
if [ `id -u` != "0" ]; then
echo "Oops, you should be root before running this!"
exit 1
fi
verify_sickgear_pid() {
# Make sure the pid corresponds to the SickGear process.
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.
sickgear_stop() {
echo "Stopping $name"
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
}
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 # 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: # to work properly. Please create /etc/conf.d/sickbeard with the following:
# #
# SICKBEARD_USER=<user you want sickbeard to run under> # SICKGEAR_USER=<user you want sickgear to run under>
# SICKBEARD_GROUP=<group you want sickbeard to run under> # SICKGEAR_GROUP=<group you want sickgear to run under>
# SICKBEARD_DIR=<path to Sickbeard.py> # SICKGEAR_DIR=<path to Sickbeard.py>
# PATH_TO_PYTHON_2=/usr/bin/python2 # PATH_TO_PYTHON_2=/usr/bin/python2
# SICKBEARD_DATADIR=<directory that contains sickbeard.db file> # SICKGEAR_DATADIR=<directory that contains sickbeard.db file>
# SICKBEARD_CONFDIR=<directory that contains Sickbeard's config.ini file> # SICKGEAR_CONFDIR=<directory that contains SickGear's config.ini file>
# #
RUNDIR=/var/run/sickbeard RUNDIR=/var/run/sickgear
depend() { depend() {
need net need net
@ -30,32 +30,32 @@ get_pidfile() {
-e 's/[[:space:]]*$//' \ -e 's/[[:space:]]*$//' \
-e 's/^[[:space:]]*//' \ -e 's/^[[:space:]]*//' \
-e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \ -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
< ${SICKBEARD_CONFDIR}/config.ini \ < ${SICKGEAR_CONFDIR}/config.ini \
| sed -n -e "/^\[General\]/,/^\s*\[/{/^[^;].*\=.*/p;}"` | sed -n -e "/^\[General\]/,/^\s*\[/{/^[^;].*\=.*/p;}"`
echo "${RUNDIR}/sickbeard-${web_port}.pid" echo "${RUNDIR}/sickgear-${web_port}.pid"
} }
start() { 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 \ start-stop-daemon \
--quiet \ --quiet \
--start \ --start \
--user ${SICKBEARD_USER} \ --user ${SICKGEAR_USER} \
--group ${SICKBEARD_GROUP} \ --group ${SICKGEAR_GROUP} \
--name sickbeard \ --name sickgear \
--background \ --background \
--pidfile $(get_pidfile) \ --pidfile $(get_pidfile) \
--exec ${PATH_TO_PYTHON_2} \ --exec ${PATH_TO_PYTHON_2} \
-- \ -- \
${SICKBEARD_DIR}/SickBeard.py \ ${SICKGEAR_DIR}/SickBeard.py \
-d \ -d \
--pidfile $(get_pidfile) \ --pidfile $(get_pidfile) \
--config ${SICKBEARD_CONFDIR}/config.ini \ --config ${SICKGEAR_CONFDIR}/config.ini \
--datadir ${SICKBEARD_DATADIR} --datadir ${SICKGEAR_DATADIR}
eend $? eend $?
} }
@ -74,5 +74,5 @@ stop() {
local pidfile=$(get_pidfile) local pidfile=$(get_pidfile)
local rc local rc
ebegin "Stopping Sickbeard" ebegin "Stopping SickGear"
} }

View file

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

View file

@ -4,54 +4,54 @@
# #
# - Option names (e.g. ExecStart=, Type=) are case-sensitive) # - 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 # - Optional adjust EnvironmentFile= path to configuration file
# Can ONLY be used for configuring extra options used in ExecStart. # 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 # 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, # The FIRST token of the command line must be an ABSOLUTE FILE NAME,
# then followed by arguments for the process. # then followed by arguments for the process.
# If no --datadir is given, data is stored in same dir as SickBeard.py # If no --datadir is given, data is stored in same dir as SickBeard.py
# Arguments can also be set in EnvironmentFile (except python) # 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) # multi-user.target equates to runlevel 3 (multi-user text mode)
# graphical.target equates to runlevel 5 (multi-user X11 graphical 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 # Type=forking
# PIDFile=/var/run/sickbeard/sickbeard.pid # PIDFile=/var/run/sickgear/sickgear.pid
# ExecStart=/usr/bin/python /opt/sickbeard/SickBeard.py -q --daemon --nolaunch --pidfile=/var/run/sickbeard/sickbeard.pid --datadir=/opt/sickbeard # 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 # Type=forking
# GuessMainPID=no # 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 ### Example Using simple
# Type=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 # Type=simple
# EnvironmentFile=/etc/sickbeard.conf # EnvironmentFile=/etc/sickgear.conf
# ExecStart=/usr/bin/python /opt/sickbeard/SickBeard.py -q --nolaunch --datadir=${SB_DATA} # ExecStart=/usr/bin/python /opt/sickgear/SickBeard.py -q --nolaunch --datadir=${SB_DATA}
### Configuration ### Configuration
[Unit] [Unit]
Description=SickBeard Daemon Description=SickGear Daemon
[Service] [Service]
User=sickbeard User=sickgear
Group=sickbeard Group=sickgear
Type=forking Type=forking
GuessMainPID=no 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] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

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

View file

@ -1,98 +0,0 @@
#!/bin/sh
#
# PROVIDE: sickbeard
# 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.
# Set it to YES to enable it.
# sickbeard_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
# Default is 127.0.0.1
# sickbeard_port: The port SickGear is listening on
# Default is 8081
# sickbeard_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
# Default is an empty string (no password)
# sickbeard_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"
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:=""}
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"
# Add datadir to the command if set
[ ! -z "${sickbeard_datadir}" ] && \
command_args="${command_args} --datadir ${sickbeard_datadir}"
# Ensure user is root when running this script.
if [ `id -u` != "0" ]; then
echo "Oops, you should be root before running this!"
exit 1
fi
verify_sickbeard_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"
return $?
}
# Try to stop SickGear cleanly by calling shutdown over http.
sickbeard_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
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"
}
run_rc_command "$1"