Add 9router start-on-boot setup (non-root, @reboot cron, no systemd)

This commit is contained in:
cania
2026-08-11 11:30:57 +02:00
commit 40ec0c8506
4 changed files with 203 additions and 0 deletions

26
start-9router.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/sh
# Start 9router detached at boot.
# Runs as the current user; if that's root, drop privileges to 'ardhi'.
# Uses absolute paths (cron @reboot has a minimal PATH).
SETSID=/usr/bin/setsid
RUNUSER=/usr/sbin/runuser
BIN=/usr/local/bin/9router
LOG=/home/ardhi/9router.log
touch /tmp/9router-cron-ran 2>/dev/null
if [ ! -x "$BIN" ]; then
exit 0
fi
if [ "$(id -u)" = "0" ]; then
# Running as root (e.g. root's @reboot cron): drop to ardhi.
"$SETSID" "$RUNUSER" -u ardhi -- sh -c \
"exec '$BIN' -t -n --host 127.0.0.1 --port 20128 >> '$LOG' 2>&1 < /dev/null" &
else
# Already running as ardhi: start directly.
"$SETSID" "$BIN" -t -n --host 127.0.0.1 --port 20128 >> "$LOG" 2>&1 < /dev/null &
fi
disown 2>/dev/null || true
exit 0