nixos/terraria: Wait for daemon to stop

+13 -3
+13 -3
nixos/modules/services/games/terraria.nix
··· 18 18 (boolFlag "secure" cfg.secure) 19 19 (boolFlag "noupnp" cfg.noUPnP) 20 20 ]; 21 + stopScript = pkgs.writeScript "terraria-stop" '' 22 + #!${pkgs.runtimeShell} 23 + 24 + if ! [ -d "/proc/$1" ]; then 25 + exit 0 26 + fi 27 + 28 + ${getBin pkgs.tmux}/bin/tmux -S /var/lib/terraria/terraria.sock send-keys Enter exit Enter 29 + ${getBin pkgs.coreutils}/bin/tail --pid="$1" -f /dev/null 30 + ''; 21 31 in 22 32 { 23 33 options = { ··· 124 134 125 135 serviceConfig = { 126 136 User = "terraria"; 127 - Type = "oneshot"; 128 - RemainAfterExit = true; 137 + Type = "forking"; 138 + GuessMainPID = true; 129 139 ExecStart = "${getBin pkgs.tmux}/bin/tmux -S /var/lib/terraria/terraria.sock new -d ${pkgs.terraria-server}/bin/TerrariaServer ${concatStringsSep " " flags}"; 130 - ExecStop = "${getBin pkgs.tmux}/bin/tmux -S /var/lib/terraria/terraria.sock send-keys Enter \"exit\" Enter"; 140 + ExecStop = "${stopScript} $MAINPID"; 131 141 }; 132 142 133 143 postStart = ''