Running RHEL7.X with systemd 219 and I have a systemd service called "myService" with the following settings:
ExecStart=/bin/bash /asp_APPL/myInstance/script/myServiceSystemdCtrl.sh start
ExecStop=/bin/bash /asp_APPL/myInstance/script/myServiceSystemdCtrl.sh stop
KillMode=none
Restart=no
Type=notify
NotifyAccess=all
###Can't use ExitType until Systemd 250 release ( systemctl --version )
#ExitType=cgroup
When I call the ExecStart script, it runs a number of different interdependent processes and I send systemd a NOTIFY update with MAINPID= from my startup script with a single PID to monitor what I consider the most important, and the systemctl status looks like this:
● myService@myInstance.service - "myService Instance : myInstance"
Loaded: loaded (/etc/systemd/system/myService@.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2022-06-16 15:19:40 BST; 23h ago
Process: 9700 ExecStop=/bin/bash /asp_APPL/myInstance/script/myServiceSystemdCtrl.sh stop (code=exited, status=0/SUCCESS)
Main PID: 6099 (myMainProcess)
Sometimes this MAINPID has failure and exits, but the app itself has a self-healing aspect and usually recovers, which is why we use this in our /etc/systemd/system/myService.service definition file
KillMode=none
Restart=no
We get the following systemctl status in this "failed" status scenario, but its not major consequence because of self-healing mentioned above and we can live with this as an incorrect status for a time
● myService@myInstance.service - "myService Instance : myInstance"
Loaded: loaded (/etc/systemd/system/myService@.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2022-06-17 14:58:44 BST; 1s ago
Process: 9700 ExecStop=/bin/bash /asp_APPL/myInstance/script/myServiceSystemdCtrl.sh stop (code=exited, status=0/SUCCESS)
Process: 6099 ExecStart=/bin/bash /asp_APPL/myInstance/script/myServiceSystemdCtrl.sh start (code=exited, status=1/FAILURE)
Main PID: 6099 (code=exited, status=1/FAILURE)
However sometimes the app can't recover and we want to do a "clean" shutdown of all services with requisite cleanups, which our ExecStop script does quite nicely.
However, when I run this, nothing seems to run,
systemctl stop myService@myInstance
However, when I run this, I can see the startup msgs from ExecStart immediately.
systemctl restart myService@myInstance
So to me, when you are in a "failed state", ExecStop script never runs.
I even tried running the following, but it didnt work either with ExecStop:
systemctl reset-failed myService@myInstance
● myService@myInstance.service - "myService Instance : myInstance"
Loaded: loaded (/etc/systemd/system/sierra@.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Fri 2022-06-17 15:30:16 BST; 8min ago
Process: 9700 ExecStop=/bin/bash /asp_APPL/myInstance/script/myServiceSystemdCtrl.sh stop (code=exited, status=0/SUCCESS)
Process: 27952 ExecStart=/bin/bash /asp_APPL/myInstance/script/myServiceSystemdCtrl.sh start (code=killed, signal=KILL)
Main PID: 27952 (code=killed, signal=KILL)
Is there anyway I can force the ExecStop script to run from systemctl commands/context only. In know I can run aspects of the ExecStop script manually for the cleanups, although given all the internal systemd semantics in the script, it would be hard to de-couple.