LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash script running as daemon (https://www.linuxquestions.org/questions/programming-9/bash-script-running-as-daemon-264970/)

Satriani 12-10-2004 03:08 PM

bash script running as daemon
 
Hi all,

I have written a bash script to ease my administration.
However, what i would like is, whenever i start this program, it will immediately get in the background and "daemonizes". (Meaning, that it will keep running, even if i log out.)

Is this possible with bash-scripts???
If it works as i expected, i would like to run it as service at startup (put it in the rc.d or rc.local orso), but it should also work as executable....

thanks for your help!

Satch

Cedrik 12-10-2004 03:12 PM

Did you try to put:
/path/to/your/script &

in /etc/rc.d/rc.local so it start at boot, run in background, and keep running even if you log out

Satriani 12-10-2004 03:13 PM

I see what you mean, however, i want to be able to start it by hand in the first period...

Cedrik 12-10-2004 03:19 PM

You could try your program with & to test it in background, but to keep it running out of the user
session I think you have to run it as root

Satriani 12-10-2004 03:26 PM

Running it as root was the trick i was lookin for! It now works!

thanks Cedrik!

SerfurJ 12-10-2004 03:29 PM

you can use detachtty if you want to run it as a user.

jlliagre 12-10-2004 03:49 PM

or nohup

Satriani 12-14-2004 04:28 PM

Mmm.. how should i run it then?
Should i enter something like that in the script?
If you could give an code-example, that would be great!

twantrd 12-14-2004 10:42 PM

nohup <script-name> &

-twantrd

/bin/bash 12-16-2004 06:39 AM

Since you are using Redhat you have a script handy which will launch a process as a daemon. The script is /etc/rc.d/init.d/functions and you could source that in your script and launch the process like this:

. /etc/rc.d/init.d/functions
daemon /path/to/my/script

This is from memory so you should double check the functions script to verify exactly how to call the daemon function.

Cedrik 12-16-2004 07:10 AM

Also, look at this HTTPD server written in sh script. It is a good example of a sh TCP deamon ( Main URL)

Satriani 12-16-2004 04:18 PM

Thanks bin/bash, but i am currently ot using RH, but Slackware... (Should update my profile, as you pointed me to this)

I could look in the script, i have a redhat machine somewhere..... :)

Also followd the link to that sh_httpd but it didn't help me further (yet)

j13ett5 03-29-2011 05:23 PM

Quote:

Originally Posted by Cedrik (Post 1353533)
Also, look at this HTTPD server written in sh script. It is a good example of a sh TCP deamon ( Main URL)

cute, but it's not a daemon, it appears to be a service that is launched on demand by sometheing like xinetd.


All times are GMT -5. The time now is 12:34 PM.