diff --git a/entrypoint.sh b/entrypoint.sh index 4c3690d..7b1a11c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -36,7 +36,7 @@ if [ "$SHUTDOWN_ENABLED" = "true" ]; then # Cron jobs # Shutdown services at specified time -$SHUTDOWN_TIME node /usr/local/bin/shutdown-services.sh +$SHUTDOWN_TIME /usr/local/bin/shutdown-services.sh >> /var/log/cron/cron.log 2>&1 EOF # Ensure the crontab file has correct ownership and permissions @@ -49,8 +49,8 @@ EOF chown root:root /var/log/cron/cron.log chmod 644 /var/log/cron/cron.log - # Start the cron daemon with enhanced logging - crond -b -l 8 -L /var/log/cron/cron.log + # Start the cron daemon with adjusted logging level to suppress unwanted messages + crond -b -l 6 -L /var/log/cron/cron.log # Tail the cron log to stdout so it appears in Docker logs tail -F /var/log/cron/cron.log & diff --git a/scripts/shutdown-services.sh b/scripts/shutdown-services.sh index cd85e03..90d055b 100755 --- a/scripts/shutdown-services.sh +++ b/scripts/shutdown-services.sh @@ -3,9 +3,20 @@ # Path to the services.json file servicesFile="/app/src/data/services.json" +# Log file path +logFile="/var/log/cron/cron.log" + +# Log function to include timestamps +log() { + echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$logFile" +} + +# Start logging +log "shutdown-services.sh started" + # Check if the services.json file exists if [ ! -f "$servicesFile" ]; then - echo "Error: services.json file not found at $servicesFile." + log "Error: services.json file not found at $servicesFile." exit 1 fi @@ -17,12 +28,20 @@ jq -c '.[]' "$servicesFile" | while read -r service; do # Check if the compose file is not null or empty if [ "$composeFile" != "null" ] && [ -n "$composeFile" ]; then - echo "Running docker-compose down for $composeFile in $servicePath" + log "Running docker-compose down for $composeFile in $servicePath" # Navigate to the service path and run docker-compose down - (cd "$servicePath" && docker-compose -f "$composeFile" down) + ( + cd "$servicePath" && docker-compose -f "$composeFile" down >> "$logFile" 2>&1 + if [ $? -eq 0 ]; then + log "Successfully stopped service at $servicePath" + else + log "Error stopping service at $servicePath" + fi + ) else - echo "Compose file not specified for a service. Skipping." + log "Compose file not specified for a service at $servicePath. Skipping." fi done -echo "All services have been processed." +log "All services have been processed." +log "shutdown-services.sh completed"