diff --git a/Dockerfile b/Dockerfile index d589e8f..77bd74c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,6 @@ RUN apt-get update && apt-get install -y wget ENV MAX_LOGS="20" ENV LOG_DIR="/var/log/glassminers" ENV LOG_DATE_FORMAT="%Y-%m-%d-%H-%M-%S" -ENV WATCHDOG_ENABLED="false" RUN mkdir -p ${LOG_DIR} diff --git a/docker-compose.yaml b/docker-compose.yaml index 7947ffb..f608df5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,7 +9,6 @@ services: - MAX_LOGS=20 # - LOG_DIR="/var/log/glassminers" # - LOG_DATE_FORMAT="%Y-%m-%d-%H-%M-%S" # No spaces - # - WATCHDOG_ENABLED="false" # Use docker restart behavior instead of internal watchdog volumes: - ./logs:/var/log/glassminers ports: diff --git a/scripts/server_script.sh b/scripts/server_script.sh index 8f5d69d..224eb17 100644 --- a/scripts/server_script.sh +++ b/scripts/server_script.sh @@ -3,10 +3,9 @@ MAX_LOGS=${MAX_LOGS:-20} LOG_DIR=${LOG_DIR:-"/var/log/glassminers"} LOG_DATE_FORMAT=${LOG_DATE_FORMAT:-"%Y-%m-%d-%H-%M-%S"} -WATCHDOG_ENABLED=${WATCHDOG_ENABLED:-false} -MAX_RETRIES=${MAX_RETRIES:-10} -mkdir -p "$LOG_DIR" +EXEC=./server.out +TIMESTAMP=$(date +"$LOG_DATE_FORMAT") delete_old_logs() { if [ -d "$LOG_DIR" ]; then @@ -37,44 +36,17 @@ clean_up() { delete_old_logs } -trap 'clean_up; shutdown_requested=true; kill -TERM $SERVER_PID' SIGTERM SIGINT +trap 'clean_up; exit 0' SIGTERM echo "[Info] Max number of logs set to $MAX_LOGS" -echo "[Info] Watchdog enabled: $WATCHDOG_ENABLED" -echo "[Info] Max retries: $MAX_RETRIES" +echo "[Info] Server is starting at [$TIMESTAMP]" +$EXEC >"$LOG_DIR/latest.log" & +SERVER_PID=$! -shutdown_requested=false -retry_count=0 -while true; do - TIMESTAMP=$(date +"$LOG_DATE_FORMAT") - echo "[Info] Server is starting at [$TIMESTAMP]" - - $EXEC >"$LOG_DIR/latest.log" 2>&1 & - SERVER_PID=$! - - wait $SERVER_PID - EXIT_STATUS=$? - - echo "[Info] Server stopped at [$(date +"$LOG_DATE_FORMAT")] with exit code: $EXIT_STATUS" - - if [ "$shutdown_requested" = true ] || [ $EXIT_STATUS -eq 0 ]; then - break - fi - - if [ "$WATCHDOG_ENABLED" = true ]; then - if [ $retry_count -lt $MAX_RETRIES ]; then - retry_count=$((retry_count + 1)) - clean_up - echo "[Warning] Watchdog restarting server after crash (attempt $retry_count/$MAX_RETRIES)" - sleep 5 - else - echo "[Error] Max retries reached ($MAX_RETRIES). Watchdog stopping." - break - fi - else - break - fi -done +wait $SERVER_PID +EXIT_STATUS=$? clean_up -echo "[Info] Watchdog script exiting" + +echo "[Info] Server stopped at [$(date +"$LOG_DATE_FORMAT")] with exit code: $EXIT_STATUS" +sleep 5