Linux – How to respawn a script in RHEL/Centos6 when /etc/inittab has been deprecated

centosinitinittablinuxupstart

I have a custom init script and I want that script to be respawned if in case the process dies.

In RHEL/Centos 6 /etc/inittab is deprecated. So how should I ensure the process will be respawned?

Best Answer

On RHEL 6 to respawn a script, go to /etc/init and create a file

cd /etc/init
vi scriptFileName.conf

And add this content

start on stopped rc RUNLEVEL=[12345]
stop on runlevel [!12345]
respawn
exec /you/respawned/script.sh -your -parameters

Save file and then launch this command (without .conf of file)

start scriptFileName

Thats all!