LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-03-2011, 04:23 PM   #1
bitznarf
LQ Newbie
 
Registered: Jul 2010
Posts: 15

Rep: Reputation: 1
inittab respawn vs. rc?.d


Hello folks,

I'm writing a custom daemon (test platform is CentOS 5.5) that needs to run at startup and respawn if it ever terminates for whatever reason. I've scrounged around on the net and found some advice for how to achieve this but I've had no success.

I've tried:
  • Adding my executable to inittab as gt:345:respawn:/sbin/goose-daemon In this case 8 copies of the daemon process are spawned and init stops further copies from opening for a while
  • Removing the daemon(0,0) calls from the program. In this case as expected init reaches the main loop in the program and thus never returns to carry on with loading other scripts.
  • Adding a startup script to init.d and using chkconfig to symlink it into runlevels 345 (the daemon(0,0) call is added back in). In this case the daemon starts correctly, terminates correctly, but when I call pkill goose-daemon the process does not relaunch.

According to various websites (this one in particular) starting the process directly from inittab with respawn set should work but it doesn't. What am I missing here? Do I need some particular set of code to interact properly with init to allow the both the correct respawn of the process as well as deamonizing it? Is there some way to use the rc?.d files to respawn the process if it is killed?

Below is the code I am using to daemonize the process as well as part of the of the script for rc?.d

Code:
	daemon(0,0);

	signal(SIGCHLD,SIG_IGN); /* ignore child */
	signal(SIGTSTP,SIG_IGN); /* ignore tty signals */
	signal(SIGTTOU,SIG_IGN);
	signal(SIGTTIN,SIG_IGN);
	signal(SIGHUP,SignalHandler); /* catch hangup signal */
	signal(SIGTERM,SignalHandler); /* catch kill signal */

Code:
function start()
{
    echo -n $"Starting goose-daemon:"
    daemon $PROCESS $CONFIG
    echo
    RETVAL=$?
    if [ $RETVAL -eq 0 ] ; then
       touch $LOCKFILE
    fi
}

function stop()
{
    action $"Stopping goose-daemon:" killproc goose-daemon
    RETVAL=$?
    if [ $RETVAL -eq 0 ] ; then
       rm -f $LOCKFILE
    fi
}

Last edited by bitznarf; 03-03-2011 at 04:38 PM.
 
Old 03-03-2011, 05:53 PM   #2
bitznarf
LQ Newbie
 
Registered: Jul 2010
Posts: 15

Original Poster
Rep: Reputation: 1
It seems I was wrong about what was happening when I removed the 'daemon(0,0)' code from the program. What init was doing was launching the program but it did not appear to return me to the console afterwards. However, if I tried to type/enter commands I was able to do so as expected - the [user@host] simply was not showing up after the output of the daemon.

Thus, with the 'daemon(0,0)' removed, and an entry in inittab the process spawns once on startup, then respawns when killed. I may have to add some code in to manual redirect stdin/out/err etc.

Is there a way to daemonize the process without init thinking that the process as terminated and thus needs to be respawned? Or another way to go about this using rc?.d or some other method?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to respawn a service, using respawn entry in /etc/inittab sampappachan_nyc Linux - Server 1 10-05-2010 04:58 PM
what's difference between '::respawn:/bin/sh' and '::respawn:-/bin/sh'? rainballdh Programming 1 11-06-2008 01:25 PM
Is there any differences between ::respawn:-/bin/sh and ::respawn:/bin/sh? rainballdh Linux - Newbie 1 11-06-2008 10:17 AM
respawn changes to off on ttyS1 DownhillGeezer Linux - General 4 02-19-2007 11:25 AM
respawn--about "/etc/inittab" iclinux Linux - Newbie 3 02-02-2005 12:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration