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

9,019

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!

Share:
9,019

Related videos on Youtube

Shashank
Author by

Shashank

Updated on September 18, 2022

Comments

  • Shashank
    Shashank almost 2 years

    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?

  • Shashank
    Shashank over 9 years
    Thanks a lot John for quick help. That looks great. But I was looking for some functionality which is native to linux. Something which is alternative to 'inittab'. Any idea about that?
  • John
    John over 9 years
    you can use /etc/init (which is different then /etc/init.d ) and use respawn in the init file , you can see a good example here: grokbase.com/t/centos/centos/11a4n4x2gt/…
  • Michael Hampton
    Michael Hampton over 9 years
    @Shashank systemd will handle this in RHEL 7, but you didn't say you were using that.
  • yurenchen
    yurenchen over 6 years
    seems like ubuntu upstart service manager