I've got a 3-rd party proprietary application server daemon which can be started and stopped by couple of command lines. I need this daemon to start when the system starts up and correctly stopped on system shutting down. How do I correctly implement this? Is it enough to copy some script inside /etc/init.d and modify it accordingly?

5 Answers
5

init.d is the old, deprecated system for starting daemons; is has been supplanted by upstart. Upstart has the advantage of being far easier to configure and allows proper sequencing of task initialization.

The configuration files for upstart live in /etc/init and if your daemon has no pre-requisites it can be as simple as tty1.conf:

# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
exec /sbin/getty -8 38400 tty1

in which case you can copy that file and modify to taste. More complex configurations are best documented at the upstart site and in other entries in /etc/init.

added in response to comment

Whether you use upstart or init.d, you'll still need some way of determining when Firebird is properly initialized. Unfortunately, Firebird itself doesn't seem to have a good way of verifying that it is installed and running. Therefore, the recommendation to stick your program start into /etc/rc.local is certainly the easiest, and on Ubuntu - at least - is guaranteed to run about as late as possible in the boot process.

if you do not want to migrate to UPSTART, but want the classic approach, you must:

NOTE: i am saving the service and the program with the same name in different directories (but you can change this, as long as it is reflected in your service file). change "myscriptname" and "myprogramname" to real names!

save your program that will run as a service in /usr/sbin

sudo cp myprogramname /usr/sbin/myscriptname

create a basic startup script (use /etc/init.d/skeleton as reference)

move this script to /etc/init.d

sudo mv /etc/init.d/myscriptname

give this script executable permission (i used 775, but you can set it lower)

sudo chmod 755 /etc/init.d/myscriptname

goto /etc/init.d

cd /etc/init.d

include in startup list with low startup priority

sudo update-rc.d myscriptname default 97 03

reboot your machine and check if the service has started properly

sudo ps -A --sort cmd

if your service is not starting properly, you should first check if it runs when called by hand:

cd /etc/init.d
sudo myscriptname -start

below i include a sample service file that actually works. compare it to skeleton service so as to understand what you need to configure. NOTE: this works on Ubuntu 12.04 amazon cloud AWS EC2 classic LAMP implementation.