Linux – How to Start Linux Daemon program at boot up

daemonlinux

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?

Best Answer

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.