Hi Robert, I just checked the Linux source, and setsid(8) does exactly what's required. Well spotted. The rc script to start the handle server should contain something like this: cd $SVRDIR # daemon's working directory rm -f $LOCKFILE # remove stale lock file su $HANDLEUSER -m -c \ "setsid $JAVA $MAIN $SVRDIR 0</dev/null 1>>server.log 2>&1 &" It's essential to redirect all three file descriptors in the setsid(8) command. For people who don't have setsid(8), or daemon(8), I have attached daemonise.c with a Makefile, which will do the same thing. The extra fork should not be required. The mechanism used to become a process group leader and detatch the controlling terminal has evolved a great deal over the years. It used to be that two forks were required. Setsid(8) forks before calling setsid(2), and that is sufficient. Cheers, -- Phil -----Original Message----- From: Robert Tupelo-Schneck [mailto:schneck@cnri.reston.va.us] Sent: Saturday, 31 July 2010 12:11 AM To: Chadwick, Philip Cc: handle-info@cnri.reston.va.us Subject: Re: [Handle-info] Starting and stopping the handle server from Unix rc scripts [SEC=UNCLASSIFIED] If your Linux has the "setsid" executable, you might find it preferable to "nohup". From http://bytes.com/topic/java/answers/528276-subject-detach-daemon : "A daemon changes its working directory, forks, redirects output streams to /dev/null, detaches from the controlling terminal by calling setsid(), and forks again. You'll be hard pressed to accomplish most of that in Java. Perhaps what you want is this instead: $ setsid java MyApp /dev/null 2>&1 & or $ ( setsid java MyApp /dev/null 2>&1 & ) & to get the extra fork." Robert On 2010-07-29, at 17:46, Chadwick, Philip wrote: > Hi Robert, > > Thank you for a very sensible and helpful response. > > Several others have also pointed out that swing is not used in the > handle server, and there is no need for a frame buffer. > > I am sure that nohup(1) would avoid most problems arising from sharing > a controlling terminal with other process, as SIGHUP is the signal you > would most often see -- when any process group leader did an exit(2). > However it's still very undesirable to expose a daemon to signals from > random other processes (which have the right to send any signal they > like to process group members). > > I see that Tanuki is well regarded (the Apache foundation "endorse" it). > However I can't find documentation on *exactly* what it does, and it > also looks to be very heavy weight. > > I will post my start/stop script solution as soon as I have tested it. > > Cheers, > > -- > Phil ------ If you have received this transmission in error please notify us immediately by return e-mail and delete all copies. If this e-mail or any attachments have been sent to you in error, that error does not constitute waiver of any confidentiality, privilege or copyright in respect of information in the e-mail or attachments. Please consider the environment before printing this email. ------
Attachment:
daemonise.c
Description: daemonise.c
Attachment:
Makefile
Description: Makefile