systemctl cannot start service (code=exited status =0/success)
You’re not specifying the Type. By default, it is simple, which expects that the service process not exit.
According to the project page, running in the foreground is as simple as not passing -d start.
The complete unit file would look like this:
[Unit]
Description=Shadowsocks-R Server
After=network.target
[Service]
ExecStart=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json
[Install]
WantedBy=multi-user.target
Systemd will automatically take care of monitoring the process, restarting and stopping it as requested/required.
Related videos on Youtube
Ch3_ong
Updated on September 18, 2022Comments
-
Ch3_ong 3 months
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.targetBut 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 successThe 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.serviceI tried runningjournalctl -xeand 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.targetI first stop the server.py process by
/etc/init.d/shadowsocks-r stopand it reuturnsShadowsocksR is stoppedThen I run
systemctl daemon-reload systemctl start shadowsocks-r.service systemctl status shadowsocks-r.serviceI 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-
Michael Frank over 3 yearsAfter attempting to start the service, runjournalctl -xe, it should give you some extended output. -
Ch3_ong over 3 yearsThanks Michael, I try running journalctl -xe and I append the result to my original question.
-
Michael Frank over 3 yearsI think your service file is fine, perhaps there is something stoppingserver.pyfrom launching correctly? Have you manually called your ExecStart command? -
Ch3_ong over 3 yearsNo I didn't. I noticed the result lists out two processes (start and stop), which I didn't see when running other systemctl command. I'm not sure if that's normal or if that hints anything.
-
Michael Frank over 3 yearsHm... it normally stops you from doing this, but did yousystemctl daemon-reloadafter saving the file? -
Ch3_ong over 3 yearsYes I did. Every time I edited the service file I need to daemon-reload.
- First I start the process by
-
Ch3_ong over 3 yearsI removed the ExecStop line but the problem persisits. I updated my question to reflect the return after I made the change.
-
Daniel B over 3 years@Ch3_ong Please read my answer again, fully. You must change theExecStartline or you must specify aType(which has more implications). -
Ch3_ong over 3 yearsThanks Daniel! I remove the "-d start" and it worked! Though I don't quite understand how this happened (and I couldn't figure out why running in the foreground is as simple as not passing "-d start"), I appreciate your advice!
-
Daniel B over 3 yearsHow to run a program in the background or foreground is entirely specific to the program. It’s really just a matter of reading the documentation.-d startis probably meant as an abbreviation fordaemon start. -
Ch3_ong over 3 yearsYes it means to start in the background. I don't understand why I need to remove this specification to make things go right ...
-
Daniel B over 3 yearsBecauseType=simpleexpects to program to not run in the background. That’s all. ForType=forking, you’d ideally have a PID file, which this service may or may not be able to create. It’s generally not worth it.