Run multiple shadowsocks client (ss-local) instances on Gentoo with OpenRC

First of all you should create separate system user and group for shadowsocks:

# useradd -r shadowsocks

Create an OpenRC script for ss-local instances (/etc/init.d/ss-local):

#!/sbin/openrc-run
# Copyright 1999-2020 Gentoo Authors
# Copyright 2023 Rl
# Distributed under the terms of the GNU General Public License v2

SS_CONFIG=
SS_PIDFILE=
SS_USER=shadowsocks
SS_GROUP=shadowsocks

depend() {
    need net
}

checkconfig() {
    SS_SVCNAME="${RC_SVCNAME#*.}"

    SS_CONFIG="/etc/shadowsocks-libev/client/$SS_SVCNAME.conf"
    SS_PIDFILE="/run/ss-local/$SS_SVCNAME.pid"

    if [ ! -d /run/ss-local ]; then
        mkdir /run/ss-local
        chown ${SS_USER}:${SS_GROUP} /run/ss-local
    fi

    if [ ! -f ${SS_CONFIG} ]; then
        eerror "${SS_CONFIG} does not exist."
    fi
}

start() {
    checkconfig || return 1

    ebegin "Starting ss-local for ${SS_SVCNAME}"
    start-stop-daemon --start --exec /usr/bin/ss-local \
        --user ${SS_USER} --group ${SS_GROUP} \
        -- -c ${SS_CONFIG} -f ${SS_PIDFILE} >/dev/null 2>&1 &
    eend $?
}

stop() {
    checkconfig || return 1

    ebegin "Stopping ss-local for ${SS_SVCNAME}"
    if [ ! -f "$SS_PIDFILE" ]; then
        eerror "$SS_PIDFILE: pid file not found"
    else
        start-stop-daemon --stop \
        --user ${SS_USER} --group ${SS_GROUP} \
        --pidfile ${SS_PIDFILE}
        eend $?
    fi
}

Create /etc/shadowsocks-libev/clients directory, chown it to shadowsocks:shadowsocks.

Store each clients' config in a separate file with .conf extension under the /etc/shadowsocks-libev/clients directory.

chown them to shadowsocks:shadowsocks and chmod to 600.


Let's say you put your config to /etc/shadowsocks-libev/clients/myproxy.conf file.

Go to /etc/init.d, run:

# ln -s ss-local ss-local.myproxy

Then start the service:

# /etc/init.d/ss-local.myproxy start

Your ss-local client should now be up and running.

You may also want to add it to the default runlevel:

# rc-update add ss-local.myproxy default
If you have any comments, contact me by email.