mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 04:19:19 -08:00
fix(avahi): workaround weird hostname conflicts
This commit is contained in:
parent
7dd0e14e1f
commit
4505d8b340
1 changed files with 41 additions and 1 deletions
|
|
@ -1,9 +1,12 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkDefault;
|
||||
inherit (lib.modules) mkDefault mkIf mkOptionDefault;
|
||||
inherit (lib.strings) makeBinPath;
|
||||
cfg = config.services.avahi;
|
||||
in {
|
||||
services.avahi = {
|
||||
enable = mkDefault true;
|
||||
|
|
@ -16,4 +19,41 @@ in {
|
|||
};
|
||||
wideArea = mkDefault false;
|
||||
};
|
||||
|
||||
systemd.services = let
|
||||
# work around a weird bug or interaction in avahi-daemon
|
||||
RestartSec = 2;
|
||||
daemon = "avahi-daemon.service";
|
||||
avahi-daemon-watchdog = pkgs.writeShellScript "avahi-daemon-watchdog" ''
|
||||
set -eu
|
||||
export PATH="$PATH:${makeBinPath [ config.systemd.package pkgs.coreutils pkgs.gnugrep ]}"
|
||||
while read -r line; do
|
||||
if [[ $line = *"Host name conflict"* ]]; then
|
||||
if systemctl is-active ${daemon} > /dev/null; then
|
||||
echo restarting avahi-daemon due to host name conflict... >&2
|
||||
systemctl stop ${daemon}
|
||||
sleep ${toString RestartSec}
|
||||
systemctl start ${daemon}
|
||||
fi
|
||||
fi
|
||||
done < <(journalctl -o cat -feu ${daemon} | grep -F 'Host name conflict, retrying with ')
|
||||
'';
|
||||
in mkIf (cfg.enable && cfg.publish.enable) {
|
||||
avahi-daemon = {
|
||||
serviceConfig = {
|
||||
inherit RestartSec;
|
||||
};
|
||||
};
|
||||
avahi-daemon-watchdog = {
|
||||
wantedBy = [ daemon ];
|
||||
serviceConfig = {
|
||||
Type = mkOptionDefault "exec";
|
||||
ExecStart = [
|
||||
"${avahi-daemon-watchdog}"
|
||||
];
|
||||
Restart = mkOptionDefault "on-failure";
|
||||
RestartSec = mkOptionDefault RestartSec;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue