1

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?

voretaq7
  • 79,879
  • 17
  • 130
  • 214

2 Answers2

4

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.

  • 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 (http://upstart.ubuntu.com/) in place of the traditional SysV init scripts and best practices are different there. – voretaq7 Nov 29 '11 at 18:59
0

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.

thinice
  • 4,716
  • 21
  • 38