Lines 1-5
Link Here
|
1 |
#!/bin/sh |
1 |
#!/bin/sh |
2 |
# |
2 |
# |
|
|
3 |
# $FreeBSD$ |
4 |
# |
3 |
# PROVIDE: sabnzbd |
5 |
# PROVIDE: sabnzbd |
4 |
# KEYWORD: shutdown |
6 |
# KEYWORD: shutdown |
5 |
# |
7 |
# |
Lines 22-91
Link Here
|
22 |
|
24 |
|
23 |
. /etc/rc.subr |
25 |
. /etc/rc.subr |
24 |
|
26 |
|
25 |
name="sabnzbd" |
27 |
name=sabnzbd |
26 |
rcvar=sabnzbd_enable |
28 |
rcvar=sabnzbd_enable |
27 |
|
|
|
28 |
# Required, for some reason, to find all our binaries when starting via service. |
29 |
PATH="%%PREFIX%%/bin:$PATH" |
30 |
|
31 |
load_rc_config ${name} |
29 |
load_rc_config ${name} |
32 |
|
30 |
|
33 |
: ${sabnzbd_enable:="NO"} |
31 |
: ${sabnzbd_enable:=NO} |
34 |
: ${sabnzbd_user:="_sabnzbd"} |
32 |
: ${sabnzbd_user:=_sabnzbd} |
35 |
: ${sabnzbd_group:="_sabnzbd"} |
33 |
: ${sabnzbd_group:=_sabnzbd} |
36 |
: ${sabnzbd_conf_dir:="%%PREFIX%%/sabnzbd"} |
34 |
: ${sabnzbd_conf_dir="%%PREFIX%%/sabnzbd"} |
37 |
|
35 |
|
38 |
required_dirs=${sabnzbd_conf_dir} |
36 |
required_dirs=${sabnzbd_conf_dir} |
39 |
|
37 |
|
40 |
start_cmd="${name}_start" |
38 |
start_cmd="${name}_start" |
41 |
#start_postcmd="${name}_poststart" |
|
|
42 |
status_cmd="${name}_status" |
39 |
status_cmd="${name}_status" |
43 |
stop_cmd="${name}_stop" |
40 |
stop_cmd="${name}_stop" |
44 |
start_precmd=sabnzbd_check_dir |
41 |
start_precmd=sabnzbd_check_dir |
45 |
|
42 |
|
46 |
|
|
|
47 |
|
48 |
sabnzbd_start() |
43 |
sabnzbd_start() |
49 |
{ |
44 |
{ |
50 |
if [ ! -f "${sabnzbd_pid}" ]; then |
45 |
if [ ! -f "${sabnzbd_pid}" ]; then |
51 |
su -m ${sabnzbd_user} -c "%%PREFIX%%/bin/SABnzbd.py --daemon -f ${sabnzbd_conf_dir}/sabnzbd.ini" |
46 |
su -m ${sabnzbd_user} -c "%%PREFIX%%/bin/SABnzbd.py --daemon -f ${sabnzbd_conf_dir}/sabnzbd.ini" |
52 |
echo "Starting ${name}." |
47 |
echo "Starting ${name}." |
53 |
else |
48 |
else |
54 |
GETPROCESSPID=`/bin/ps -auxw | /usr/bin/awk '/SABnzbd.py/ && !/awk/ && !/sh/ {print $2}'` |
49 |
GETPROCESSPID=`/bin/ps -auxw | /usr/bin/awk '/SABnzbd.py/ && !/awk/ && !/sh/ {print $2}'` |
55 |
PIDFROMFILE=`cat ${sabnzbd_pid}` |
50 |
PIDFROMFILE=`cat ${sabnzbd_pid}` |
56 |
if [ "$GETPROCESSPID" = "$PIDFROMFILE" ]; then |
51 |
if [ "$GETPROCESSPID" = "$PIDFROMFILE" ]; then |
57 |
echo "${name} already running with PID: ${PIDFROMFILE} ?" |
52 |
echo "${name} already running with PID: ${PIDFROMFILE} ?" |
58 |
echo "Remove ${sabnzbd_pid} manually if needed." |
53 |
echo "Remove ${sabnzbd_pid} manually if needed." |
59 |
else |
54 |
else |
60 |
rm -f ${sabnzbd_pid} |
55 |
rm -f ${sabnzbd_pid} |
61 |
su -m ${sabnzbd_user} -c "%%PREFIX%%/bin/SABnzbd.py --daemon -f ${sabnzbd_conf_dir}/sabnzbd.ini" |
56 |
su -m ${sabnzbd_user} -c "%%PREFIX%%/bin/SABnzbd.py --daemon -f ${sabnzbd_conf_dir}/sabnzbd.ini" |
62 |
echo "Starting ${name}." |
57 |
echo "Starting ${name}." |
63 |
fi |
58 |
fi |
64 |
fi |
59 |
fi |
65 |
} |
60 |
} |
66 |
|
61 |
|
67 |
#sabnzbd_poststart() { |
|
|
68 |
# echo `/bin/ps -auxw | /usr/bin/awk '/SABnzbd.py/ && !/awk/ {print $2}'` > $sabnzbd_pid |
69 |
#} |
70 |
|
71 |
# SABnzbd can only be cleanly stopped by calling the http api |
62 |
# SABnzbd can only be cleanly stopped by calling the http api |
72 |
sabnzbd_stop() { |
63 |
sabnzbd_stop() |
73 |
echo "Stopping $name" |
64 |
{ |
74 |
if [ -f "${sabnzbd_conf_dir}/sabnzbd.ini" ]; then |
65 |
echo "Stopping $name" |
75 |
apikey=`grep ^api_key ${sabnzbd_conf_dir}/sabnzbd.ini | tr -d " _"` |
66 |
if [ -f "${sabnzbd_conf_dir}/sabnzbd.ini" ]; then |
76 |
host=`grep -m1 -E '^host\ =\ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9].'` |
67 |
apikey=`grep ^api_key ${sabnzbd_conf_dir}/sabnzbd.ini | tr -d " _"` |
77 |
if [ ${host} = "0.0.0.0" ] ; then host="localhost" ; fi |
68 |
host=`grep -m1 -E '^host\ =\ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9].'` |
78 |
port=`grep -m1 ^port ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9]'` |
69 |
if [ ${host} = "0.0.0.0" ] ; then |
79 |
fetch -o /dev/null "http://${host}:${port}/api?mode=shutdown&${apikey}" > /dev/null 2>&1 |
70 |
host="localhost" ; |
80 |
else |
71 |
fi |
81 |
sabnzbd_pid=`ps -U ${sabnzbd_user} | grep "python.*SABnzbd.py.*--daemon" | grep -v 'grep' | awk '{print $1}'` |
72 |
port=`grep -m1 ^port ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9]'` |
82 |
if [ -n "${sabnzbd_pid}" ]; then |
73 |
fetch -o /dev/null "http://${host}:${port}/api?mode=shutdown&${apikey}" > /dev/null 2>&1 |
83 |
kill ${sabnzbd_pid} |
74 |
else |
84 |
fi |
75 |
sabnzbd_pid=`ps -U ${sabnzbd_user} | grep "python.*SABnzbd.py.*--daemon" | grep -v 'grep' | awk '{print $1}'` |
85 |
fi |
76 |
if [ -n "${sabnzbd_pid}" ]; then |
|
|
77 |
kill ${sabnzbd_pid} |
78 |
fi |
79 |
fi |
86 |
} |
80 |
} |
87 |
|
81 |
|
88 |
sabnzbd_status() { |
82 |
sabnzbd_status() |
|
|
83 |
{ |
89 |
sabnzbd_pid=`ps -U ${sabnzbd_user} | grep "python.*SABnzbd.py.*--daemon" | grep -v 'grep' | awk '{print $1}'` |
84 |
sabnzbd_pid=`ps -U ${sabnzbd_user} | grep "python.*SABnzbd.py.*--daemon" | grep -v 'grep' | awk '{print $1}'` |
90 |
if [ -n "${sabnzbd_pid}" ]; then |
85 |
if [ -n "${sabnzbd_pid}" ]; then |
91 |
echo "$name is running as ${sabnzbd_pid}" |
86 |
echo "$name is running as ${sabnzbd_pid}" |
Lines 94-103
Link Here
|
94 |
fi |
89 |
fi |
95 |
} |
90 |
} |
96 |
|
91 |
|
97 |
sabnzbd_check_dir() { |
92 |
sabnzbd_check_dir() |
|
|
93 |
{ |
98 |
if [ ! -f "${required_dirs}" -a ! -d "${required_dirs}" -a ! -L "${required_dirs}" ]; then |
94 |
if [ ! -f "${required_dirs}" -a ! -d "${required_dirs}" -a ! -L "${required_dirs}" ]; then |
99 |
mkdir -p ${required_dirs} |
95 |
install -d -o ${sabnzbd_user} -g ${sabnzbd_group} ${required_dirs} |
100 |
chown ${sabnzbd_user}:${sabnzbd_group} ${required_dirs} |
|
|
101 |
fi |
96 |
fi |
102 |
} |
97 |
} |