Run multiple shadowsocks client (ss-local) instances on Void Linux

In this post I'll demonstrate how to set up a configuration similar to what I described in my previous article about Gentoo, but this time on Void Linux (which uses runit as init system, as opposed to Gentoo's OpenRC).

In a sense, it's even easier, because runit uses very pure and simple BSD-style scripts.

First, install shadowsocks-libev:

# xbps-install shadowsocks-libev

The user and group shadowsocks will be created automatically during the package install.

Let's take a look at the default /etc/sv/shadowsocks-libev-client/run script.

On my machine it looks like this:

exec 2>&1
exec chpst -u shadowsocks:shadowsocks ss-local -c /etc/shadowsocks-libev/config.json 1>/dev/null

As you can see, it has /etc/shadowsocks-libev/config.json hardcoded while we want it to be dynamic. So let's create similar service, but with that "dynamic" in mind. We'll call it shadowsocks-libev-local. First create a directory:

# mkdir /etc/sv/shadowsocks-libev-local

Then a script /etc/sv/shadowsocks-libev-local/run. It's almost the same, with the exception that it extracts the name of config from the service name:



exec 2>&1
exec chpst -u shadowsocks:shadowsocks ss-local -c /etc/shadowsocks-libev/$name.conf 1>/dev/null

Now, suppose you have two shadowsocks proxies, proxy1 and proxy2 and their corresponding configs are stored in /etc/shadowsocks-libev/proxy1.conf and /etc/shadowsocks-libev/proxy2.conf. Create two symlinks to our new service in /etc/sv:

# cd /etc/sv
# ln -s shadowsocks-libev-local shadowsocks-libev-local.proxy1
# ln -s shadowsocks-libev-local shadowsocks-libev-local.proxy2

(Of course, your config files must be chowned to shadowsocks:shadowsocks.)

Then enable them with runit:

# ln -s /etc/sv/shadowsocks-libev-local.proxy1 /var/service
# ln -s /etc/sv/shadowsocks-libev-local.proxy2 /var/service

Bingo, now you have two ss-local proxies running with different configs and you can start as many instances of shadowsocks-libev-local service as you want, using this little shell-scripting-and-symlinking trick.

If you have any comments, contact me by email.