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.