Ubuntu: Issue starting a demon process at startup in Ubuntu



Question:

I tried Starting Deamon process. I am trying to run this command during startup to start DTN2 deamon using command dtnd -c DTN2/dtn/dtn.conf -o DTN2/dtn/log -d in ubuntu 14.04

I made this as a shell script in one location in my computer and added it in rc.local e.g sh '/pathtoscript/script.sh'. It works when i use sudo /etc/init.d/rc.local start. However it is not starting after the restart. How can i make sure this runs? Would creating a script using init.d or adding an Upstart job would be better way for running the deamon on startup for ubuntu 14.04.


Solution:1

And now, the Ubuntu answer.

You are using Ubuntu Linux. You already have either upstart or systemd (the former in this particular case). Do not begin by writing System 5 rc scripts.

/etc/rc.local is a double backwards compatibility mechanism, because it is a backwards compatibility mechanism for a mechanism that was itself a compatibility mechanism in System 5 rc. And as shown by the mess that https://askubuntu.com/a/618138/43344 addresses, using /etc/rc.local can go horribly wrong. Do not begin by using rc.local.

upstart and version 14

So write an upstart job file.

It would look something like this:

  # /etc/init/dtnd.conf    description "DTN2 daemon"    start on filesystem and static-network-up  stop on runlevel [016]    env DAEMON='/usr/sbin/dtnd'    respawn    exec /usr/sbin/dtnd -c /etc/dtn/dtn.conf -o /var/log/dtn/log  

Adjust for your log and configuration set up; and use as an upstart job, in the usual manner, with initctl start, initctl stop, and so forth.

Do not use the -d option. The program is already "daemonized" by dint of being run under a service manager.

systemd and version 15

So write a systemd service unit.

The first rule for migrating to systemd applies … yet again. Someone has already done this. For an example, see dtnd.service written by a pseudonymous person in 2012.

Again: Do not use the -d option. The program is already "daemonized" by dint of being run under a service manager.

Also note that you don't need the -o option. Log to standard output/standard error in the ordinary way, and systemd will write it to the journal.

Use as a systemd service, in the usual manner, with systemctl start, systemctl stop, systemctl status, and so forth. In particular, use systemctl enable to ensure that the service is auto-started at system bootstrap.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »