Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systemd service files #103

Open
inferrna opened this issue Apr 26, 2018 · 5 comments
Open

Systemd service files #103

inferrna opened this issue Apr 26, 2018 · 5 comments

Comments

@inferrna
Copy link

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.

@zonyitoo
Copy link
Collaborator

Awesome and thanks

@zonyitoo
Copy link
Collaborator

Are you going to open a PR?

@naruto522ru
Copy link

naruto522ru commented Nov 7, 2020

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 shadowsocks-rust-manager@ss.service

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

@pyy
Copy link

pyy commented Jun 17, 2021

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

@Klaaktu
Copy link

Klaaktu commented Jul 9, 2021

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants