Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unit falling into a failed state (status=143) when stopping service [closed]

here is my problem. I have CentOS and java process running on it. Java process is operated by the start/stop script. It creates a .pid file of java instance too.

My unit file is looking like:

[Unit]
After=syslog.target network.target
Description=Someservice

[Service]
User=xxxuser
Type=forking
WorkingDirectory=/srv/apps/someservice
ExecStart=/srv/apps/someservice/server.sh start
ExecStop=/srv/apps/someservice/server.sh stop
PIDFile=/srv/apps/someservice/application.pid
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target

When I call stop function, script terminates java process with SIGTERM and returns 0 code:

kill $OPT_FORCEKILL `cat $PID_FILE`
<...>
return 0

After that, if I check the status of my unit, I get something like that (status=143):

● someservice.service - Someservice
   Loaded: loaded (/usr/lib/systemd/system/someservice.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2017-08-30 09:17:40 EEST; 4s ago
  Process: 48365 ExecStop=/srv/apps/someservice/server.sh stop (code=exited, status=0/SUCCESS)
 Main PID: 46115 (code=exited, status=143)

Aug 29 17:10:02 whatever.domain.com systemd[1]: Starting Someservice...
Aug 29 17:10:02 whatever.domain.com systemd[1]: PID file /srv/apps/someservice/application.pid not readable (yet?) after start.
Aug 29 17:10:04 whatever.domain.com systemd[1]: Started Someservice.
Aug 30 09:17:39 whatever.domain.com systemd[1]: Stopping Someservice...
Aug 30 09:17:39 whatever.domain.com server.sh[48365]: Stopping someservice - PID [46115]
Aug 30 09:17:40 whatever.domain.com systemd[1]: someservice.service: main process exited, code=exited, status=143/n/a
Aug 30 09:17:40 whatever.domain.com systemd[1]: Stopped Someservice.
Aug 30 09:17:40 whatever.domain.com systemd[1]: Unit someservice.service entered failed state.
Aug 30 09:17:40 whatever.domain.com systemd[1]: someservice.service failed.

When I haven't got the return value in my start/stop script, it acts absolutely the same.
Adding into the unit file something like:

[Service]
SuccessExitStatus=143

is not good idea for me. Why the systemctl acting so and doesn't show me normal service state?

When I try to modify my start/stop script and instead of return 0 I put return 10 it acts the same, but I can see that exit 10 is passed.
Here is an example:

● someservice.service - Someservice
   Loaded: loaded (/usr/lib/systemd/system/someservice.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2017-08-30 09:36:22 EEST; 5s ago
  Process: 48460 ExecStop=/srv/apps/someservice/server.sh stop (code=exited, status=10)
  Process: 48424 ExecStart=/srv/apps/someservice/server.sh start (code=exited, status=0/SUCCESS)
 Main PID: 48430 (code=exited, status=143)

Aug 30 09:36:11 whatever.domain.com systemd[1]: Starting Someservice...
Aug 30 09:36:11 whatever.domain.com systemd[1]: PID file /srv/apps/someservice/application.pid not readable (yet?) after start.
Aug 30 09:36:13 whatever.domain.com systemd[1]: Started Someservice.
Aug 30 09:36:17 whatever.domain.com systemd[1]: Stopping Someservice...
Aug 30 09:36:17 whatever.domain.com server.sh[48460]: Stopping someservice - PID [48430]
Aug 30 09:36:21 whatever.domain.com systemd[1]: someservice.service: main process exited, code=exited, status=143/n/a
Aug 30 09:36:22 whatever.domain.com systemd[1]: someservice.service: control process exited, code=exited status=10
Aug 30 09:36:22 whatever.domain.com systemd[1]: Stopped Someservice.
Aug 30 09:36:22 whatever.domain.com systemd[1]: Unit someservice.service entered failed state.
Aug 30 09:36:22 whatever.domain.com systemd[1]: someservice.service failed.

From the journalctl log I can see that systemctl firstly returns the status=143 and then my return value of 10. So i guess that my mistake is somewhere in start/stop script (because error code 143 is passed before function returns 0)?

like image 422
sergei Avatar asked Aug 30 '17 06:08

sergei


1 Answers

You should be able to suppress this by adding the exit code into the unit file as a "success" exit status:

[Service]
SuccessExitStatus=143

source

like image 67
Mohannd Avatar answered Sep 27 '22 22:09

Mohannd