0

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.

3
  • Yes, an init.d script would be better
    – Daniel
    Dec 8, 2015 at 20:12
  • Thanks ...Sorry, I am new to this Can i ask how can i use that ..As far as i kno i need to Create new script in init.d and giving path to the script which has the follwing command dtnd -c DTN2/dtn/dtn.conf -o DTN2/dtn/log -d..making the scripts executable and configuring init.d system to run this at startup using update-rc.d script defaults...Is there any other thing i should know to start deamon using init.d....I guess i had tried this once but did not work..Did I miss anything?
    – Don
    Dec 8, 2015 at 20:20
  • See this: gist.github.com/naholyr/4275302
    – Daniel
    Dec 8, 2015 at 21:59

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .