#!/bin/sh # Garmin Health Lab — DSM boot script. # Mirrors the convention already used by S99frpc.sh on this NAS. APP=/volume1/web/garmin-health-lab RUNAS=ericwyuan # Kept inside the app dir, not /var/run: the service runs as an unprivileged # user, which cannot write there. PIDFILE="$APP/app.pid" start() { if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then echo "already running (pid $(cat "$PIDFILE"))" return 0 fi # Runs as the owning user: the service needs nothing privileged and its # .env holds database and API credentials. # setsid + closed stdio so it survives the invoking shell and never holds # an SSH session open. if [ "$(id -un)" = "$RUNAS" ]; then sh "$APP/deploy/start.sh" >/dev/null 2>&1 /dev/null 2>&1 /dev/null))" } stop() { [ -f "$PIDFILE" ] && kill "$(cat "$PIDFILE")" 2>/dev/null rm -f "$PIDFILE" pkill -f "gunicorn.*8124" 2>/dev/null echo "stopped" } case "$1" in start) start ;; stop) stop ;; restart) stop; sleep 2; start ;; status) if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then echo "running (pid $(cat "$PIDFILE"))" else echo "not running" fi ;; *) echo "Usage: $0 {start|stop|restart|status}" ;; esac