To expand on Ipor Sircer's comment about using
From the RHEL 7 Documentation:
Systemd is a system and service manager for Linux operating systems. It is designed to be backwards compatible with SysV init scripts, and provides a number of features such as parallel startup of system services at boot time, on-demand activation of daemons, support for system state snapshots, or dependency-based service control logic. In Red Hat Enterprise Linux 7, systemd replaces Upstart as the default init system.
systemd manages services and the system as a whole. If you want a process to always be running, then you want it to behave as a service. It is not difficult to make custom service files.
Service Files belong in
/etc/systemd/system/NAME.service as per documentation
An example of a custom service file from the RHEL 7 documentation again:
Their description of what this file does:
service_description is an informative description that is displayed in journal log files and in the output of the systemctl status command.
the After setting ensures that the service is started only after the network is running. Add a space-separated list of other relevant services or targets.
path_to_executable stands for the path to the actual service executable.
WantedBy states the target or targets that the service should be started under. Think of these targets as of a replacement of the older concept of runlevels, see Section 9.3, “Working with systemd Targets” for details.
Type=simple is the norm, and assumes the executable launched in the
ExecStart will remain running.
Back to the original question, if you use
systemd to turn your process into a service you can use
systemd to ensure your service is always running.
From the RHEL 7 Documentation again:
Another example is a configuration file that restarts the service after its main process exited, with a delay of 30 seconds:
If you just add the
Restart=always option into the
[Service] section of your service file the service should restart any time it goes down/exits unless you stop it using