mirror of
https://github.com/WSA-Installer/wsa-webdav.git
synced 2026-07-29 11:24:16 -07:00
139 lines
3.1 KiB
Bash
139 lines
3.1 KiB
Bash
#!/bin/bash
|
|||
|
|
# WSA WebDAV Server - Service Control Script
|
||
|
|
# Usage: ./wsa_webdav.sh {start|stop|restart|status|log|config|root|health|help}
|
||
|
|
|
||
|
|
APP_NAME="WSA WebDAV Server"
|
||
|
|
LOG_DIR="/data/local/tmp/wsa_webdav"
|
||
|
|
PID_FILE="$LOG_DIR/server.pid"
|
||
|
|
LOG_FILE="$LOG_DIR/server.log"
|
||
|
|
PYTHON_DIR="$(dirname "$0")/python_runtime"
|
||
|
|
PYTHON_SCRIPT="$PYTHON_DIR/main.py"
|
||
|
|
CONFIG_FILE="$(dirname "$0")/config.json"
|
||
|
|
DEFAULT_PORT=8088
|
||
|
|
|
||
|
|
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..."
|
||
|
|
mkdir -p "$LOG_DIR"
|
||
|
|
|
||
|
|
nohup python3 "$PYTHON_SCRIPT" --config "$CONFIG_FILE" --log "$LOG_FILE" > /dev/null 2>&1 &
|
||
|
|
echo $! > "$PID_FILE"
|
||
|
|
echo "$APP_NAME started (PID: $!)"
|
||
|
|
}
|
||
|
|
|
||
|
|
stop() {
|
||
|
|
if [ ! -f "$PID_FILE" ]; then
|
||
|
|
echo "$APP_NAME is not running"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
pid=$(cat "$PID_FILE")
|
||
|
|
if kill -0 "$pid" 2>/dev/null; then
|
||
|
|
echo "Stopping $APP_NAME (PID: $pid)..."
|
||
|
|
kill "$pid"
|
||
|
|
sleep 2
|
||
|
|
if kill -0 "$pid" 2>/dev/null; then
|
||
|
|
kill -9 "$pid"
|
||
|
|
fi
|
||
|
|
rm -f "$PID_FILE"
|
||
|
|
echo "$APP_NAME stopped"
|
||
|
|
else
|
||
|
|
echo "$APP_NAME is not running (stale PID file)"
|
||
|
|
rm -f "$PID_FILE"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
restart() {
|
||
|
|
stop
|
||
|
|
sleep 1
|
||
|
|
start
|
||
|
|
}
|
||
|
|
|
||
|
|
status() {
|
||
|
|
if [ -f "$PID_FILE" ]; then
|
||
|
|
pid=$(cat "$PID_FILE")
|
||
|
|
if kill -0 "$pid" 2>/dev/null; then
|
||
|
|
echo "$APP_NAME: RUNNING (PID: $pid)"
|
||
|
|
echo "Port: $DEFAULT_PORT"
|
||
|
|
echo "Log: $LOG_FILE"
|
||
|
|
else
|
||
|
|
echo "$APP_NAME: DEAD (stale PID file)"
|
||
|
|
fi
|
||
|
|
else
|
||
|
|
echo "$APP_NAME: STOPPED"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
log() {
|
||
|
|
if [ -f "$LOG_FILE" ]; then
|
||
|
|
tail -${1:-50} "$LOG_FILE"
|
||
|
|
else
|
||
|
|
echo "No log file found"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
config() {
|
||
|
|
if [ -f "$CONFIG_FILE" ]; then
|
||
|
|
cat "$CONFIG_FILE"
|
||
|
|
else
|
||
|
|
echo "No config file found"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
root() {
|
||
|
|
if su -c "id" 2>/dev/null | grep -q "uid=0"; then
|
||
|
|
echo "Root: AVAILABLE"
|
||
|
|
else
|
||
|
|
echo "Root: NOT AVAILABLE"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
health() {
|
||
|
|
if [ -f "$PID_FILE" ]; then
|
||
|
|
pid=$(cat "$PID_FILE")
|
||
|
|
if kill -0 "$pid" 2>/dev/null; then
|
||
|
|
echo "Health: OK"
|
||
|
|
else
|
||
|
|
echo "Health: PROCESS DEAD"
|
||
|
|
fi
|
||
|
|
else
|
||
|
|
echo "Health: NOT RUNNING"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
help() {
|
||
|
|
echo "$APP_NAME - Control Script"
|
||
|
|
echo ""
|
||
|
|
echo "Usage: $0 {start|stop|restart|status|log|config|root|health|help}"
|
||
|
|
echo ""
|
||
|
|
echo "Commands:"
|
||
|
|
echo " start Start the server"
|
||
|
|
echo " stop Stop the server"
|
||
|
|
echo " restart Restart the server"
|
||
|
|
echo " status Show server status"
|
||
|
|
echo " log [N] Show last N lines of log (default: 50)"
|
||
|
|
echo " config Show configuration"
|
||
|
|
echo " root Check root access"
|
||
|
|
echo " health Check server health"
|
||
|
|
echo " help Show this help"
|
||
|
|
}
|
||
|
|
|
||
|
|
case "$1" in
|
||
|
|
start) start ;;
|
||
|
|
stop) stop ;;
|
||
|
|
restart) restart ;;
|
||
|
|
status) status ;;
|
||
|
|
log) log "$2" ;;
|
||
|
|
config) config ;;
|
||
|
|
root) root ;;
|
||
|
|
health) health ;;
|
||
|
|
help|*) help ;;
|
||
|
|
esac
|