htrefil / rkvm

Virtual KVM switch for Linux machines
MIT License
386 stars 50 forks source link

Fix systemd services #48

Closed jian-lin closed 9 months ago

jian-lin commented 9 months ago

[1]: man systemd.special [2]: man systemd.unit

htrefil commented 9 months ago

Thank you for the MR!

network.target indicates that the network management stack has been started. Ordering after it has little meaning during start-up: whether any network interfaces are already configured when it is reached is not defined. Wouldn't it make more sense for the server to depend on network-online.target rather than network.target?

If I have listen = "12.34.56.7:1234" and server gets started when the interface on which the address 12.34.56.7 is bound to is not up yet, it will fail.

jian-lin commented 9 months ago

Wouldn't it make more sense for the server to depend on network-online.target rather than network.target?

network-online.target should be avoided, if possible, to not slow down the boot according to the "Should network-online.target be used?" section of Network Configuration Synchronization Points

Usually, a server is listened on addresses which are always available, such as 0.0.0.0. So network.target is enough.

If I have listen = "12.34.56.7:1234"

Then the suggestion from systemd is:

If you write a server: if you want to listen on other, explicitly configured addresses, consider using the IP_FREEBIND sockopt functionality of the Linux kernel. This allows your code to bind to an address even if it is not actually (yet or ever) configured locally.

Actually, IP_FREEBIND is not needed in some cases. For example, I let rkvm-server listen on an wireguard address with After=network.target and it works well because my wireguard service has Wants=network.target and Before=network.target.