forked from nickbock/Sick-Beard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.freebsd
executable file
·111 lines (95 loc) · 3.29 KB
/
init.freebsd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
#
# PROVIDE: sickbeard
# REQUIRE: wget
# 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 SickBeard daemon runs as what
# you want it to be. It uses '_sabnzbd' user by
# default. Do not set it as empty or it will run
# as root.
# sickbeard_dir: Directory where Sick Beard lives.
# Default: /usr/local/sickbeard
# sickbeard_chdir: Change to this directory before running Sick Beard.
# Default is same as sickbeard_dir.
# sickbeard_pid: The name of the pidfile to create.
# Default is sickbeard.pid in sickbeard_dir.
# sickbeard_flags: Change or add startup arguments for sickbeard.
# Default: --quiet --nolaunch
#
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_pid:="${sickbeard_dir}/sickbeard.pid"}
: ${sickbeard_flags:="--quiet --nolaunch"}
required_dirs=${sickbeard_dir}
WGET="/usr/local/bin/wget" # You need wget for this script to safely shutdown Sick Beard.
status_cmd="${name}_status"
stop_cmd="${name}_stop"
command="${sickbeard_dir}/SickBeard.py"
command_args="--daemon --pidfile=${sickbeard_pid}"
# Check for wget and refuse to start without it.
if [ ! -x "${WGET}" ]; then
warn "Sickbeard not started: You need wget to safely shut down Sick Beard."
exit 1
fi
# 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
# Try to stop Sick Beard cleanly by calling shutdown over http.
sickbeard_stop() {
echo "Stopping $name"
if [ -f ${sickbeard_pid} ]; then
pid=`cat ${sickbeard_pid} 2>/dev/null`
else
pid=`ps -U ${sickbeard_user} | grep "python.*SickBeard.py.*--daemon" | grep -v 'grep' | awk '{print $1}'`
fi
if [ -n "${pid}" ]; then
if [ -f "${sickbeard_dir}/config.ini" ]; then
host=`grep -m1 -E '^web_host\ =\ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' ${sickbeard_dir}/config.ini | tr -dc '[0-9].'`
port=`grep -m1 ^web_port ${sickbeard_dir}/config.ini | tr -dc '[0-9]'`
sbusr=`grep -m1 ^web_username ${sickbeard_dir}/config.ini | /usr/bin/awk '{print $3}'`
sbpwd=`grep -m1 ^web_password ${sickbeard_dir}/config.ini | /usr/bin/awk '{print $3}'`
if [ ${sbusr} = '""' ]; then
sbusr=""
fi
if [ ${sbpwd} = '""' ]; then
sbpwd=""
fi
${WGET} -O - -q --user=${sbusr} --password=${sbpwd} "http://${host}:${port}/home/shutdown/?pid=${pid}" >/dev/null
else
kill ${pid}
fi
wait_for_pids ${pid}
echo "Stopped"
else
echo "Stopping $name failed. $name is not running"
fi
}
sickbeard_status() {
if [ -f ${sickbeard_pid} ]; then
pid=`cat ${sickbeard_pid} 2>/dev/null`
echo "$name is running as ${pid}"
else
pid=`ps -U ${sickbeard_user} | grep "python.*SickBeard.py.*--daemon" | grep -v 'grep' | awk '{print $1}'`
if [ -n "${pid}" ]; then
echo "No PID file found for $name. $name is running as ${pid}"
else
echo "$name is not running"
fi
fi
}
run_rc_command "$1"