LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Run init script as daemon (http://www.linuxquestions.org/questions/linux-software-2/run-init-script-as-daemon-527211/)

isuck@linux 02-10-2007 12:51 AM

Run init script as daemon
 
I just added a small script to my init scripts, it basically continuously reads a pipe. If I run this script from the command line without & if freezes my screen and I can't stop it. Now I wonder if the same is going to happen when I reboot. Is there any way to tell the script to run as a daemon directly? TIA

wjevans_7d1@yahoo.co 02-10-2007 08:35 AM

In whatever init file calls your init script, try putting a & after the call to your script.

For example, if your call to your init script says:

Code:

/etc/rc.d/localscripts/mylocalscript
then it should now say:

Code:

/etc/rc.d/localscripts/mylocalscript &
Hope this helps.

isuck@linux 02-10-2007 07:01 PM

Thanks for your answer, I knew that one, but I meant something inside the script so I didn't have to call it with the & at the end.

wjevans_7d1@yahoo.co 02-11-2007 07:14 AM

If you're programming entirely with bash scripts, and you want to start something that continues after the boot process is complete, I don't think you can avoid "&".

alienDog 02-11-2007 07:40 AM

It's possible to avoid the &:

#!/bin/bash
if [ "x$1" != "xdaemon" ]; then
$0 daemon &
exit 0
fi

... the rest of your script goes here

isuck@linux 02-12-2007 02:29 AM

Thanks for all the answers. That's what I was looking for alienDog.


All times are GMT -5. The time now is 03:53 PM.