I installed Shadowsocks-r in my CentOS 7 server, and I want to use systemd to manage it. So I created a file in /etc/systemd/system called shadowsocks-r.service.
shadowsocks-r.service:
[Unit]
Description=Shadowsocks-R Server
After=network.target
[Service]
ExecStart=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json -d start
ExecStop=/etc/init.d/shadowsocks-r stop
[Install]
WantedBy=multi-user.target
But the service couldn't be started correctly. When checking the status of the service, below is what I get:
shadowsocks-r.service - Shadowsocks-R Server
Loaded: loaded (/etc/systemd/system/shadowsocks-r.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Tue 2019-05-14 10:29:46 UTC; 8s ago
Process: 19267 ExecStop=/etc/init.d/shadowsocks-r stop (code=exited, status=0/SUCCESS)
Process: 19234 ExecStart=/etc/init.d/shadowsocks-r start (code=exited, status=0/SUCCESS)
Main PID: 19234 (code=exited, status=0/SUCCESS)
May 14 10:29:46 vultr.guest systemd[1]: Started Shadowsocks-R Server.
May 14 10:29:46 vultr.guest shadowsocks-r[19234]: 2019-05-14 10:29:46 INFO util.py:94 loading libcrypto from libcrypto.so.10
May 14 10:29:46 vultr.guest shadowsocks-r[19234]: 2019-05-14 10:29:46 INFO shell.py:74 ShadowsocksR 2.8.2
May 14 10:29:46 vultr.guest shadowsocks-r[19234]: IPv6 support
May 14 10:29:46 vultr.guest shadowsocks-r[19234]: Starting ShadowsocksR success
May 14 10:29:46 vultr.guest shadowsocks-r[19267]: 2019-05-14 10:29:46 INFO shell.py:74 ShadowsocksR 2.8.2
May 14 10:29:46 vultr.guest shadowsocks-r[19267]: IPv6 support
May 14 10:29:46 vultr.guest shadowsocks-r[19267]: stopped
May 14 10:29:46 vultr.guest shadowsocks-r[19267]: Stopping ShadowsocksR success
The messages shadowsocks-r is from the start and stop function. From the message it seems both start and stop function were executed. Why this happened and what i should do to correct it? thanks!
Update:
After running systemctl start shadowsocks-r.service
I tried running journalctl -xe
and this is what I get:
May 14 11:09:01 vultr.guest systemd[1]: Started Shadowsocks-R Server.
-- Subject: Unit shadowsocks-r.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit shadowsocks-r.service has finished starting up.
--
-- The start-up result is done.
May 14 11:09:01 vultr.guest polkitd[1547]: Unregistered Authentication Agent for unix-process:19521:1303198 (system bus name :1.57, object path
May 14 11:09:01 vultr.guest shadowsocks-r[19527]: 2019-05-14 11:09:01 INFO util.py:94 loading libcrypto from libcrypto.so.10
May 14 11:09:01 vultr.guest shadowsocks-r[19527]: 2019-05-14 11:09:01 INFO shell.py:74 ShadowsocksR 2.8.2
May 14 11:09:01 vultr.guest shadowsocks-r[19527]: IPv6 support
May 14 11:09:01 vultr.guest shadowsocks-r[19527]: Starting ShadowsocksR success
May 14 11:09:01 vultr.guest shadowsocks-r[19560]: 2019-05-14 11:09:01 INFO shell.py:74 ShadowsocksR 2.8.2
May 14 11:09:02 vultr.guest shadowsocks-r[19560]: IPv6 support
May 14 11:09:02 vultr.guest shadowsocks-r[19560]: stopped
May 14 11:09:02 vultr.guest shadowsocks-r[19560]: Stopping ShadowsocksR success
------Update------
Now I tried a few more and it's confirmed that the systemctl command actually stopped the process even when I used the command "start". Here is what I tried:
- First I start the process by
/etc/init.d/shadowsocks-r start
And the terminal returns:
IPv6 support
2019-05-16 08:39:30 INFO util.py:94 loading libcrypto from libcrypto.so.10
2019-05-16 08:39:30 INFO shell.py:74 ShadowsocksR 2.8.2
started
Starting ShadowsocksR success
- Then I run
systemctl start shadowsocks-r.service
- Then I run
/etc/init.d/shadowsocks-r status
, and the result is:ShadowsocksR is stopped
So even when I started the shadowsocks-r process using other method, the systemctl will kill it even when I try to start it.
- Running
systemctl status shadowsocks-r.service
, here is what I get:
shadowsocks-r.service - Shadowsocks-R Server
Loaded: loaded (/etc/systemd/system/shadowsocks-r.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2019-05-16 08:45:10 UTC; 12min ago
Process: 713 ExecStop=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json -d stop (code=exited, status=0/SUCCESS)
Process: 686 ExecStart=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json -d start (code=exited, status=1/FAILURE)
Main PID: 686 (code=exited, status=1/FAILURE)
May 16 08:45:10 vultr.guest server.py[686]: 2019-05-16 08:45:10 INFO shell.py:74 ShadowsocksR 2.8.2
May 16 08:45:10 vultr.guest server.py[686]: 2019-05-16 08:45:10 ERROR daemon.py:75 already started at pid 670
May 16 08:45:10 vultr.guest server.py[686]: IPv6 support
May 16 08:45:10 vultr.guest server.py[686]: IPv6 support
May 16 08:45:10 vultr.guest systemd[1]: shadowsocks-r.service: main process exited, code=exited, status=1/FAILURE
May 16 08:45:10 vultr.guest server.py[713]: 2019-05-16 08:45:10 INFO shell.py:74 ShadowsocksR 2.8.2
May 16 08:45:10 vultr.guest server.py[713]: IPv6 support
May 16 08:45:10 vultr.guest server.py[713]: stopped
May 16 08:45:10 vultr.guest systemd[1]: Unit shadowsocks-r.service entered failed state.
May 16 08:45:10 vultr.guest systemd[1]: shadowsocks-r.service failed.
-------Update --------
Per @Daniel B's suggestion, I removed the ExecStop line in the service file:
[Unit]
Description=Shadowsocks-R Server
After=network.target
[Service]
ExecStart=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json -d start
[Install]
WantedBy=multi-user.target
I first stop the server.py process by /etc/init.d/shadowsocks-r stop
and it reuturns ShadowsocksR is stopped
Then I run
systemctl daemon-reload
systemctl start shadowsocks-r.service
systemctl status shadowsocks-r.service
I still get the error message, and it seems the systemctl command couldn't start the process (before it can start then stop the process)
shadowsocks-r.service - Shadowsocks-R Server
Loaded: loaded (/etc/systemd/system/shadowsocks-r.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Thu 2019-05-16 09:40:43 UTC; 29s ago
Process: 2964 ExecStart=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json -d start (code=exited, status=0/SUCCESS)
Main PID: 2964 (code=exited, status=0/SUCCESS)
May 16 09:40:43 vultr.guest systemd[1]: Started Shadowsocks-R Server.
May 16 09:40:43 vultr.guest server.py[2964]: 2019-05-16 09:40:43 INFO util.py:94 loading libcrypto from libcrypto.so.10
May 16 09:40:43 vultr.guest server.py[2964]: 2019-05-16 09:40:43 INFO shell.py:74 ShadowsocksR 2.8.2
May 16 09:40:43 vultr.guest server.py[2964]: IPv6 support
journalctl -xe
, it should give you some extended output.server.py
from launching correctly? Have you manually called your ExecStart command?systemctl daemon-reload
after saving the file?