Skip to content

Instantly share code, notes, and snippets.

Created April 5, 2023 14:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A simple daemon script that I used for debugging running Docker containers in AWS ECS.


{"name": "worker", "level": "INFO", "message": "Service start", "timestamp": "2023-04-05 14:04:48.974687279", "ip": "", "pid": 7}
{"name": "worker", "level": "INFO", "message": "ping", "timestamp": "2023-04-05 14:04:48.975945036", "ip": "", "pid": 7}
{"name": "worker", "level": "INFO", "message": "Received signal: SIGTERM", "timestamp": "2023-04-05 14:04:53.979013322", "ip": "", "pid": 7}
{"name": "worker", "level": "INFO", "message": "Stopping", "timestamp": "2023-04-05 14:04:53.980930837", "ip": "", "pid": 7}
#!/usr/bin/env bash
set -e
IP=$(hostname -I | awk '{print $1}')
print_log() {
printf \
'{"name": "worker", "level": "%s", "message": "%s", "timestamp": "%s", "ip": "%s", "pid": %d}\n' \
"$1" "$2" \
"$(date "+%Y-%m-%d %H:%M:%S.%N")" \
"${IP}" \
trap 'print_log "INFO" "Received signal: $1" && print_log "INFO" "Stopping"; exit' SIGINT SIGTERM
print_log "INFO" "Service start"
while true; do
print_log "INFO" "ping"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment