summaryrefslogtreecommitdiff
blob: 3f0e7c6af9c35d25ca592f1de2f5fe2c7b9d0201 (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
#!/sbin/openrc-run
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

SS_CONFIG="/etc/shadowsocks-libev/shadowsocks.json"

SS_PIDFILE="/run/shadowsocks.pid"

depend() {
    need net
}

checkconfig() {
    if [ ! -f ${SS_CONFIG} ]; then
        ewarn "${SS_CONFIG} does not exist."
    fi

    SS_SVCNAME="${RC_SVCNAME#*.}"
    case ${SS_SVCNAME} in
    client)
        SS_COMMAND="/usr/bin/ss-local"
	return 0
	;;
    server)
        SS_COMMAND="/usr/bin/ss-server"
	return 0
	;;
    redir)
        SS_COMMAND="/usr/bin/ss-redir"
	return 0
	;;
    tunnel)
        SS_COMMAND="/usr/bin/ss-tunnel"
	return 0
	;;
    *)
    	eerror "please choose to run as server or client mode"
    	eerror "  server: rc-update add shadowsocks.server default"
    	eerror "  client: rc-update add shadowsocks.client default"
	eerror "  client: rc-update add shadowsocks.redir default"
	eerror "  client: rc-update add shadowsocks.tunnel default"
        return 1
    	;;
    esac
}

start() {
    checkconfig || return 1

    ebegin "Starting Shadowsocks: ${SS_SVCNAME} mode"
    start-stop-daemon --start --exec ${SS_COMMAND} \
    -- -c ${SS_CONFIG} -f ${SS_PIDFILE} >/dev/null 2>&1 &
    eend $?
}

stop() {
    ebegin "Stopping Shadowsocks"
    start-stop-daemon --stop --pidfile ${SS_PIDFILE}
    eend $?
}