@@ -9,41 +9,45 @@ ROTATED_LOG_FILE="$LOG_PATH.1"
99if [ -f " $ROTATED_LOG_FILE " ]; then
1010 echo " Log rotation successful. Processing the rotated log file."
1111
12+ # Find the PID of the traefik process
13+ TRAEFIK_PID=$( pgrep traefik)
14+
15+ # Check if the PID was found
16+ if [ -n " $TRAEFIK_PID " ]; then
17+ # Send USR1 signal to the traefik process
18+ kill -USR1 " $TRAEFIK_PID "
19+ echo " Sent USR1 signal to traefik process with PID $TRAEFIK_PID "
20+ else
21+ echo " Traefik process not found."
22+ fi
23+
24+ # Make sure traefik has time to reopen the log file before we try to compress it
25+ sleep 10
26+
27+ # Get the uploaded log file name
28+ TIMESTAMP=$( date +" %Y%m%dT%H00Z" ) # Cron runs on the hour, so we round to the hour
29+ HASH_SUFFIX=$( cksum " $ROTATED_LOG_FILE " | cut -d ' ' -f 1 | cut -c1-8)
30+ S3_KEY=" ${TIMESTAMP} _HASH${HASH_SUFFIX} _access.log.gz"
31+
1232 # Compress the rotated log before upload
13- COMPRESSED_LOG_FILE=" ${ROTATED_LOG_FILE} .gz"
14- if ! gzip -c " $ROTATED_LOG_FILE " > " $COMPRESSED_LOG_FILE " ; then
33+ if ! gzip -c " $ROTATED_LOG_FILE " > " $S3_KEY " ; then
1534 echo " Failed to compress rotated log file."
1635 exit 1
1736 fi
1837
1938 # Upload the compressed log file to S3
20- TIMESTAMP=$( date +" %Y%m%dT%H00Z" ) # Cron runs on the hour, so we round to the hour
21- HASH_SUFFIX=$( cksum " $COMPRESSED_LOG_FILE " | cut -d ' ' -f 1 | cut -c1-8)
22- S3_KEY=" ${TIMESTAMP} _HASH${HASH_SUFFIX} _access.log.gz"
23- echo " Uploading $COMPRESSED_LOG_FILE to s3://$S3_BUCKET /$S3_KEY ..."
39+ echo " Uploading $S3_KEY to s3://$S3_BUCKET /$S3_KEY ..."
2440
25- aws s3 cp " $COMPRESSED_LOG_FILE " " s3://$S3_BUCKET /$S3_KEY "
41+ /usr/local/bin/ aws s3 cp " $S3_KEY " " s3://$S3_BUCKET /$S3_KEY "
2642
2743 if [ $? -ne 0 ]; then
2844 echo " Failed to upload log file to S3."
2945 exit 1
3046 fi
31- echo " Upload to S3 successful."
32-
33- rm -f " $COMPRESSED_LOG_FILE "
3447
35- # Find the PID of the traefik process
36- TRAEFIK_PID=$( pgrep traefik)
48+ rm -f " $S3_KEY "
3749
38- # Check if the PID was found
39- if [ -n " $TRAEFIK_PID " ]; then
40- # Send USR1 signal to the traefik process
41- kill -USR1 " $TRAEFIK_PID "
42- echo " Sent USR1 signal to traefik process with PID $TRAEFIK_PID "
43- else
44- echo " Traefik process not found."
45- exit 1
46- fi
50+ echo " Upload to S3 successful."
4751else
4852 echo " Rotated log file not found."
4953 exit 1
0 commit comments