summaryrefslogtreecommitdiff
blob: 84aa9b3db3676c61a86ac919b33cf83976159b7f (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/sbin/runscript

opts="start stop restart slow fast info"

depend() {
	need net
}

start() {
	ebegin "Starting mldonkey"
	if [ ! -d ${BASEDIR}/${SUBDIR} ]
	then
		einfo "Directory ${BASEDIR}/${SUBDIR} not existing, trying to create..."
		su ${USER} -c "mkdir ${BASEDIR}/${SUBDIR}" 
		if [ ! -d ${BASEDIR}/${SUBDIR} ]
		then
			eerror "Directory ${BASEDIR}/${SUBDIR} could not be created!"
			return 1
		fi
		einfo "...ok!"
	fi
	cd ${BASEDIR}/${SUBDIR}/
	env HOME=${BASEDIR} start-stop-daemon --quiet --start -c ${USER}  \
		-x /usr/bin/mlnet &>${LOG} &
	sleep 5
	if ! pgrep -u ${USER} mlnet >/dev/null
	then
		eerror "MLDonkey could not be started! Check logfile: ${LOG}"
	fi
	renice ${NICE} -u ${USER} >/dev/null
	eend $?
}

stop() {
	BASE="http://"
	if [[ -n ${USERNAME} && -n ${PASSWORD} ]]
	then
		BASE=${BASE}${USERNAME}:${PASSWORD}@
	fi
	BASE=${BASE}${SERVER}:${PORT}
	ebegin "Stopping mldonkey - please wait"
	wget --spider ${BASE}/submit?q=close_fds -q 
	wget --spider ${BASE}/submit?q=save -q 
	wget --spider ${BASE}/submit?q=kill -q 
	sleep 10
	start-stop-daemon --oknodo --stop -x /usr/bin/mlnet &>/dev/null
	eend $?
}

restart() {
	svc_stop
	sleep 5
	svc_start
}

slow() {
	if ! service_started mldonkey
	then
		start_service mldonkey
	fi
	ebegin "Reducing bandwidth to ${LOW_DOWN}k/${LOW_UP}k"

	BASE="http://"
	if [[ -n ${USERNAME} && -n ${PASSWORD} ]]
	then
		BASE=${BASE}${USERNAME}:${PASSWORD}@
	fi
	BASE=${BASE}${SERVER}:${PORT}

	wget --spider ${BASE}/submit?q=set+max_hard_download_rate+${LOW_DOWN} -q 

	wget --spider ${BASE}/submit?q=set+max_hard_upload_rate+${LOW_UP} -q 

	eend $?
}

fast() {
	if ! service_started mldonkey
	then
		start_service mldonkey
	fi
	ebegin "Increasing bandwidth to ${HIGH_DOWN}k/${HIGH_UP}k"

	BASE="http://"
	if [[ -n ${USERNAME} && -n ${PASSWORD} ]]
	then
		BASE=${BASE}${USERNAME}:${PASSWORD}@
	fi
	BASE=${BASE}${SERVER}:${PORT}

	wget --spider ${BASE}/submit?q=set+max_hard_download_rate+${HIGH_DOWN} -q 

	wget --spider ${BASE}/submit?q=set+max_hard_upload_rate+${HIGH_UP} -q 

	eend $?
}


info() {
	if service_started mldonkey 
	then
		BASE="http://"
		if [[ -n ${USERNAME} && -n ${PASSWORD} ]]
		then
			BASE=${BASE}${USERNAME}:${PASSWORD}@
		fi

		BASE=${BASE}${SERVER}:${PORT}
		VALUE=$(/usr/bin/wget -O - ${BASE}/submit?q=vo 2> /dev/null| /bin/grep  -C1 max_hard_upload|/usr/bin/tail -n 1|/bin/cut -d\" -f2)
		if [[ ${VALUE} -eq ${LOW_UP} ]]
		then
			INFO="mldonkey runs slow"
		else
			INFO="mldonkey runs fast"
		fi
	else
		INFO="mldonkey is not running"
	fi
	einfo "$INFO"
}