3

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?

3

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!

  • seems like ubuntu upstart service manager – yurenchen Mar 2 '18 at 10:56
0

I normally use supervisord.

http://supervisord.org/

clean and simple.

Here's a nice example:

[program:vmstats]
; this assumes that there's a symlink from vmstats->vmstats-VERSION
command=/apps/vmstats/jdk1.6.0_32/bin/java -Dlog4j.configuration=file:/apps/vmstats/log4j.properties -jar /apps/vmstats/vmstats-2.0.1-jar-with-dependencies.jar
numprocs=1                    ; number of processes copies to start (def 1)
directory=/apps/vmstats/                ; directory to cwd to before exec (def no cwd)
autostart=true                ; start at supervisord start (default: true)
autorestart=true       ; whether/when to restart (default: unexpected)
startsecs=3                  ; number of secs prog must stay running (def. 1)
startretries=3                ; max # of serial start failures (default 3)
user=vmstats                  ; setuid to this UNIX account to run the program
redirect_stderr=true          ; redirect proc stderr to stdout (default false)
stdout_logfile=/var/log/vmstats/vmstats-stdout.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false   ; emit events on stdout writes (default false)
stderr_logfile=/var/log/vmstats/vmstats-stderr.log        ; stdout log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10     ; # of stderr logfile backups (default 10)
stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
stderr_events_enabled=false   ; emit events on stderr writes (default false)

you can see it here: https://github.com/Nordstrom/vmstats/blob/master/supervisord/vmstats.conf

  • 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? – Shashank Oct 30 '14 at 13:22
  • 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/… – John Oct 30 '14 at 14:53
  • @Shashank systemd will handle this in RHEL 7, but you didn't say you were using that. – Michael Hampton Oct 30 '14 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.