Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is systemd stopping service immediately after it is started? [closed]

Tags:

linux

systemd

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.

like image 626
RajSanpui Avatar asked Jan 05 '16 14:01

RajSanpui


People also ask

Why does systemd service fail?

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 ..

Does Systemctl disable stop the service?

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.

How do you check if a systemd service is running?

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.


1 Answers

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?

like image 62
Jay Baker Avatar answered Sep 19 '22 19:09

Jay Baker