Wake on LAN Persistance Issues 22.04

there should be a setting when you close the lid to do nothing, not suspend.

Your laptop should work and be pingable even with the lid closed.

2 Likes

Welcome @ArchitectTim to the community!

1 Like

I have changed the contents of the /etc/systemd/logind.conf file to the following:

#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#UserStopDelaySec=10
#HandlePowerKey=poweroff
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
#HandleRebootKey=reboot
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
LidSwitchIgnoreInhibited=no
#RebootKeyIgnoreInhibited=no
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RuntimeDirectoryInodesMax=400k
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192

This has the effect that when I close the lid the screen goes dark, but ssh keeps working and I can still use the laptop by ssh. The problem is that when I testend WOL I had the laptop next to me open and when I send the command sudo shutdown -h now by ssh it whould shut down. The I send the magic packet and it whould start back up. I thought everything was working so I closed the lid and set the laptop in the closet and try'd again and now It does not respond to the magic packets. I have testend that nothing changed exept the state of the lid. I think this might have something to do with that the laptop goes to diffrend power states when shut down depending on if the lid is open or closed, but I don't know how I whould change this and am not sure if that is the problem. Thanks for the fast reaction and for the warm welcome.

1 Like

See my post Jun '22, After you shutdown, it resets the Ethernet port. You need to set the Ethernet port to 'g' state so that when it gets a magic packet, it will wake up. I've tested it with a wired pc, have not tried with a laptop. Not sure if wifi cards support WOL.

2 Likes

Thank you for the help. I use a laptop, but have it pluged in directly to the router with a ethernet cable. So I do not use wifi. I have changed the contents of the wol-enable.service file to the following according to your post: '

[Unit]
Description=Wake-on-LAN for enp2s0
Requires=network.target
After=network.target

[Service]
ExecStart=/sbin/ethtool  -s enp2s0  wol g
ExecStop=/sbin/ethtool   -s enp2s0  wol g

[Install]
WantedBy=multi-user.target

Ather that I ran the commands:

systemctl start wol.service
systemctl enable wol.service
systemctl is-enabled wol.service
systemctl daemon-reload

Then I ran the command sudo poweroff and the laptop powerd off. When I send the wol magic packet the laptop woke op and ping came through. Then I closed the lid and send the sudo poweroff command again by ssh. The ping stoped. I send the magic packet twice and the ping did not come back and when I opent the lid the laptop was still off. When I then turned on the laptop I checked the contents of the wol-enable.service to copy it to this and then I checked the Ethernet port and it was in the g state.
I am thinking of just keeping the lid off Always, but that is not proffered as that will cost more electricity as the screen wil then be always on.
If you have some test that I could do with specific setting so you can help me better that would be great. I am currently just trying to put all relevant information in the post that I can think of. Thanks for the help so far. One other question, English is not my first language so I don't know how clearly this is. Is this clear to read or should I check more with google translate?

2 Likes

your English is fine. Since the ping stopped when you closed the lid, that means the Do Nothing you did in the logind.conf did not work. So, you need to find some file in systemd that senses the lid closed. This should be in power management.

My laptop (T420) with lid closed, Do nothing in power settings, I can ssh and look at logs to find where systemd hides all this.

journalctl -b -u systemd-logind.service there should be an event, Lid closed.

2 Likes

update: laptop T420 is wired and on power.

  1. set power management Do Nothing. Lid closed, laptop is still pingable, I don't know if it draws much current, I can ssh and do work on the laptop

  2. set power management Shutdown immediately, lid closed, laptop turned off. I added the WOl.service. Now I went to my router and sent a magic packet to the mac address, laptop woke up, is pingable.

3 Likes

If I start the laptop and run the commandjournalctl -b -u systemd-logind.service it outputs the following:

archi@ubuntuservertim:~$ journalctl -b -u systemd-logind.service
Jul 03 14:58:16 ubuntuservertim systemd[1]: Starting User Login Management...
Jul 03 14:58:17 ubuntuservertim systemd-logind[827]: New seat seat0.
Jul 03 14:58:17 ubuntuservertim systemd-logind[827]: Watching system buttons on /dev/input/event2 (Power Button)
Jul 03 14:58:17 ubuntuservertim systemd-logind[827]: Watching system buttons on /dev/input/event1 (Power Button)
Jul 03 14:58:17 ubuntuservertim systemd-logind[827]: Watching system buttons on /dev/input/event0 (Lid Switch)
Jul 03 14:58:17 ubuntuservertim systemd-logind[827]: Watching system buttons on /dev/input/event3 (AT Translated Set 2 keyboard)
Jul 03 14:58:18 ubuntuservertim systemd[1]: Started User Login Management.
Jul 03 14:58:32 ubuntuservertim systemd-logind[827]: New session 1 of user archi.

I then closed the lid on the laptop. Opent the lid again after 20 seconds and ran the command agian. This was the next output:

archi@ubuntuservertim:~$ journalctl -b -u systemd-logind.service
Jul 03 14:58:16 ubuntuservertim systemd[1]: Starting User Login Management...
Jul 03 14:58:17 ubuntuservertim systemd-logind[827]: New seat seat0.
Jul 03 14:58:17 ubuntuservertim systemd-logind[827]: Watching system buttons on /dev/input/event2 (Power Button)
Jul 03 14:58:17 ubuntuservertim systemd-logind[827]: Watching system buttons on /dev/input/event1 (Power Button)
Jul 03 14:58:17 ubuntuservertim systemd-logind[827]: Watching system buttons on /dev/input/event0 (Lid Switch)
Jul 03 14:58:17 ubuntuservertim systemd-logind[827]: Watching system buttons on /dev/input/event3 (AT Translated Set 2 keyboard)
Jul 03 14:58:18 ubuntuservertim systemd[1]: Started User Login Management.
Jul 03 14:58:32 ubuntuservertim systemd-logind[827]: New session 1 of user archi.
Jul 03 15:01:58 ubuntuservertim systemd-logind[827]: Lid closed.
Jul 03 15:02:10 ubuntuservertim systemd-logind[827]: Lid opened.

I now see a lid closed and lid opened event as the last 2 lines.
I have ran the command: sudo systemctl restart systemd-logind.service but this did not affect anything that I could test.
This are the ping logs


PS C:\Users\mailt> PING.EXE ubuntuservertim -t

Pinging ubuntuservertim.fritz.box [192.168.178.120] with 32 bytes of data:
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=2ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=2ms TTL=64
Reply from 192.168.178.120: bytes=32 time=2ms TTL=64
Reply from 192.168.178.120: bytes=32 time=2ms TTL=64
Reply from 192.168.178.120: bytes=32 time=1ms TTL=64
Reply from 192.168.178.120: bytes=32 time=2ms TTL=64
Reply from 192.168.178.120: bytes=32 time=2ms TTL=64
Reply from 192.168.178.120: bytes=32 time=2ms TTL=64
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.
Reply from 192.168.178.55: Destination host unreachable.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.
Reply from 192.168.178.55: Destination host unreachable.
Request timed out.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.
Reply from 192.168.178.55: Destination host unreachable.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.
Reply from 192.168.178.55: Destination host unreachable.
Reply from 192.168.178.55: Destination host unreachable.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.
Reply from 192.168.178.55: Destination host unreachable.
Request timed out.
Request timed out.
Reply from 192.168.178.55: Destination host unreachable.

Ping statistics for 192.168.178.120:
   Packets: Sent = 68, Received = 46, Lost = 22 (32% loss),
Approximate round trip times in milli-seconds:
   Minimum = 1ms, Maximum = 2ms, Average = 1ms
Control-C 

I find it intressting that when I shut the laptop off it says request timed out. But afther I send the magic packet it says somethimes host unreachable and sometimes request timed out.

1 Like

For me 1 is true.
For 2: Did you send the poweroff command before or after you closed the lid? By me it only did not work if I closed the lid before the power off command.

1 Like

that is option 2. when you shutdown laptop by closing the lid, it is no longer pingable, that's correct. The magic packet is sent to the mac address, it does not look for an ip address.

1 Like

Let me understand the steps you take:

you installed wol.service, then ssh to the laptop (wired and on power), you tell it to sudo poweroff. Then from router you send a magic packet to the mac address, the laptop should wake up.

In my case, I just changed the event, when lid is closed, shutdown immediately.

1 Like

What do you mean by installed wol.service. I ran:

 foc@ubuntu22:~$ sudo --preserve-env systemctl edit --force --full wol-enable.service

Then I typed this in the file with nano:

[Unit]
Description=Wake-on-LAN for enp2s0
Requires=network.target
After=network.target

[Service]
ExecStart=/sbin/ethtool  -s enp2s0  wol g
ExecStop=/sbin/ethtool   -s enp2s0  wol g

[Install]
WantedBy=multi-user.target

and ran:

systemctl start wol.service
systemctl enable wol.service
systemctl is-enabled wol.service
systemctl daemon-reload

I use vscode to create a ssh connection with the laptop. I manualy close the lid. The ssh connection keeps working becouse I edited the /etc/systemd/logind.conf file
Than I send the command sudo poweroff in vscode. The ssh connection breaks because it powers off.
Then I send a magic packet by the program Wake on LAN (Magic Packet) to the MAC address. I have also try'd with sending the magic packet by the web interface of the router. Both work if the lid is open when I power off the laptop. And both do not work if the lid is closed when I power off the laptop.

I don't know what you mean bij "In my case, I just changed the event, when lid is closed, shutdown immediately." I don't want to shutdown the laptop when the lid is closed as I want to keep using the laptop wether the lid is closed or not.


I can not reply to this threat. I am a new user of this form and I get the message that I am reply limited. What should I do. Edit this command or continue this converstation somewhere else?
@pavlos_kairis


My situation is this:
I have a old laptop that I would like to put away in a room to use as a test-server. In this case I want to be able to close the screen with the laptop still functioning because it doesn't need a screen as a server and it will only use electricity. I have this functionality working.
I also want to be able to remotely turn the "server" on and off, because I will use it for testing and it does not need to be always on. This way it uses less power and collects less dust inside it if it is not turnt on al the time. Turning it off is easy but turning it on not. I can use WOL to turn it on remotely, wich is exactly what I want. But then I ran into a problem. During testing I had the screen open, but when I put the laptop away to use it as a server and closed the screen the WOL stoped working. I eventualy found out that the problem of WOL not working only ocourd if the screen was closed at the time the laptop turned off. This could be fix in 2 ways by never turning it off (wich I do not prefer ) Or by always having the lid open (wich would cost electricy for the screen). The perfect solution whould be to be able to start the server with a magic packet even If the screen is closed.


I will go with your sugestion: Wake on LAN Persistance Issues 22.04 - #20 by pavlos_kairis
I have used the setterm command to let the screen go dark afther 2 minutes. This was not the solution that I was thinking of, but in practice it will make no difference so it is perfect. Thank you for your time to day @pavlos_kairis.

1 Like

based on your last paragraph, you want the laptop to remain ON regardless if the lid is closed or not, so you need option 1. Nothing to do with WOL.

you wrote "I don't want to shutdown the laptop", why do you send sudo poweroff ?

Maybe I don't understand the full scenario ...

Wake on LAN is used if you want to turn off a server/laptop and days/weeks/months and later you want to wake it up. To do so, you need what we added in .../systemd/system/ otherwise, if the laptop is 24/7 ON, just tell it, do nothing, when lid is closed.

1 Like

I read the "my situation is this ..."

Put the laptop in the closet with lid open, install the WOL.service, ssh to the laptop and sudo poweroff. laptop is off. From the other room you work on, send a packet to the mac address, the laptop should wake up and be pingable. Send again sudo poweroff, the laptop turns off and not be pingable. Then send the packet again, laptop wakes up and is pingable. This is option 2.

2 Likes

Hi there Pavlov, I'm sorry to drag you back into this but I was wondering if you could help me with a situation similar to Tim's.

Same situation entirely: I'm using my laptop (also a Lenovo Thinkpad T420) as a server and need to stash it somewhere with the lid closed. I'm using an Ikea Utespelare Desk (link gives you an image), which has a cable runway underneath the desktop where I store my laptop. WOL works perfectly when the lid is open, and you already know what happens when the lid is shut.

I've enabled WOL and created a service that runs every time it starts up. This was confirmed in that log you see every time you boot up the server version of Ubuntu, saying that wake on LAN was successfully enabled. The laptop is connected to power (I've removed the battery) and is connected to my router via ethernet.

I've gone into logind.conf and set anything related to the lid switch to "ignore". The laptop stays on when shutting the lid and I can use SSH to access it.

The problem begins once I use "sudo shutdown now" to turn it off remotely. At that point it's completely unreachable via WOL. I used TCPDump to confirm that the laptop was even receiving the magic packets at all, and it was.

Any help is appreciated, thank you for taking the time to read this.

1 Like

in the T420 BIOS, did you set Config > Network > Wake on LAN > AC Only ?

I just tried that and it worked, even with the lid shut. Unfortunately, once I put my laptop back and tried again, nothing happened.

in Settings > Power options, you should have do nothing when the lid closes.

To sum up: T420 laptop, when the lid closes, it does nothing. Turn off the laptop with sudo poweroff. The WOL service is installed and uses ethtool to set wol to g. You send a magic packet to the mac address and it wakes up. You can add comments to /var/log/syslog using logger. I dont see issues.

3 Likes

Welcome @Aarnav_Sharma to the community!

I'll try that tomorrow and let you know how it goes. Thanks for your help!