100 lines
2.0 KiB
Bash
Executable File
100 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
APP_NAME="frame_exporter"
|
|
APP_PATH="/usr/bin/t3hs/t3hs_frame_exporter"
|
|
APP_ARGS=""
|
|
PID_FILE="/var/run/t3hs/${APP_NAME}.pid"
|
|
ENABLED_FILE="/etc/t3hs/${APP_NAME}/enabled"
|
|
|
|
RUN_AS="root"
|
|
RESPAWN_DELAY=1
|
|
|
|
is_enabled() {
|
|
[ -f "$ENABLED_FILE" ] && return 0 || return 1
|
|
}
|
|
|
|
start() {
|
|
if [ -f "$PID_FILE" ]; then
|
|
pid=$(cat "$PID_FILE")
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
echo "$APP_NAME is already running (pid $pid)"
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
echo "Starting $APP_NAME..."
|
|
|
|
if is_enabled; then
|
|
while is_enabled; do
|
|
start-stop-daemon -S -b -m -p "$PID_FILE" -c "$RUN_AS" -x "$APP_PATH" -- $APP_ARGS >> /dev/null 2>&1
|
|
sleep "$RESPAWN_DELAY"
|
|
done &
|
|
else
|
|
start-stop-daemon -S -b -m -p "$PID_FILE" -c "$RUN_AS" -x "$APP_PATH" -- $APP_ARGS >> /dev/null 2>&1
|
|
fi
|
|
}
|
|
|
|
stop() {
|
|
echo "Stopping $APP_NAME..."
|
|
start-stop-daemon -K -p "$PID_FILE"
|
|
rm -f "$PID_FILE"
|
|
}
|
|
|
|
status() {
|
|
if [ -f "$PID_FILE" ]; then
|
|
pid=$(cat "$PID_FILE")
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
echo "$APP_NAME is running (pid $pid)"
|
|
return 0
|
|
else
|
|
echo "$APP_NAME pid file exists but process is not running"
|
|
return 1
|
|
fi
|
|
else
|
|
echo "$APP_NAME is not running"
|
|
return 3
|
|
fi
|
|
}
|
|
|
|
enable() {
|
|
touch "$ENABLED_FILE"
|
|
echo "Enabled $APP_NAME to start at boot"
|
|
}
|
|
|
|
disable() {
|
|
rm -f "$ENABLED_FILE"
|
|
echo "Disabled $APP_NAME from starting at boot"
|
|
}
|
|
|
|
mkdir -p $(dirname "$PID_FILE")
|
|
mkdir -p $(dirname "$ENABLED_FILE")
|
|
|
|
case "$1" in
|
|
start)
|
|
start
|
|
;;
|
|
stop)
|
|
stop
|
|
;;
|
|
restart)
|
|
stop
|
|
sleep 1
|
|
start
|
|
;;
|
|
status)
|
|
status
|
|
;;
|
|
enable)
|
|
enable
|
|
;;
|
|
disable)
|
|
disable
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|restart|status|enable|disable}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0
|