aboutsummaryrefslogtreecommitdiffstats
path: root/net-p2p/mldonkey/files/mlnet.sh
blob: 41a0b866eae8dbdb024cf92ceb9e92b0e1fe0b75 (plain) (blame)
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
#!/bin/sh
# $FreeBSD$

# PROVIDE: mlnet
# REQUIRE: LOGIN
# KEYWORD: FreeBSD shutdown

mlnet_enable=${mlnet_enable:-"NO"}
mlnet_http_port=${mlnet_http_port:-"4080"}
mlnet_logfile=${mlnet_logfile:-"/var/log/mlnet"}

. %%RC_SUBR%%

name=mlnet
rcvar=`set_rcvar`
command="%%PREFIX%%/bin/${name}"
start_cmd="${name}_start"
stop_cmd="${name}_stop"

mlnet_conf="%%PREFIX%%/etc/mlnet.conf"
required_files="${mlnet_conf}"
mlnet_user=${mlnet_user:-"mlnet"}

if [ -r ${mlnet_conf} ] ; then
    . ${mlnet_conf}
fi

mlnet_url="http://"
if [ -n "${mlnet_http_user}" -a -n "${mlnet_http_password}" ] ; then
    mlnet_url="${mlnet_url}${mlnet_http_user}:${mlnet_http_password}@"
fi
mlnet_url="${mlnet_url}localhost:${mlnet_http_port}"

mlnet_start() {
    if checkyesno mlnet_enable ; then
        echo -n " mlnet"
        su ${mlnet_user} -c "${command} \
            ${mlnet_flags} \
            -daemon \
            -http_port ${mlnet_http_port}" \
            >>${mlnet_logfile} 2>&1
    fi
}

mlnet_stop() {
    if checkyesno mlnet_enable ; then
        echo -n " mlnet"
        %%LOCALBASE%%/bin/wget --spider -q \
            "${mlnet_url}/submit?q=close_fds" \
            >>${mlnet_logfile} 2>&1
        %%LOCALBASE%%/bin/wget --spider -q \
            "${mlnet_url}/submit?q=save" \
            >>${mlnet_logfile} 2>&1
        %%LOCALBASE%%/bin/wget --spider -q \
            "${mlnet_url}/submit?q=kill" \
            >>${mlnet_logfile} 2>&1
    fi
}

load_rc_config ${name}
run_rc_command "$1"