shadowsocks-rust icon indicating copy to clipboard operation
shadowsocks-rust copied to clipboard

Systemd service files

Open inferrna opened this issue 7 years ago • 5 comments
trafficstars

For anyone who wants to autostart shadowsocks services via systemd:

  1. 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).
  2. place configs below into /usr/local/systemd/system/ or /lib/systemd/system/
  3. sudo systemctl enable sslocal.service on client and sudo systemctl enable ssserver.service on server
  4. sudo systemctl start sslocal.service on client and sudo systemctl start ssserver.service on 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.

inferrna avatar Apr 26 '18 09:04 inferrna

Awesome and thanks

zonyitoo avatar Apr 27 '18 14:04 zonyitoo

Are you going to open a PR?

zonyitoo avatar Apr 27 '18 14:04 zonyitoo

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

you-oops-dev avatar Nov 07 '20 01:11 you-oops-dev

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

pyy avatar Jun 17 '21 09:06 pyy

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
}

Klaaktu avatar Jul 09 '21 05:07 Klaaktu