Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am confused on how to start my Daemon C program at boot-up. The program runs as a Daemon OK when I satrt it from command shell, but now I want it to start up every time at boot-up. I have searched for the last week on how to do this and there many confusions on how this is done - easily and simply? I am running Unbuntu 11.10 and don't really want to put in the the Ubuntu Startup files - it works but only after the user has logged-on. I want it to start-up even if the user has not logged in - just like apache2 server that I have which starts up after boot-up - plain and simple.

What I have found is that I need to create a init script and put in in the /etc/init.d/ directory but am not sure how to do this properley? My Daemon is executable and located at /usr/local/bin/myDaemon and to run it from the command shell I simply use /usr/local/bin/myDaemon to run it?

Can someone please show me a simple basic exapmple script that I can use to get me started?

share|improve this question
add comment

migrated from stackoverflow.com Nov 29 '11 at 14:24

This question came from our site for professional and enthusiast programmers.

2 Answers

Don't forget to call the daemon library function in your program.

Then, create a /etc/init.d/yourdaemon script taking /etc/init.d/skeleton as a model (init script vary from distribution to distribution).

You could also create a crontab entry for your daemon, using @reboot as the time specification.

share|improve this answer
    
You also need to symlink your /etc/init.d/yourdaemon script into an appropriate place in the SysV RC hierarchy (the init manpage on your system will usually tell you which runlevels are for what, and finding the right spot within a runlevel is usually pretty self-explanatory. Note that Ubuntu has started using Upstart (upstart.ubuntu.com) in place of the traditional SysV init scripts and best practices are different there. –  voretaq7 Nov 29 '11 at 18:59
add comment

Other options outside of setting it up in /etc/init.d:

Crontab:

@reboot /path/to/exec

Most systems will have /etc/rc.local - which executes the commands in it on system boot.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.