upstart job
Until Ubuntu 10.04 (LTS), upstart is the default system to start applications on startup.
Most applications you want to run automatically are not daemon-friendly.
And upstart does not play well with these applications or some easy subterfuges you might try to daemonise them like adding a &
at the end of the command…
The solution relies on 2 steps :
- be able to launch your application with
start-stop-damon
- configure an upstart job that will invoke the proper command
Step 1 : start-stop-daemon
Try to keep it simple and not add so many arguments. We will use upstart later on, so keeping track of the PID is not our job here.
Try something as simple as possible, like this :
start-stop-daemon -S -b -x <your-program-here> -- <your-opthions-here>
You can try the start-stop-daemon
command in your usual shell, simpli use kill to stop the daemon once it works.
Step 2 : upstart job
Create a file in /etc/init/
named myservice.conf
as follows :
- myservice.conf
start on (filesystem and net-device-up) stop on shutdown respawn respawn limit 10 5 expect daemon console log setuid gcp env HOME=/opt/gcp_cups_connector/ env USER=gcp exec start-stop-daemon -S -b -x /opt/gcp_cups_connector/gcp-cups-connector -- -config-filename /etc/gcp_cups_connector/gcp-cups-connector.config.json
The important part here is expect daemon
that will tell upstart that some forks are to be expected and the process will probably change uid.
This way, upstart will be able to follow the forks and keep track of the real pid.
That's it, it should now work !