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

SS_CONFIG="/etc/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
	;;
    *)
    	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"
        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 $?
}