I have successfully created a service in systemd that runs a script just before server shutdown/reboot. But the problem is that my script takes too long to execute (around 3-4 minutes) and the server shuts down before it is finished. Debug log indicates that the script is indeed running but it is stopped halfway.
Here are my two different ways of implementing this service:
[Unit]
Description=Stop Service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/home/user/stop-service.sh
[Install]
WantedBy=multi-user.target
and
[Unit]
Description=Stop Service
DefaultDependencies=no
Before=final.target
[Service]
ExecStart=/home/user/stop-service.sh
[Install]
WantedBy=final.target
They both successfully call stop-service.sh
but the script takes too long to run. Is there any way to make sure stop-service.sh
finishes running before server is fully shut down?
My server is RHEL7.