67 lines
2.7 KiB
Markdown
67 lines
2.7 KiB
Markdown
# Wolz
|
|
|
|
- Wake up or shutdown a device on the local network
|
|
- Broadcast Wake on Lan (WoL) magic packet to wake up.
|
|
- WoL only works if the target network interface supports it and is not in low power mode.
|
|
- Check [arch wiki](https://wiki.archlinux.org/title/Wake-on-LAN) on this subject to setup your device to Wakup on LAN.
|
|
- Run a daemon on the target machine to accept shutdown requests.
|
|
|
|
## Design goals
|
|
|
|
- Do not have any dependency on other crates, only on shared libraries shipped with the distro.
|
|
- Do not start any additional process. (No Command::new stuff)
|
|
- Configuration should only have MAC addresses as they are permanent for a device. Do not configure any IP address
|
|
|
|
## Usage
|
|
|
|
Run `wolz` to view the help text.
|
|
|
|
### Shutdown functionality
|
|
|
|
Run `wolz` under daemon mode to start listening to tcp traffic on port (check code for port). Make sure firewall doesn't block.
|
|
|
|
The daemon process can be started as systemd service after network.targets. The user running should have the following permissions, setup in polkit. Create a new rule.
|
|
|
|
```
|
|
$ # Read the config below and update the subject.user as appropriate
|
|
$ cat /etc/polkit-1/rules.d/50-poweroff-chips.rules
|
|
polkit.addRule(function(action, subject) {
|
|
if ((action.id == "org.freedesktop.login1.power-off" ||
|
|
action.id == "org.freedesktop.login1.power-off-multiple-sessions" ||
|
|
action.id == "org.freedesktop.login1.reboot" ||
|
|
action.id == "org.freedesktop.login1.reboot-multiple-sessions") &&
|
|
subject.user == "chips") {
|
|
return polkit.Result.YES;
|
|
}
|
|
});
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
This tool broadcasts the magic packet to the broadcast address (and port 9) of all networks the physical interfaces connect to.
|
|
|
|
Install `tcpdump` to inspect the network traffic on the receiving node. And execute the tool from the source node.
|
|
|
|
```bash
|
|
$> # Update `enp42s0` to your interface name.
|
|
$> sudo tcpdump -i enp42s0 udp and port 9 -n -XX
|
|
$>
|
|
$> # Sample output for mac aa:bb:cc:dd:ee:ff
|
|
18:56:47.573848 IP 192.168.0.10.34801 > 192.168.0.255.9: UDP, length 102
|
|
0x0000: ffff ffff ffff dca6 324f e820 0800 4500 ........2O....E.
|
|
0x0010: 0082 adf8 4000 4011 0a19 c0a8 000a c0a8 ....@.@.........
|
|
0x0020: 00ff 87f1 0009 006e 8b27 ffff ffff ffff .......n.'......
|
|
0x0030: aabb ccdd eeff aabb ccdd eeff aabb ccdd ................
|
|
0x0040: eeff aabb ccdd eeff aabb ccdd eeff aabb ................
|
|
0x0050: ccdd eeff aabb ccdd eeff aabb ccdd eeff ................
|
|
0x0060: aabb ccdd eeff aabb ccdd eeff aabb ccdd ................
|
|
0x0070: eeff aabb ccdd eeff aabb ccdd eeff aabb ................
|
|
0x0080: ccdd eeff aabb ccdd eeff aabb ccdd eeff ................
|
|
```
|
|
|
|
To debug TCP packets intended to wolz-daemon, run
|
|
|
|
```
|
|
$> sudo tcpdump -i lo tcp and port 21367 -n -XX
|
|
```
|