Systemd not adding "...wants" link to match WantedBy in unit file

Asked by Michael Fox

Systemd not adding "...wants" link to match WantedBy in unit file

Ubuntu 16.04LTS
watchdog package version 5.14-3ubuntu0.16.04.1
systemd package version 229-4ubuntu21.15

I can use "systemctl start watchdog.service" to start up the watchdog
daemon. But I'm trying to cause watchdog.service to start at boot-up with
"systemctl enable watchdog.service".

The default unit file that comes in the package is:

$ cat /lib/systemd/system/watchdog.service
[Unit]
Description=watchdog daemon
Conflicts=wd_keepalive.service
After=multi-user.target
OnFailure=wd_keepalive.service

[Service]
Type=forking
EnvironmentFile=/etc/default/watchdog
ExecStartPre=/bin/sh -c '[ -z "${watchdog_module}" ] || [ "${watchdog_module}" = "none" ] || /sbin/modprobe $watchdog_module'
ExecStart=/bin/sh -c '[ $run_watchdog != 1 ] || exec /usr/sbin/watchdog $watchdog_options'
ExecStopPost=/bin/sh -c '[ $run_wd_keepalive != 1 ] || false'

[Install]

And, because there is nothing in the [Install] section, I understand that
"systemctl enable watchdog.service" won't do anything.

So, I added the proper override file:

$ cat /etc/systemd/system/watchdog.service.d/override.conf
[Install]
WantedBy=multi-user.target

systemd seems to see the override file:

$ systemctl cat watchdog.service
# /lib/systemd/system/watchdog.service
[Unit]
Description=watchdog daemon
Conflicts=wd_keepalive.service
After=multi-user.target
OnFailure=wd_keepalive.service

[Service]
Type=forking
EnvironmentFile=/etc/default/watchdog
ExecStartPre=/bin/sh -c '[ -z "${watchdog_module}" ] || [ "${watchdog_module}" = "none" ] || /sbin/modprobe
ExecStart=/bin/sh -c '[ $run_watchdog != 1 ] || exec /usr/sbin/watchdog $watchdog_options'
ExecStopPost=/bin/sh -c '[ $run_wd_keepalive != 1 ] || false'

[Install]

# /etc/systemd/system/watchdog.service.d/override.conf
[Install]
WantedBy=multi-user.target

Then I run: systemctl enable watchdog.service

And this seems to work. But my understanding is that there should be a link in
/etc/systemd/system/multi-user.target.wants to the watchdog.service unit file.
But this link is not created.

As a result, when I reboot, I get:

$ systemctl status watchdog.service
● watchdog.service - watchdog daemon
   Loaded: loaded (/lib/systemd/system/watchdog.service; static; vendor preset: enabled)
  Drop-In: /etc/systemd/system/watchdog.service.d
           └─override.conf
   Active: inactive (dead)

Also,

$ systemctl show watchdog.service -p WantedBy
WantedBy=

It's like systemd doesn't see the WantedBy line.

I also tried a complete override of /lib/systemd/system/watchdog.service with
/etc/systemd/system/watchdog.service. I even tried adding the WantedBy line
directly into the /lib/systemd/system/watchdog.service file (which I know is
not the right way to override). But in all cases, systemd won't recognize the
WantedBy= line and won't create the link in .../multi-user.target.wants.

If I manually create the link:

ln -s /lib/systemd/system/watchdog.service \
  /etc/systemd/system/multi-user.target.wants/watchdog.service

and then reboot, watchdog comes up just fine.

But my understanding is that the link should be autogenerated based on the
WantedBy parameter in the [Install] section of the unit file.

So, why isn't that happening? What am I doing wrong?

Also, in case it's helpful /etc/default/watchdog is set to start watchdog
at boot time. I'm not sure how that relates to the above, if at all.

$ cat /etc/default/watchdog
# Start watchdog at boot time? 0 or 1
run_watchdog=1
# Start wd_keepalive after stopping watchdog? 0 or 1
run_wd_keepalive=1
# Load module before starting watchdog
#watchdog_module="none"
watchdog_module="iTCO_wdt"
# Specify additional watchdog options here (see manpage).
#watchdog_options="-v"

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu systemd Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

If you make the file /etc/rc.local and add the 3 below lines:

#!/bin/sh -e
systemctl start watchdog.service
exit 0

and mark it as executable, You can do this with

sudo chmod +x /etc/rc.local

Reboot to test

Revision history for this message
Michael Fox (news-9) said :
#2

I know how to start the service. That's not the problem. The problem is that systemd is not automatically creating the link in multi-user.target.wants so it starts automatically.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#3

I suggest you report a bug

Revision history for this message
Launa Stull (launastull) said :
#4

https://www.techrepublic.com/article/how-to-use-dns-over-tls-on-ubuntu-linux/
https://friday-nightfunkin.com

Could configure it yourself. We have SSL on websites for this sort of thing so you know you are hitting the right server.

Can you help with this problem?

Provide an answer of your own, or ask Michael Fox for more information if necessary.

To post a message you must log in.