I needed an easy way to shutdown or hibernate my machine over the network. This is a method1 that use a systemd socket service.
Considering systemd services for shutdown and hibernation are
respectively systemd-halt.service
and
systemd-suspend.service
, we create for each a systemd
socket unit file2:
Here is the content of systemd-halt.socket
(systemd-suspend.socket
is identical except the port which
is 2113):
[Socket]
ListenStream=2112
TriggerLimitBurst=1
TriggerLimitIntervalSec=10min
[Install]
WantedBy=sockets.target
ListenStream
is the port to listen.TriggerLimitBurst
andTriggerLimitIntervalSec
specify that the socket may be activated only once every ten minutes.
This should be installed in
/usr/local/lib/systemd/system
and enabled :
$ systemctl enable systemd-halt.socket
This way, any connection on the port 2112 and 2113 will respectively halt and suspend the target. This can be done with a navigator.