Enable daemon to run with service daemon start,etc
Hi,
I have a php script that runs as a deamon.I start it up with php deamon.php from my /etc/rc.local file.What must i do so that i can use linux commands such as chkconfig deamon and service deamon start/restart on it? Thanks |
chkconfig and service are wrappers for the 'init' scripts. To use them you need to add a script into /etc/rc.d/init.d/ If you inspect the contents of the directory you'll see all of the existing scripts.
chkconfig is used to assign each script to a particular run level. This is evident by ruining 'chkconfig --list'. You'll need to copy and amend any of the script to suite you purpose then tell chkconfig when to run it i.e. chkconfig --level 35 <your script> |
Hi,
Ok,i have had a look at the scripts,and i added my script /etc/init.d.It works fine with service start.and chkconfig on. My question now is.how would i gou about to notify my daemon when the system shuts down?I know i should do a chkconfig off,or put the script in /etc/rc6.d.but what can i do to tell the deamon(say its a simple while(1) loop),that it must stop what its doing,and shut the service down.I assume i must have some interrupt checker of some kind?Can anyone give me some info how i need to go about getting this working? example..Say this my daemon Code:
while (1) do Thanks |
On runlevel change init sends the process a TERM and then a KILL so (using chkconfig to) link your script in /etc/init.d to /etc/rc0.d/K<number>nameofscript and /etc/rc6.d/K<number>nameofscript should be enough.
|
HI Thanks for the reply.
I understand the whole procedure with adding it.My only problem is,how do i,in my deamon that is already running,catch this TERM signal,and send all connected to the deamon.(Its a socket server)a notification that we're going down.something like. Code:
while (1) do |
Hi,
Looks like i got the answer.Thanks for the help.if anyone else is looking for an answer on this try something like(in php) Code:
// signal handler function |
Well done posting the answer yourself.
|
All times are GMT -5. The time now is 06:29 PM. |