Files
9router_start_onboot/start-9router.sh

27 lines
749 B
Bash
Executable File

#!/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