blob: b7e5613723924342db74fd19d88c87884d445e45 (
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#!/sbin/openrc-run
extra_started_commands="reload slow fast info"
MLDONKEY_BINARY=${MLDONKEY_BINARY:-/usr/bin/mlnet}
MLDONKEY_TIMEOUT=${TIMEOUT:-10}
depend() {
need localmount net
${USE_LOGGER} && use logger
}
start() {
if [ -z "${MLDONKEY_DIR}" ]; then
ewarn "mldonkey's start script has been changed. You should remove"
ewarn "BASEDIR and SUBDIR from /etc/conf.d/mldonkey and set MLDONKEY_DIR"
ewarn "to the correct value (you probably want"
ewarn "MLDONKEY_DIR=${BASEDIR}/${SUBDIR})"
MLDONKEY_DIR="${BASEDIR}/${SUBDIR}"
einfo "Using ${MLDONKEY_DIR} as working directory"
fi
if [ ! -d "${MLDONKEY_DIR}" ]; then
ebegin "Directory ${MLDONKEY_DIR} not existing, trying to create..."
mkdir -p "${MLDONKEY_DIR}" && chown ${USER}:users "${MLDONKEY_DIR}"
eend $? || return 1
fi
ebegin "Starting ${SVCNAME}"
cd "${MLDONKEY_DIR}"
export MLDONKEY_DIR
start-stop-daemon --start --user "${USER}" --nice "${NICE}" \
--exec "${MLDONKEY_BINARY}" --pidfile /var/run/"${SVCNAME}".pid \
--background --make-pidfile
eend $?
}
send_telnet_commands() {
if [ -z "${TELNET_PORT+x}" ]; then
return 1
fi
local cmds=
if [ -n "${USERNAME}" -a -n "${PASSWORD}" ]; then
cmds="auth ${USERNAME} ${PASSWORD}\n"
fi
cmds="$cmds\nansi false\n"
while [ $# -gt 0 ]; do
cmds="$cmds$1\n"
shift
done
printf "$cmds\nexit\n" | nc -w "${MLDONKEY_TIMEOUT}" localhost "${TELNET_PORT}" 2> /dev/null
return $?
}
send_http_commands() {
if [ -z "${PORT+x}" ]; then
return 1
fi
local base="http://"
if [ -n "${USERNAME}" -a -n "${PASSWORD}" ]; then
base="${base}${USERNAME}:${PASSWORD}@"
fi
base="${base}${SERVER}:${PORT}"
local retval=0
while [ $retval -eq 0 -a $# -gt 0 ]; do
wget -q -O /dev/stdout --timeout="${MLDONKEY_TIMEOUT}" "${base}/submit?q=${1// /+}" 2> /dev/null
retval=$?
shift
done
return $retval
}
send_commands() {
send_telnet_commands "$@" &> /dev/null || send_http_commands "$@" &> /dev/null
return $?
}
stop() {
ebegin "Stopping ${SVCNAME} -- please wait"
send_commands close_fds save kill
# give it a chance to die:
local timeout=${MLDONKEY_TIMEOUT}
while [ $timeout -gt 0 ]; do
if ! start-stop-daemon --test --quiet --quiet --stop \
--exec "${MLDONKEY_BINARY}" \
--pidfile /var/run/"${SVCNAME}".pid ; then
eend 0
return 0
fi
sleep 1
timeout=$((${timeout} - 1))
done
eend 1 "Failed to cleanly stop ${SVCNAME}"
ebegin "Forcing ${SVCNAME} to stop"
start-stop-daemon --stop --exec "${MLDONKEY_BINARY}" \
--pidfile /var/run/"${SVCNAME}".pid
eend $?
}
# This doesn't work for baselayout-2
restart() {
svc_stop
sleep 5
svc_start
}
reload() {
ebegin "Reloading ${SVCNAME}"
start-stop-daemon --stop --signal HUP --oknodo \
--exec "${MLDONKEY_BINARY}" --pidfile /var/run/"${SVCNAME}".pid
eend $?
}
slow() {
ebegin "Reducing bandwidth to ${LOW_DOWN}k/${LOW_UP}k"
send_commands "set max_hard_download_rate ${LOW_DOWN}" "set max_hard_upload_rate ${LOW_UP}"
eend $?
}
fast() {
ebegin "Increasing bandwidth to ${HIGH_DOWN}k/${HIGH_UP}k"
send_commands "set max_hard_upload_rate ${HIGH_UP}" "set max_hard_download_rate ${HIGH_DOWN}"
eend $?
}
info() {
set -o pipefail
local result=$(
send_telnet_commands "voo max_hard_upload_rate" | grep -a 'max_hard_upload_rate.* =' | cut -d \ -f 3 ||
send_http_commands "voo max_hard_upload_rate" | fgrep name=value | sed -e 's/.*value="//' -e 's/".*//'
)
if [ "${result}" = "${LOW_UP}" ]; then
einfo "${SVCNAME} runs slow"
else
einfo "${SVCNAME} runs fast"
fi
}
|