Skip to content

Commit

Permalink
fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrisae9 committed Sep 26, 2024
1 parent 80743ea commit 0079338
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
6 changes: 3 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 &
Expand Down
29 changes: 24 additions & 5 deletions scripts/shutdown-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"

0 comments on commit 0079338

Please sign in to comment.