Zend certified PHP/Magento developer

Trouble with a bash script running as a systemd service restarting another systemd service the first time

I’ve written a bash loop and named it freud.sh.

freud.sh

#!/bin/bash
set -x

while :
do
sleep 30
systemctl stop pacemaker
sleep 30
systemctl start pacemaker
done

Here is my unit file:

[Unit]
Description=Freud SplitBrain Service

[Service]
ExecStart=/root/utils/freud.sh

[Install]
WantedBy=multi-user.target

Systemd restarts the service the first time it tries to start the pacemaker service in the bash script (systemtl start pacemaker) as observed in ‘journalctl -fu freud’

Jul 08 15:19:52 ENG_QA-HA2 systemd[1]: Started Freud SplitBrain Service.
Jul 08 15:19:53 ENG_QA-HA2 freud.sh[5460]: + :
Jul 08 15:19:53 ENG_QA-HA2 freud.sh[5460]: + sleep 30
Jul 08 15:20:23 ENG_QA-HA2 freud.sh[5460]: + systemctl stop pacemaker
Jul 08 15:20:26 ENG_QA-HA2 freud.sh[5460]: + sleep 30
Jul 08 15:20:39 ENG_QA-HA2 systemd[1]: Stopping Freud SplitBrain Service...
Jul 08 15:20:39 ENG_QA-HA2 systemd[1]: Stopped Freud SplitBrain Service.
Jul 08 15:20:39 ENG_QA-HA2 systemd[1]: Started Freud SplitBrain Service.
Jul 08 15:20:39 ENG_QA-HA2 freud.sh[6897]: + :
Jul 08 15:20:39 ENG_QA-HA2 freud.sh[6897]: + sleep 30
Jul 08 15:21:09 ENG_QA-HA2 freud.sh[6897]: + systemctl stop pacemaker
Jul 08 15:21:09 ENG_QA-HA2 freud.sh[6897]: + sleep 30
Jul 08 15:21:39 ENG_QA-HA2 freud.sh[6897]: + systemctl start pacemaker
Jul 08 15:21:39 ENG_QA-HA2 freud.sh[6897]: + :

It works the subsequent times as listed above, but in my “real” script, I’ve already passed that logic in the while loop which determines it needs to stop and start and it leaves the pacemaker service in a stopped state.

When I run the script in an ssh session or on cosole as a bash script, it works as desired. Does anyone have any idea how to troubleshoot why the first attempt restarts my service?

Please let me know if you need more information.

Thanks!