diff options
Diffstat (limited to 'net-proxy/shadowsocks-libev/files/shadowsocks.initd')
-rw-r--r-- | net-proxy/shadowsocks-libev/files/shadowsocks.initd | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/net-proxy/shadowsocks-libev/files/shadowsocks.initd b/net-proxy/shadowsocks-libev/files/shadowsocks.initd new file mode 100644 index 000000000000..d32e6df9a915 --- /dev/null +++ b/net-proxy/shadowsocks-libev/files/shadowsocks.initd @@ -0,0 +1,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 $? +} + |