2010-03-13 03:02:58 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
2011-11-16 09:44:27 +00:00
|
|
|
# Copyright (C) 2010-2011 OpenWrt.org
|
2010-03-13 03:02:58 +00:00
|
|
|
# Copyright (C) 2010 Alexander Sulfrian
|
|
|
|
|
|
|
|
START=50
|
|
|
|
STOP=50
|
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
SERVICE_DAEMONIZE=1
|
|
|
|
SERVICE_WRITE_PID=1
|
|
|
|
SERVICE_PID_FILE="/var/run/deluged.pid"
|
2010-03-13 03:02:58 +00:00
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
error() {
|
|
|
|
echo "${initscript}:" "$@" 1>&2
|
|
|
|
}
|
|
|
|
|
|
|
|
section_enabled() {
|
|
|
|
config_get_bool enabled "$1" 'enabled' 0
|
|
|
|
[ $enabled -gt 0 ]
|
|
|
|
}
|
2010-03-13 03:02:58 +00:00
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
start_instance() {
|
|
|
|
local s="$1"
|
2010-03-13 03:02:58 +00:00
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
section_enabled "$s" || return 1
|
|
|
|
|
|
|
|
config_get uid "$s" 'user'
|
|
|
|
[ -n "$uid" ] || {
|
|
|
|
error "user is not set"
|
2010-03-13 03:02:58 +00:00
|
|
|
return 1
|
2011-11-16 09:44:27 +00:00
|
|
|
}
|
|
|
|
user_exists $uid || {
|
|
|
|
error "user '$uid' dos not exist"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
config_get gid "$s" 'group'
|
|
|
|
[ -n "$gid" ] || {
|
|
|
|
error "group is not set"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
group_exists $gid || {
|
|
|
|
error "group '$gid' dos not exist"
|
|
|
|
return 1
|
|
|
|
}
|
2010-03-13 03:02:58 +00:00
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
config_get home "$s" 'home'
|
|
|
|
[ -n "$home" ] || {
|
|
|
|
home=$(grep "^${user}:" /etc/passwd | cut -d ':' -f 6)
|
2010-03-13 03:02:58 +00:00
|
|
|
fi
|
2011-11-16 09:44:27 +00:00
|
|
|
[ -d "$home" ] || {
|
|
|
|
error "home directory '$home' for user '$uid' dos not exist"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
config_get options "$s" 'options'
|
|
|
|
|
|
|
|
HOME="$home" \
|
|
|
|
SERVICE_UID="$uid" \
|
|
|
|
SERVICE_GID="$gid" \
|
|
|
|
service_start /usr/bin/python2.6 /usr/bin/deluged --do-not-daemonize $options
|
2010-03-13 03:02:58 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
stop_instance() {
|
|
|
|
local s="$1"
|
2010-03-13 03:02:58 +00:00
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
section_enabled "$s" || return 1
|
2010-03-13 03:02:58 +00:00
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
config_get uid "$s" 'user'
|
|
|
|
config_get gid "$s" 'group'
|
2010-03-13 03:02:58 +00:00
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
SERVICE_UID="$uid" \
|
|
|
|
SERVICE_GID="$gid" \
|
|
|
|
service_stop /usr/bin/python2.6
|
2010-03-13 03:02:58 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
start()
|
2010-03-13 03:02:58 +00:00
|
|
|
{
|
2011-11-16 09:44:27 +00:00
|
|
|
config_load 'deluged'
|
|
|
|
config_foreach start_instance 'deluged'
|
|
|
|
}
|
2010-03-13 03:02:58 +00:00
|
|
|
|
2011-11-16 09:44:27 +00:00
|
|
|
stop()
|
|
|
|
{
|
|
|
|
config_load 'deluged'
|
|
|
|
config_foreach stop_instance 'deluged'
|
2010-03-13 03:02:58 +00:00
|
|
|
}
|