Unix/Linux Go Back    


Ubuntu Ubuntu is a complete desktop Linux operating system, freely available with both community and professional support.

unix and linux commands - unix shell scripting

How can I automatically start a daemon at boot time.

Ubuntu


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-18-2008   -   Original Discussion by iamjayanth
iamjayanth's Unix or Linux Image
iamjayanth iamjayanth is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 9 June 2009, 2:53 AM EDT
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
How can I automatically start a daemon at boot time.

Hi masters,

I am still learning trades in kernel. I am trying to learn the basic of daemon programming. Can any one tell me how can I start a daemon automatically during boot up. I will be greatfull if anyone post some example code to the above task.
Also what are the other things that you must know when you try daemon programming? Can any one help me?
Sponsored Links
    #2  
Old Unix and Linux 12-18-2008   -   Original Discussion by iamjayanth
s93366's Unix or Linux Image
s93366 s93366 is offline
Registered User
 
Join Date: Apr 2002
Last Activity: 4 August 2011, 11:04 AM EDT
Location: Sweden / Stockholm
Posts: 168
Thanks: 0
Thanked 1 Time in 1 Post
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 <name_of_initfile> start


Hope this helps somewhat!

Last edited by s93366; 12-18-2008 at 04:38 AM..
Sponsored Links
    #3  
Old Unix and Linux 12-18-2008   -   Original Discussion by iamjayanth
iamjayanth's Unix or Linux Image
iamjayanth iamjayanth is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 9 June 2009, 2:53 AM EDT
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks s93366 ...... That was very useful..............That cleared all.........
    #4  
Old Unix and Linux 03-10-2009   -   Original Discussion by iamjayanth
agan01's Unix or Linux Image
agan01 agan01 is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 22 June 2009, 1:06 PM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How does it work on Solaris?

Hi s93366,

Thanks so much for the excellent tutorial. I works great on Linux environment. However, When I was trying it on Solaris environment, it doesn't work since there's no chkconfig on Linux. Do you have any idea on how to make it work on Solaris? I am new to Linux/Unix, and is learning Linux/Unix. Any help will be greatly appreciated.
Sponsored Links
Closed


Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Database can't start automatically on solaris Sachin Vaidya Solaris 2 02-27-2008 11:12 PM
How to start Oracle database automatically greg0320 Solaris 3 03-30-2005 05:46 PM
start a process at boot up time vtran4270 UNIX for Advanced & Expert Users 1 12-08-2002 07:31 PM
getting postfix tyo start automatically kmgrady01 UNIX for Dummies Questions & Answers 2 05-21-2002 03:18 AM
Disable routed daemon at boot time???? rrivas UNIX for Dummies Questions & Answers 2 04-09-2002 12:53 PM



All times are GMT -4. The time now is 06:56 PM.