Why does the system stop the service immediately after it starts?

I created a systemd service that should run a shell script on startup 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 continued to restart in an infinite loop as soon as it was started, but when I added the TimeoutSec parameter, it called ExecStop as soon as the service was started for the first time (it started and then stopped immediately).

Any clue where am I wrong? PS: indexControl is a shell script that launches other processes.

+6
source share
1 answer

Try changing Restart=on-abort to Restart=on-abnormal

From http://www.freedesktop.org/software/systemd/man/systemd.service.html :

Setting this option to failure is the recommended choice for long-term use of services in order to increase reliability, trying to automate error recovery. For services that may be their own choice (and avoid an immediate restart) , an abnormally alternative option.

Alternatively, you can 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 one job and then Exit. You might want to set RemainAfterExit = yes so that systemd still considers the service active after the process exits.

You can insert 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 if you even need the Restart= line ... Does this utility script file often get called with an error?

+3
source

All Articles