Is it possible to make systemd automatically restart a service only if the service did not return 0? As far as I have understood, a service returns 0, when a correct end occured- say when a user terminates the service actively like closing a program. I would love to tell systemd not to restart the service, when it was terminated by hand. Is that possible?
Linux – systemd restart service automatically only after crash
linuxsystemd
Best Answer
Yes, you can use
Restart=on-failure
inside the unit'sService
section.From systemd's documentation (also available at
man 5 systemd.service
):As an aside, instead of your current method of terminating the process by hand, you can explicitly tell systemd to stop the service with
systemctl stop
, which will bypass anyRestart=
settings.