[patchteam] - New Package - Deluge - with daemon, console and web ui
[openwrt/svn-archive/archive.git] / net / deluge / files / deluge.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2010 OpenWrt.org
3 # Copyright (C) 2010 Alexander Sulfrian
4
5 NAME=deluge
6 PIDFILE=/var/run/deluged.pid
7 START=50
8 STOP=50
9
10 load_config()
11 {
12 config_get_bool enabled $1 enabled 0
13 [ "${enabled}" -eq 0 ] && return 1
14
15 config_get user $1 user
16 if [ "${user}" == "" ]; then
17 echo "Please check your uci config. User for '$1' should not be empty."
18 return 1
19 fi
20
21 username=$(echo ${user} | cut -d ':' -f 1)
22 group=$(echo ${user} | cut -d ':' -f 2)
23
24 if ! $(cut -d ':' -f 1 /etc/passwd | grep -sq "${username}"); then
25 echo "Please check your uci config. User for '$1' should exist."
26 return 1
27 fi
28
29 if [ "${group}" != "" ]; then
30 if ! $(cut -d ':' -f 1 /etc/passwd | grep -sq "${group}"); then
31 echo "Please check your uci config. Group for '$1' should exist."
32 return 1
33 fi
34 fi
35 }
36
37 start()
38 {
39 config_load "${NAME}"
40 load_config deluged || return $?
41
42 config_get options deluged options
43
44 config_get home deluged home
45 if [ "${home}" == "" ]; then
46 home=$(grep "^${username}:" /etc/passwd | cut -d ':' -f 6)
47 fi
48
49 HOME="${home}" /sbin/start-stop-daemon -S -u "${username}" \
50 -p "${PIDFILE}" -b -m -x "/usr/bin/python2.6" -a deluged \
51 -c "${user}" -- --do-not-daemonize ${options}
52 }
53
54 stop()
55 {
56 config_load "${NAME}"
57 load_config deluged || return $?
58
59 /sbin/start-stop-daemon -K -u "${username}" -n deluged -p "${PIDFILE}"
60 }