deploy: version systemd runtime setup
This commit is contained in:
23
deploy/systemd/bin/metin-game-instance-start.in
Normal file
23
deploy/systemd/bin/metin-game-instance-start.in
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
instance="${1:?missing instance name}"
|
||||
root_dir="{{RUNTIME_ROOT}}/channels"
|
||||
channel_dir="${instance%_*}"
|
||||
core_dir="${instance##*_}"
|
||||
workdir="${root_dir}/${channel_dir}/${core_dir}"
|
||||
binary="./${instance}"
|
||||
|
||||
if [ ! -d "$workdir" ]; then
|
||||
echo "Missing workdir for instance ${instance}: ${workdir}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$workdir"
|
||||
|
||||
if [ ! -x "$binary" ]; then
|
||||
echo "Missing executable for instance ${instance}: ${workdir}/${instance}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exec "$binary"
|
||||
29
deploy/systemd/bin/metin-wait-port
Normal file
29
deploy/systemd/bin/metin-wait-port
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if len(sys.argv) < 3:
|
||||
print("usage: metin-wait-port <host> <port> [timeout_secs]", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
host = sys.argv[1]
|
||||
port = int(sys.argv[2])
|
||||
timeout_secs = float(sys.argv[3]) if len(sys.argv) > 3 else 30.0
|
||||
deadline = time.monotonic() + timeout_secs
|
||||
|
||||
while time.monotonic() < deadline:
|
||||
try:
|
||||
with socket.create_connection((host, port), timeout=0.5):
|
||||
return 0
|
||||
except OSError:
|
||||
time.sleep(0.2)
|
||||
|
||||
print(f"Timed out waiting for {host}:{port}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user