mirror of
https://github.com/sol1/rustguac.git
synced 2026-10-25 21:19:45 +00:00
26c75748b6
The entrypoint waited for both processes, so if guacd died the container kept running with every session failing, and a restart policy never fired (and the same if rustguac died). Wait for whichever exits first with bash's wait -n, stop the other, and exit with its status. Tested: docker stop in 0.3s; killing guacd or rustguac now stops the container. (cherry picked from commit 30f384e6efa92539c30e80263aa1afd1a21ae370)
63 lines
2.1 KiB
Bash
63 lines
2.1 KiB
Bash
#!/bin/bash
|
|
# Entrypoint script: starts guacd and rustguac in the background. tini (PID 1)
|
|
# passes stop signals to both. If either one exits, the other is stopped and
|
|
# the container exits with that status, so a restart policy can bring it back
|
|
# rather than leaving rustguac running without guacd.
|
|
set -e
|
|
|
|
# Copy default config on first run (if no config file is mounted/present)
|
|
CONFIG_PATH="/opt/rustguac/config.toml"
|
|
if [ ! -f "$CONFIG_PATH" ]; then
|
|
echo "No config.toml found — copying default configuration."
|
|
cp /opt/rustguac/config.toml.default "$CONFIG_PATH"
|
|
fi
|
|
|
|
# Create an admin API key on first run. rustguac decides what "first run"
|
|
# means: it opens the database named by db_path in the config and creates
|
|
# the admin only if there is none yet. Checking for a database file at a fixed
|
|
# path here broke any config that moved db_path: every restart then tried to
|
|
# create the admin again and failed on the existing one (#240).
|
|
ADMIN_OUT=$(/opt/rustguac/bin/rustguac --config "$CONFIG_PATH" add-admin --name docker-admin --if-none)
|
|
echo "$ADMIN_OUT"
|
|
case "$ADMIN_OUT" in
|
|
*"API Key:"*)
|
|
echo ""
|
|
echo "==> SAVE THE API KEY ABOVE — it is only shown once! <=="
|
|
echo ""
|
|
;;
|
|
esac
|
|
|
|
# Start guacd in background
|
|
echo "Starting guacd..."
|
|
LD_LIBRARY_PATH=/opt/rustguac/lib FREERDP_ADDIN_PATH=/opt/rustguac/lib/freerdp3 \
|
|
/opt/rustguac/sbin/guacd \
|
|
-b 127.0.0.1 -l 4822 -L "${GUACD_LOG_LEVEL:-info}" -f \
|
|
-C /opt/rustguac/tls/cert.pem -K /opt/rustguac/tls/key.pem &
|
|
GUACD_PID=$!
|
|
|
|
# Wait briefly to confirm guacd started
|
|
sleep 0.5
|
|
if ! kill -0 "$GUACD_PID" 2>/dev/null; then
|
|
echo "ERROR: guacd failed to start"
|
|
exit 1
|
|
fi
|
|
echo "guacd started (pid=$GUACD_PID)"
|
|
|
|
|
|
echo "Starting rustguac..."
|
|
/opt/rustguac/bin/rustguac --config "$CONFIG_PATH" serve &
|
|
RUSTGUAC_PID=$!
|
|
|
|
# Wait for whichever exits first, then stop the other.
|
|
set +e
|
|
wait -n "$GUACD_PID" "$RUSTGUAC_PID"
|
|
STATUS=$?
|
|
if ! kill -0 "$GUACD_PID" 2>/dev/null; then
|
|
echo "guacd exited (status $STATUS), stopping rustguac"
|
|
else
|
|
echo "rustguac exited (status $STATUS), stopping guacd"
|
|
fi
|
|
kill "$GUACD_PID" "$RUSTGUAC_PID" 2>/dev/null
|
|
wait
|
|
exit "$STATUS"
|