Lines 1-7
Link Here
|
1 |
#!/sbin/runscript |
1 |
#!/sbin/runscript |
2 |
# Copyright 1999-2013 Gentoo Foundation |
2 |
# Copyright 1999-2013 Gentoo Foundation |
3 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# Distributed under the terms of the GNU General Public License v2 |
4 |
# $Header: /var/cvsroot/gentoo-x86/net-nntp/sabnzbd/files/sabnzbd.initd,v 1.5 2013/06/25 03:48:26 jsbronder Exp $ |
|
|
5 |
|
4 |
|
6 |
RUNDIR=/var/run/sabnzbd |
5 |
RUNDIR=/var/run/sabnzbd |
7 |
|
6 |
|
Lines 9-14
Link Here
|
9 |
need net |
8 |
need net |
10 |
} |
9 |
} |
11 |
|
10 |
|
|
|
11 |
get_var() { |
12 |
|
13 |
echo $(sed -n '/\[misc]/,/'$1'/ s/'$1' = \([[:alnum:].]\+\).*/\1/p' ${SABNZBD_CONFIGFILE}) |
14 |
} |
15 |
|
16 |
get_port() { |
17 |
|
18 |
[[ $(get_var 'enable_https') == 1 ]] && echo $(get_var 'https_port') || echo $(get_var 'port') |
19 |
} |
20 |
|
21 |
get_addr() { |
22 |
|
23 |
local host=$(get_var 'host') |
24 |
local port=$(get_port) |
25 |
local protocol |
26 |
|
27 |
[[ ${host} == "0.0.0.0" ]] && host=localhost |
28 |
[[ $(get_var 'enable_https') == 1 ]] && protocol="https" || protocol="http" |
29 |
|
30 |
echo ${protocol}://${host}:${port} |
31 |
|
32 |
} |
33 |
|
34 |
get_pidfile() { |
35 |
|
36 |
local port=$(get_port) |
37 |
echo "${RUNDIR}/sabnzbd-${port}.pid" |
38 |
} |
39 |
|
12 |
start() { |
40 |
start() { |
13 |
ebegin "Starting SABnzbd" |
41 |
ebegin "Starting SABnzbd" |
14 |
|
42 |
|
Lines 20-95
Link Here
|
20 |
--user ${SABNZBD_USER} \ |
48 |
--user ${SABNZBD_USER} \ |
21 |
--group ${SABNZBD_GROUP} \ |
49 |
--group ${SABNZBD_GROUP} \ |
22 |
--name sabnzbd \ |
50 |
--name sabnzbd \ |
|
|
51 |
--background \ |
23 |
--pidfile $(get_pidfile) \ |
52 |
--pidfile $(get_pidfile) \ |
24 |
--exec /usr/bin/sabnzbd \ |
53 |
--exec /usr/bin/sabnzbd \ |
25 |
-- \ |
54 |
-- \ |
26 |
--config-file ${SABNZBD_CONFIGFILE} \ |
55 |
--config-file ${SABNZBD_CONFIGFILE} \ |
27 |
--logging ${SABNZBD_LOGGING} \ |
56 |
--logging ${SABNZBD_LOGGING} \ |
28 |
--daemon \ |
57 |
--daemon \ |
29 |
--pid "${RUNDIR}" |
58 |
--pid ${RUNDIR} |
30 |
|
59 |
|
31 |
eend $? |
60 |
eend $? |
32 |
} |
61 |
} |
33 |
|
62 |
|
34 |
get_var() { |
|
|
35 |
echo $(echo $(grep "^$1" ${SABNZBD_CONFIGFILE} | head -n 1 | sed 's/\r//' | awk '{print $3}')) |
36 |
} |
37 |
|
38 |
get_pidfile () { |
39 |
# pid file name is hard-coded in sabnzbd, this must match |
40 |
local ssl=$(get_var 'enable_https') |
41 |
|
42 |
if [ -z "${ssl}" ]; then |
43 |
echo "${RUNDIR}/sabnzbd-8080.pid" |
44 |
elif [ ${ssl} -eq 0 ]; then |
45 |
echo "${RUNDIR}/sabnzbd-$(get_var 'port').pid" |
46 |
else |
47 |
echo "${RUNDIR}/sabnzbd-$(get_var 'https_port').pid" |
48 |
fi |
49 |
} |
50 |
|
51 |
get_addr() { |
52 |
local host=$(get_var 'host') |
53 |
#local ssl=$(get_var 'enable_https') |
54 |
#local ssl_port=$(get_var 'https_port') |
55 |
local port=$(get_var 'port') |
56 |
|
57 |
if [ "${host}" == "0.0.0.0" ]; then |
58 |
host=localhost |
59 |
fi |
60 |
|
61 |
# sabnzbd seems to only respond correctly to non ssl requests |
62 |
echo ${host}:${port} |
63 |
} |
64 |
|
63 |
|
65 |
stop() { |
64 |
stop() { |
66 |
local api_key=$(get_var 'api_key') |
65 |
local api_key=$(get_var 'api_key') |
67 |
local rc t |
66 |
local addr=$(get_addr) |
|
|
67 |
local pidfile=$(get_pidfile) |
68 |
local rc |
69 |
|
70 |
ebegin "Stopping SABnzbd" |
71 |
|
72 |
einfo "Attempting web-based shutdown @ ${addr}" |
73 |
|
74 |
# SABnzbd will return "ok" if shutdown is successful |
75 |
rc=$(/usr/bin/curl -k -s "${addr}/sabnzbd/api?mode=shutdown&apikey=${api_key}") |
76 |
[[ ${rc} == "ok" ]] && rc=0 || rc=1 |
68 |
|
77 |
|
69 |
ebegin "Stopping SABnzbd @ $(get_addr)" |
78 |
if [ ${rc} -eq 1 ]; then |
70 |
|
|
|
71 |
/usr/bin/wget -q --delete-after --no-check-certificate \ |
72 |
"http://$(get_addr)/sabnzbd/api?mode=shutdown&apikey=${api_key}" |
73 |
rc=$? |
74 |
|
75 |
if [ ${rc} -eq 0 ]; then |
76 |
# Wait for sabnzbd to fully shutdown. |
77 |
for ((t=0; t < 30; t++)); do |
78 |
sleep 0.5 |
79 |
[ ! -s $(get_pidfile) ] && break |
80 |
done |
81 |
fi |
82 |
|
83 |
if [ -s $(get_pidfile) ]; then |
84 |
# Using wget didn't work, resort to start-stop-daemon |
85 |
einfo "Falling back to SIGTERM, this may not work if you restarted via the web interface" |
79 |
einfo "Falling back to SIGTERM, this may not work if you restarted via the web interface" |
86 |
start-stop-daemon \ |
80 |
start-stop-daemon \ |
87 |
--stop \ |
81 |
--stop \ |
88 |
--pidfile $(get_pidfile) \ |
82 |
--pidfile ${pidfile} \ |
89 |
--retry SIGTERM/1/SIGKILL/5 |
83 |
--retry SIGTERM/1/SIGKILL/5 |
90 |
rc=$? |
84 |
rc=$? |
91 |
fi |
85 |
fi |
92 |
|
86 |
|
93 |
eend ${rc} |
87 |
eend ${rc} |
94 |
} |
88 |
} |
95 |
|
|
|