rblibtorrent, deluge: broken for ages, moved to abandoned github feed
[openwrt.org/packages.git] / net / deluge.init
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
#!/bin/sh /etc/rc.common
# Copyright (C) 2010-2011 OpenWrt.org
# Copyright (C) 2010 Alexander Sulfrian

START=50
STOP=50

SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
SERVICE_PID_FILE="/var/run/deluged.pid"

error() {
	echo "${initscript}:" "$@" 1>&2
}

section_enabled() {
	config_get_bool enabled "$1" 'enabled' 0
	[ $enabled -gt 0 ]
}

start_instance() {
	local s="$1"

	section_enabled "$s" || return 1

	config_get uid "$s" 'user'
	[ -n "$uid" ] || {
		error "user is not set"
		return 1
	}
	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
	}

	config_get home "$s" 'home'
	[ -n "$home" ] || {
		home=$(grep "^${user}:" /etc/passwd | cut -d ':' -f 6)
	fi
	[ -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
}

stop_instance() {
	local s="$1"

	section_enabled "$s" || return 1

	config_get uid "$s" 'user'
	config_get gid "$s" 'group'

	SERVICE_UID="$uid" \
	SERVICE_GID="$gid" \
	service_stop /usr/bin/python2.6
}

start()
{
	config_load 'deluged'
	config_foreach start_instance 'deluged'
}

stop()
{
	config_load 'deluged'
	config_foreach stop_instance 'deluged'
}

comments