Skip to content

Instantly share code, notes, and snippets.

@evianzhow
Last active April 27, 2019 14:21
Show Gist options
  • Save evianzhow/7bb54b322dffde604eb680291c2ec1b2 to your computer and use it in GitHub Desktop.
Save evianzhow/7bb54b322dffde604eb680291c2ec1b2 to your computer and use it in GitHub Desktop.
shadowsocks-server OpenWRT init.d script
#!/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
}
@ttimasdf
Copy link

Changing server to ["[::0]", "0.0.0.0"] and remove the line local_address makes this config works dual-stack, according to shadowsocks/shadowsocks-libev#2115 and shadowsocks/shadowsocks-libev#254.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment