Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a daemon/service (milter-regex), that is dying. I'm only using it temporarily (A few months), so don't care too much, but I want it to restart when it dies.

It is an init.d script. 'service milter-regex start' etc. The init script lives at /etc/init.d/milter-regex

I know if I have something in /etc/inittab, it will automagically respawn if it dies. Are init scripts supposed to do this as well, or do I need to put it in inittab?

It could be failing to restart as it isn't cleaning up a stale sock file, which I will fix today, but thought I'd ask the question anyway.

Running on RHEL4 (Yes, old)

Thanks, Brock

share|improve this question
    
Can you edit the question to be better organized and clear? What is the content of the script in question, etc. –  vgoff Nov 14 '12 at 22:23
    
@vgoff My question wasn't about the script, just about if daemons started via 'service nameofdaemon start' were supposed to respawn automatically. Adding the content of the script would make my question less clear. –  Brock Nov 14 '12 at 23:34
add comment

2 Answers

up vote 1 down vote accepted

Scripts in init.d don't get rerun automatically when the service crashes. If you want to do the minimum amount of work to make sure it runs, inittab may be your best bet. It's icky though, almost as icky as still running RHEL 4.

share|improve this answer
    
Can I clean up a sock file in inittab? 'mrx:2345:respawn:rm -f sock;milter-regex' Or will that do something weird like attempt to keep rm running? –  Brock Nov 14 '12 at 22:15
    
I wouldn't try that... maybe wrap milter-regex in a script that deletes the socket and exec's milter-regex. –  Dennis Kaarsemaker Nov 14 '12 at 22:31
    
OK. Thanks for your help. –  Brock Nov 14 '12 at 22:57
add comment

I had to solve a very similar problem for RHEL6. (In addition there was not only one command but a pipe of commands.) Because I wanted to stay with the /etc/init.d scripts, I wrote a small tool pipexec: this restarts the child if it terminates and can easily integrated into the /etc/init.d scripts, because e.g. it also supports pid file handling.

Example:

$ pipexec -p /var/run/whatsoever.pid -s 5 -- /opt/bin/whatsoever

Creates a pid file, runs /opt/bin/whatsoever. When the whatsoever is abnormally terminated (e.g. by a signal), pipexec waits 5 seconds and restarts it.

Kind regards - Andreas

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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