Run systemd script forever and restart if it dies

General support questions
Post Reply
adeptus24
Posts: 2
Joined: 2017/04/25 11:31:22

Run systemd script forever and restart if it dies

Post by adeptus24 » 2017/04/25 11:52:57

Hi all,

My question is how do I run a script at background mode?

If i run this line in a therminal, the script run ok and the process its running:

Code: Select all

/bin/su -c /CCScannerDB/CCScannerDB.sh informix &

Code: Select all

$ ps aux | grep cannerDB
root     25755  0.0  0.0 163284   172 pts/1    S    13:25   0:00 /bin/su -c /CCScannerDB/CCScannerDB.sh informix
informix 25756  0.0  0.0 113256   100 ?        Ss   13:25   0:00 /bin/bash /CCScannerDB/CCScannerDB.sh
I have created a service to execute this line and it is always running:

Code: Select all

[Unit]
Description=Servicio de arranque y respawn CCScannerDB

[Service]
Type=simple
ExecStart=/bin/su -c /CCScannerDB/CCScannerDB.sh informix
Restart=always

[Install]
WantedBy=multi-user.target
But if I try to run it gives me an error and the script is not running:

Code: Select all

$ systemctl status ccscannerdb
● ccscannerdb.service - Servicio de arranque y respawn CCScannerDB
   Loaded: loaded (/etc/systemd/system/ccscannerdb.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Tue 2017-04-25 13:05:09 CEST; 45min ago
 Main PID: 24066 (code=exited, status=0/SUCCESS)
Anyone know how I can solve this problem?

I have tried with "line" and "line"... But nothing works.

Best regards

adeptus24
Posts: 2
Joined: 2017/04/25 11:31:22

Re: Run systemd script forever and restart if it dies

Post by adeptus24 » 2017/04/26 13:46:09

Hi all,

I have already solved the problem, in the script there was a control that forced to launch the script from a tty, so in the service I have included:

Unit section add:

Code: Select all

Conflicts=getty@tty1.service
OnFailure=unit-status-mail@%p.service
Service section add:

Code: Select all

StandardInput=tty-force
Best regards.

Post Reply