I created a systemd service which should invoke a shell script, when started or on reboot.
[Unit]
Description=Starts the DCCA index software
[Install]
WantedBy=multi-user.target
[Service]
ExecStart=/opt/insiteone/bin/indexControl start
ExecStop=/opt/insiteone/bin/indexControl stop
# Execute pre and post scripts as root
#PermissionsStartOnly=true
Restart=on-abort
TimeoutSec=600
Initially it kept on restarting in infinite loop as soon as it is started, but when i added the TimeoutSec
option, it called the ExecStop
as soon as the service was started for the first time (started, and then stopped again immediately).
Any clue, where i am going wrong? P.S: indexControl is a shell script, which starts other processes.
A Failed Systemd Service There might be any number of reasons responsible for a service crash or failure such as misconfigurations, lack of system resources, file/data corruptions etc ..
2 Enabling and disabling services with systemctlDisabling a service means it will not start at boot, but can be started manually, or as a dependency of another service.
To check a service's status, use the systemctl status service-name command. I like systemd's status because of the detail given. For example, in the above listing, you see the full path to the unit file, the status, the start command, and the latest status changes.
Try changing Restart=on-abort
to Restart=on-abnormal
From http://www.freedesktop.org/software/systemd/man/systemd.service.html:
Setting this to on-failure is the recommended choice for long-running services, in order to increase reliability by attempting automatic recovery from errors. For services that shall be able to terminate on their own choice (and avoid immediate restarting), on-abnormal is an alternative choice.
Also, you may want to add Type=oneshot
to the [Service]
section.
From https://wiki.archlinux.org/index.php/Systemd#Service_types:
Type=oneshot: this is useful for scripts that do a single job and then exit. You may want to set RemainAfterExit=yes as well so that systemd still considers the service as active after the process has exited.
You can paste my recommended changes below:
[Unit]
Description=Starts the DCCA index software
[Install]
WantedBy=multi-user.target
[Service]
Type=oneshot
ExecStart=/opt/insiteone/bin/indexControl start
ExecStop=/opt/insiteone/bin/indexControl stop
Restart=on-abnormal
Something else to consider is whether or not you even need the Restart=
line ... Does the script this service file calls fail often?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With