Linux daemon start up
Solution 1
Put 2 comments into your script:
# chkconfig: - 90 10
# description: description of your service
As root, run :
chkconfig --add my_service
Solution 2
a basic unix daemon does the following:
fork
close all filedescriptors (stdout,stderr, etc)
chdir /
signal handeling (sighup, sigterm etc)
while
do stuff
sleep(xx)
done
(example in C: daemon.c)
Red Hat example on how to install startup scripts:
to start a deamon at system startup in redhat you need a init script. it should be placed in /etc/init.d
example of init script :
Code:
# chkconfig: 3 99 1
# description: my daemon
case "$1" in
'start')
/usr/local/bin/mydaemon
;;
'stop')
pkill mydaemon
;;
'restart')
pkill -HUP mydaemon
;;
esac
the first line will tell chkconfig to start the daemon in run level 3 with priority 99 and kill it as priority 1 when server shutdowns.
to install the startup script use the following: chkconfig --add ./scriptabove Now it will start when the server boots.
to start it right away use: service start
If you want more details information visit a link
Hope this helps somewhat!
Mr.Cool
Updated on June 04, 2022Comments
-
Mr.Cool about 2 years
i wrote one service on linux(Redhat Server Edition 5.1) . which is started by shell scritpt, In case when i start my application i manually start my service , now i want to start my service at boot time,by means i put my service on init.d folder by my daemon not invoke at boot time,any have idea how to start a daemon at boot time on linux?
this my sample but is not working
#!/bin/sh # # myservice This shell script takes care of starting and stopping # the <myservice> # # Source function library . /etc/rc.d/init.d/functions # Do preliminary checks here, if any #### START of preliminary checks ######### ##### END of preliminary checks ####### # Handle manual control parameters like start, stop, status, restart, etc. case "$1" in start) # Start daemons. echo -n $"Starting <myservice> daemon: " echo daemon <myservice> echo ;; stop) # Stop daemons. echo -n $"Shutting down <myservice>: " killproc <myservice> echo # Do clean-up works here like removing pid files from /var/run, etc. ;; status) status <myservice> ;; restart) $0 stop $0 start ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 1 esac exit 0