Files
claude-code-screenshots/server.sh
2026-04-13 09:11:52 +00:00

79 lines
1.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
APP_CMD="node $SCRIPT_DIR/server.mjs"
PID_FILE="/tmp/server_mjs.pid"
start() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p $PID > /dev/null 2>&1; then
echo "Service läuft bereits (PID: $PID)"
exit 1
else
echo "Alte PID-Datei gefunden, wird entfernt"
rm -f "$PID_FILE"
fi
fi
echo "Starte Service..."
nohup $APP_CMD > /tmp/server_mjs.log 2>&1 &
echo $! > "$PID_FILE"
echo "Gestartet mit PID $(cat $PID_FILE)"
}
stop() {
if [ ! -f "$PID_FILE" ]; then
echo "Keine PID-Datei gefunden läuft der Service?"
exit 1
fi
PID=$(cat "$PID_FILE")
if ps -p $PID > /dev/null 2>&1; then
echo "Stoppe Service (PID: $PID)..."
kill $PID
rm -f "$PID_FILE"
echo "Gestoppt"
else
echo "Prozess läuft nicht mehr, entferne PID-Datei"
rm -f "$PID_FILE"
fi
}
status() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p $PID > /dev/null 2>&1; then
echo "Service läuft (PID: $PID)"
else
echo "PID-Datei vorhanden, aber Prozess läuft nicht"
exit 1
fi
else
echo "Service gestoppt"
exit 3
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac