wake_command

This commit is contained in:
mwiegand 2022-02-12 18:23:09 +01:00
parent 78b324903d
commit 6727fcf404
2 changed files with 21 additions and 13 deletions

View file

@ -1,17 +1,28 @@
from ipaddress import ip_interface
@metadata_reactor.provides(
'wol-sleeper/wake_command',
)
def wake_command(metadata):
waker_hostname = repo.get_node(metadata.get('wol-sleeper/waker')).hostname
mac = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/mac")
ip = ip_interface(metadata.get(f"network/{metadata.get('wol-sleeper/network')}/ipv4")).ip
return {
'wol-sleeper': {
'wake_command': f"ssh wol@{waker_hostname} 'wakeonlan {mac} && while ! ping {ip} -c1 -W3; do true; done'",
},
}
@metadata_reactor.provides(
'apt/packages/ethtool',
'systemd/units/enable-wol',
'systemd/services/enable-wol.service',
)
def systemd(metadata):
interfaces = set(
conf['interface']
for conf in metadata.get('network').values()
if conf.get('wol', False)
)
if not interfaces:
return {}
interface = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/interface")
return {
'apt': {
@ -28,10 +39,7 @@ def systemd(metadata):
'Service': {
'Type': 'oneshot',
'RemainAfterExit': 'yes',
'ExecStart': set(
f"ethtool -s {interface} wol g"
for interface in interfaces
),
'ExecStart': f'ethtool -s {interface} wol g',
},
'Install': {
'WantedBy': 'multi-user.target',

View file

@ -20,7 +20,6 @@
'ipv4': '10.0.0.5/24',
'gateway4': '10.0.0.1',
'mac': 'd8:cb:8a:e7:be:c6',
'wol': True,
},
},
'backup-server': {
@ -38,6 +37,7 @@
},
},
'wol-sleeper': {
'network': 'internal',
'waker': 'home.server',
},
'zfs-mirror': {