Can't get service noip2 to start on boot [duplicate]

Solution 1:

Since Ubuntu 15.04 the standard way to control background processes (and much, much more) is systemd. I suggest switching from your init.d script to a systemd unit:

Create the file /etc/systemd/system/noip2.service with the following content (and drop your init.d scripts):

[Unit]
Description=noip2 service

[Service]
Type=forking
ExecStart=/usr/local/bin/noip2
Restart=always

[Install]
WantedBy=default.target

Then issue

sudo systemctl daemon-reload

to make systemd aware of the new unit (systemd caches unit files and this command makes systemd reconsider its cache).

Now you can try to start and stop your unit and see its status:

sudo systemctl status noip2
sudo systemctl start  noip2
sudo systemctl status noip2
sudo systemctl stop   noip2
sudo systemctl status noip2

To have the unit started at boot time you need to enable it:

sudo systemctl enable noip2

To disable autostart at boot time you must disable the unit:

sudo systemctl disable noip2

Most of the time five commands are sufficient to control a units behaviour:

systemctl start   $unit   # starts a unit NOW
systemctl stop    $unit   # stops a unit NOW
systemctl status  $unit   # shows status
systemctl enable  $unit   # starts a unit at boot time (but not NOW)
systemctl disable $unit   # stops autostart (but doesn't stop the unit NOW)

You may also enable autostart and start the unit imediately or disable autostart and stop it at once:

systemctl enable  --now $unit   # enable and start in one go
systemctl disable --now $unit   # disable and stop in one go

Update

Some research revealed the noip2 runs as a daemon, i.e. when you start it, it creates another process that runs in background (so called forking) and the foreground process immediately returns (exits). That's why the init.d script and the systemd unit failed: They started noip2 just to see it immediately exits. Hence, systemd tried to restart it over and over to no avail. (By default, systemd restarts a process at most 5 times within 10 seconds or so before giving up and leaving it in failed state.)

To tell systemd the unit is of type forking add the line

Type=forking

to the [Service] section as I just did in the snippet above. This tells systemd to expect the main process to return immediately but instead watch the process spawned (forked) by noip2.