[Solved] Systemd-wakeonlan not working

Issues related to applications and software problems and general support
Post Reply
m0t0m
Posts: 22
Joined: 2017/01/04 10:05:56

[Solved] Systemd-wakeonlan not working

Post by m0t0m » 2020/09/26 05:15:47

My wakeonlan settings won't persist over reboot.

i created a udev rule following this https://www.linuxunit.com/add-systemd-s ... ke-on-lan/.

A part that isn't working is

Code: Select all

# vi /usr/lib/systemd/systemd-wakeonlan
#!/bin/sh

# only usable for root
[ $EUID = 0 ] || exit 4

start() {
        ethtool -s enp9s0 wol g
}

stop() {
        ethtool -s enp9s0 wol d
}

case "$1" in
        start|stop) "$1" ;;
esac 
I expect that when I run sudo systemctl start wakeonlan.service the setting Wake-on: d will change to Wake-on: g when check ethtool enp9s0

I tested $ ethtool -s enp9s0 wol g which works.
Last edited by m0t0m on 2020/10/12 15:49:50, edited 1 time in total.

mathog
Posts: 258
Joined: 2008/07/09 23:52:06

Re: Systemd-wakeonlan not working

Post by mathog » 2020/09/28 23:02:43

WOL can be a real can of worms.

Does the system in question have an option in its firmware that enables WOL? If so, be sure that it is turned on. That will in the case of most servers make the machine respond to WOL packets following a power failure (without UPS/nice shutdown) if it is not set to automatically start when it sees power. However, in the case of most desktops that setting will not be sufficient in that scenario.

The other WOL problem one often encounters is that while ethtool may have been used to set the network interface to "g", somewhere during the shutdown something else will turn that off again. So ironically a power failure which is gracefully handled (UPS detects, controlled shutdown) may leave the system unresponsive to a WOL packet. I wouldn't do this on a server, but on a desktop turning off the power strip at various times during the shutdown can sometimes reveal where that might be happening, when the power is yanked before that critical point the system will respond to WOL, and after it won't.

Regarding your specific question, how is it "not working"? Is "g" not set after the systemd command? If so put in something like:

echo "Debug 1" >>/tmp/debug.log

at various points in the script and see where it goes wrong, or if it is even executing at all. It might be as simple as the wrong file protection mask on the file.

mathog
Posts: 258
Joined: 2008/07/09 23:52:06

Re: Systemd-wakeonlan not working

Post by mathog » 2020/09/28 23:37:26

I just tested WOL on the one CentOS 8 machine I have. Following "poweroff" it woke right up when etherwake on Ubuntu was directed at its MAC. The system is using NetworkManager and shows this:

Code: Select all

nmcli c show eno1 | grep -i wake
802-3-ethernet.wake-on-lan:             default
802-3-ethernet.wake-on-lan-password:    --
Also WOL is set in the BIOS and it is a server class machine, albeit not a big one. It is a Dell PowerEdge T110 II and the NIC is:

Code: Select all

02:00.0 Ethernet controller: Broadcom Inc. and subsidiaries NetXtreme BCM5722 Gigabit Ethernet PCI Express
I did nothing to configure it to work, it just did. There is only the one network interface.

m0t0m
Posts: 22
Joined: 2017/01/04 10:05:56

Re: Systemd-wakeonlan not working

Post by m0t0m » 2020/09/29 06:04:36

Thanks for the idea to add a debug log to /usr/lib/systemd/systemd-wakeonlan

The problem was the .service at the end of systemctl stop wakeonlan.service as shown in the guide I linked.
running

Code: Select all

systemctl stop wakeonlan
works.

For future reference, to enable wake on lan on boot for an ethernet device in centos.

Get your enthernet device name with $ nmcli and replace enp9s0 with your device.


/usr/lib/systemd/systemd-wakeonlan

Code: Select all

#!/bin/sh

# only usable for root
[ $EUID = 0 ] || exit 4

start() {
        ethtool -s enp9s0 wol g
}

stop() {
        ethtool -s enp9s0 wol d
}

case "$1" in
        start|stop) "$1" ;;
esac
 
/usr/lib/systemd/system/wakeonlan.service

Code: Select all

[Unit]
Description=Configure Wake-up on LAN

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-wakeonlan start
ExecStop=/usr/lib/systemd/systemd-wakeonlan stop

[Install]
WantedBy=basic.target
The final step was to enable the service on boot

Code: Select all

# systemctl enable wakeonlan.service
ln -s '/usr/lib/systemd/system/wakeonlan.service'\
'/etc/systemd/system/basic.target.wants/wakeonlan.service'
I will mark as Solved after I have rebooted the system

mathog
Posts: 258
Joined: 2008/07/09 23:52:06

Re: Systemd-wakeonlan not working

Post by mathog » 2020/09/29 18:09:54

OK, but why is the network interface not coming up as "g" when it booted without the modification? As I said, the only configuration step on the server was to enable wake on lan in the firmware (BIOS in this case). Is your machine only signaling that it has the capability but it is not setting it?

Also, for many (most) desktops the system will not respond to a WOL packet after a "poweroff" no matter what one does in the BIOS or OS. Generalizing - server class machines can usually WOL following a "poweroff", desktops only WOL from "sleep" states.

m0t0m
Posts: 22
Joined: 2017/01/04 10:05:56

Re: Systemd-wakeonlan not working

Post by m0t0m » 2020/09/29 20:11:37

I don't know why the machine defaults to d, I assumed it was normal behavior as someone wrote a guide to make the change persist after reboot. It seems like a common behavior with tutorials for Linux Mint and Arch linux to make the change persistent.

My machine is an old laptop, an Dell inspiron 1545 with wake on lan enabled in the BIOS.

I send "systemctl suspend" and wake it from that using wol, not "poweroff".

If you know where to look I'd also like to know why the machine sets "d" instead of "g", but I can only guess it's a security measure.

mathog
Posts: 258
Joined: 2008/07/09 23:52:06

Re: Systemd-wakeonlan not working

Post by mathog » 2020/09/30 00:30:50

m0t0m wrote:
2020/09/29 20:11:37
My machine is an old laptop, an Dell inspiron 1545 with wake on lan enabled in the BIOS.

I send "systemctl suspend" and wake it from that using wol, not "poweroff".

If you know where to look I'd also like to know why the machine sets "d" instead of "g", but I can only guess it's a security measure.
The BIOS most likely is setting the NIC so that it is capable of using WOL but it does not actually set it up for you. It probably assumes the OS will do that.

With that class of machine what you are seeing is as good as it is going to get.

jimj
Posts: 93
Joined: 2014/10/01 05:34:57

Re: [Solved] Systemd-wakeonlan not working

Post by jimj » 2020/12/05 00:56:23

m0t0m wrote:
2020/09/26 05:15:47
I tested $ ethtool -s enp9s0 wol g which works.
Instead of ethtool did you try using nmcli to see if that persists across reboots?

Code: Select all

nmcli c modify "enp9s0" 802-3-ethernet.wake-on-lan magic
The GUI equivalent is:
nm-connection-editor

lightman47
Posts: 1522
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: [Solved] Systemd-wakeonlan not working

Post by lightman47 » 2020/12/12 16:58:09

Just 'throwing this out there' -

In researching my own problem (it always used to work on this machine, though it's now dual boot with Windows 10) I've learned that Windows can fiddle with this. I've messed with Device Manager power settings for the card as well as the BIOS to no avail. I don't get it!

Am currently trying your suggestions here with fingers crossed. The machine normally runs CentOS 7.

jimj
Posts: 93
Joined: 2014/10/01 05:34:57

Re: [Solved] Systemd-wakeonlan not working

Post by jimj » 2020/12/12 17:19:26

lightman47 wrote:
2020/12/12 16:58:09
In researching my own problem (it always used to work on this machine, though it's now dual boot with Windows 10) I've learned that Windows can fiddle with this. I've messed with Device Manager power settings for the card as well as the BIOS to no avail. I don't get it!
I posted some more WOL info in this thread and below are my Windows NIC device settings (I had to install Realtek drivers to get all of these options). Good luck!

Code: Select all

-Go to the "Power Management" tab and check everything
	-"Allow the computer to turn off this device to save power"
		-Checked by default
		-Seems counterintuitive, but it needs to be checked for WOL to work
	-"Allow this device to bring the computer out of standby"
		-Checked by default
		-This enables WOL
	-"Only allow management stations to bring this computer out of standby"
		-Unchecked by default
		-Checking this will only allow magic packets to wake up the computer.  Otherwise any traffic destined for this computer would wake it up.
-Go the the "Advanced" tab and make these changes
	-Shutdown Wake-On-Lan =		Enabled (this is the default)
		-This option wasn't available with the default Win10 built in driver
	-Wake on Magic Packet =		Enabled (this is the default)
	-Wake on pattern match =	Disabled (Enabled)
	-WOL &  Shutdown Link Speed = 	10 Mbps First (this is the default)
	-Note: These changes are lost whenever the driver is updated

Post Reply