Files
P42_godDaemons/Observer/startObserver.sh
T

46 lines
890 B
Bash
Executable File

#!/bin/sh
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# shellcheck source=../lib/resolveConfigPath.sh
. "$SCRIPT_DIR/../lib/resolveConfigPath.sh"
CONFIG="$(resolveConfigPath "$SCRIPT_DIR" "${1:-${CONFIG:-../config.json}}")"
set -a
. /etc/p42/secrets.env
set +a
daemon=p42Observer
logfile=observer.log
if [ ! -f "$CONFIG" ]; then
echo "Config file not found: $CONFIG" >&2
exit 1
fi
pid=$(pgrep -f "$daemon")
if [ -z "$pid" ]
then
node "${daemon}.js" --config "$CONFIG" --debug > "$logfile" 2>&1 &
pid=$!
sleep 1
if kill -0 "$pid" 2>/dev/null
then
echo ""
echo "$daemon is now running with PID=$pid (config=$CONFIG)"
echo ""
else
echo ""
echo "Failed to start $daemon. Check observer.log"
echo ""
exit 1
fi
else
echo ""
echo "$daemon is already running with PID=$pid"
echo ""
fi