-
-
Save ttimasdf/6e47f0532fdb73fcc5ffc8c2e0f0087a to your computer and use it in GitHub Desktop.
shadowsocks-server OpenWRT init.d script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh /etc/rc.common | |
# | |
# Copyright (C) 2016 Jian Chang <aa65535@live.com> | |
# Copyright (C) 2016 Evian Zhow <evianzhow@gmail.com> | |
# | |
# This is free software, licensed under the GNU General Public License v3. | |
# See /LICENSE for more information. | |
# | |
START=90 | |
STOP=15 | |
NAME=shadowsocks | |
CONFIG_FILE=/var/etc/$NAME.json | |
uci_get_server_info() { | |
local ret=$(uci get $NAME.@servers[0].$1 2>/dev/null) | |
echo ${ret:=$2} | |
} | |
gen_config_file() { | |
cat <<-EOF >$CONFIG_FILE | |
{ | |
"server": "$(uci_get_server_info server)", | |
"server_port": $(uci_get_server_info server_port), | |
"local_address": "0.0.0.0", | |
"password": "$(uci_get_server_info password)", | |
"timeout": $(uci_get_server_info timeout 60), | |
"method": "$(uci_get_server_info encrypt_method)" | |
} | |
EOF | |
} | |
start_server() { | |
gen_config_file $1 | |
ss-server -c $CONFIG_FILE \ | |
-f /var/run/ss-server.pid | |
} | |
ss_server() { | |
command -v ss-server >/dev/null 2>&1 || return 0 | |
start_server | |
} | |
start() { | |
mkdir -p /var/run /var/etc | |
ss_server | |
rm -f $CONFIG_FILE | |
} | |
kill_all() { | |
kill -9 $(pidof $@) >/dev/null 2>&1 | |
} | |
stop() { | |
kill_all ss-server | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment