Broker exit request and nix run .#loop for self-updating hosts
- broker: `{"type":"exit"}` answers `exiting`; `sausage run` then stops all
actors and exits with code 75.
- flake: apps `loop` / `loop-internal` run `nix run --refresh git+ssh://.../surma/sausage -- run <world>`
in a loop; exit code 0 (/quit) ends the loop, anything else restarts.
- PROTOCOL.md, README.md, test in cli/tests/host.rs.
Not compiled: written by the Sausage agent, which cannot build the native host.
This commit is contained in:
@@ -35,11 +35,32 @@
|
||||
'';
|
||||
meta.mainProgram = "sausage";
|
||||
};
|
||||
# `nix run .#loop -- <world>` runs the newest `sausage run <world>`
|
||||
# from the Gitea repo, again and again: after a crash or a broker
|
||||
# `exit` request it refreshes the flake and starts the host again,
|
||||
# so the world updates itself. `/quit` (exit code 0) ends the loop.
|
||||
# `--internal` (or `.#loop-internal`) uses Gitea's SSH port on the LAN.
|
||||
publicUrl = "git+ssh://containeruser@gitea.surma.technology:2222/surma/sausage";
|
||||
internalUrl = "git+ssh://containeruser@10.0.0.2:2222/surma/sausage";
|
||||
loop = name: url: pkgs.writeShellScriptBin name ''
|
||||
url="${url}"
|
||||
if [ "''${1:-}" = "--internal" ]; then url="${internalUrl}"; shift; fi
|
||||
if [ $# -eq 0 ]; then set -- world; fi
|
||||
while true; do
|
||||
nix run --refresh "$url#default" -- run "$@"
|
||||
code=$?
|
||||
if [ "$code" -eq 0 ]; then exit 0; fi
|
||||
echo "sausage-loop: sausage exited with $code, starting the newest version in 2 s …" >&2
|
||||
sleep 2
|
||||
done
|
||||
'';
|
||||
in
|
||||
{
|
||||
packages.default = sausage;
|
||||
|
||||
apps.default = { type = "app"; program = "${sausage}/bin/sausage"; };
|
||||
apps.loop = { type = "app"; program = "${loop "sausage-loop" publicUrl}/bin/sausage-loop"; };
|
||||
apps.loop-internal = { type = "app"; program = "${loop "sausage-loop-internal" internalUrl}/bin/sausage-loop-internal"; };
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
packages = [ rust pkgs.wasmtime pkgs.wasm-tools ];
|
||||
|
||||
Reference in New Issue
Block a user