shadowsocks-rust
shadowsocks-rust copied to clipboard
Systemd service files
For anyone who wants to autostart shadowsocks services via systemd:
- Be sure you has both server and client installed into /usr/local/bin/, config placed into /etc/sssconfig.json and has user nobody and group nogroup in your system (it's good practice to run network services under unprivileged user by secure reasons).
- place configs below into /usr/local/systemd/system/ or /lib/systemd/system/
sudo systemctl enable sslocal.serviceon client andsudo systemctl enable ssserver.serviceon serversudo systemctl start sslocal.serviceon client andsudo systemctl start ssserver.serviceon server
sslocal.service
[Unit]
Description=sslocal service
After=network.target
[Service]
ExecStart=/usr/local/bin/sslocal -c /etc/sssconfig.json
ExecStop=/usr/bin/killall sslocal
Restart=always
RestartSec=10 # Restart service after 10 seconds if service crashes
StandardOutput=syslog # Output to syslog
StandardError=syslog # Output to syslog
SyslogIdentifier=sslocal
User=nobody
Group=nogroup
[Install]
WantedBy=multi-user.target
ssserver.service
[Unit]
Description=ssserver service
After=network.target
[Service]
ExecStart=/usr/local/bin/ssserver -c /etc/sssconfig.json
ExecStop=/usr/bin/killall ssserver
Restart=always
RestartSec=10 # Restart service after 10 seconds if service crashes
StandardOutput=syslog # Output to syslog
StandardError=syslog # Output to syslog
SyslogIdentifier=ssserver
User=nobody
Group=nogroup
[Install]
WantedBy=multi-user.target
can close this when systemd service files be added to examples and described in docs.
Awesome and thanks
Are you going to open a PR?
shadowsocks-rust-manager @.service
[Unit]
Description=Shadowsocks-Rust Manager Service
After=network.target
[Service]
Type=simple
User=nobody
#Environment=RUST_BACKTRACE=full #For dedug
ExecStart=/usr/bin/ssmanager -c /etc/shadowsocks/%i.cfg --log-without-time
[Install]
WantedBy=multi-user.target
We start it like this: for example, the configuration file is called ss.cfg, then the service starts like this
systemctl start [email protected]
Work on Arch Linux v1.8.23!
P.S I will take a moment to ask the developer. Why the file with the .js extension is launched from the console normally, and through the service shown above, you need to rename the extension. Points to:strings
systemd file for OpenSUSE 15.2 as a example:
[Unit]
Description=Daemon to start shadowsocks-rust-server
Wants=network-online.target
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/ssserver --log-without-time -c /etc/shadowsocks-rust/config.json
Restart=always
[Install]
WantedBy=multi-user.target
Ref: #554
For newer Linux, maybe use: (under [Service] section)
Type=exec
DynamicUser=true # if not needing to write anything to file system
Not systemd... but a simple procd startup script for OpenWrt (there is also a behemoth in libev package)
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=99
STOP=01
start_service() {
procd_open_instance
procd_set_param command /opt/Shadowsocks-Rust/sslocal -c /opt/Shadowsocks-Rust/ss-client.json
procd_set_param user nobody
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}