Created
November 16, 2011 16:21
-
-
Save rrrodrigo/1370523 to your computer and use it in GitHub Desktop.
Rotation of Nginx logs with a twist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
YEAR=`date "+%Y"` | |
MONTH=`date "+%m"` | |
DAY=`date "+%d"` | |
LOG_FILES="access.log error.log" | |
DATE=$YEAR/$MONTH/$DAY | |
NGINX_LOG_ROOT=/var/log/nginx | |
# make path | |
mkdir -p $NGINX_LOG_ROOT/$DATE | |
# touch and symlink in new log files | |
for FILE in $LOG_FILES; do | |
LOG_FILE=$NGINX_LOG_ROOT/$DATE/$FILE | |
touch $LOG_FILE | |
ln -fs $LOG_FILE $NGINX_LOG_ROOT/$FILE | |
done | |
# tell nginx to re-open its log files | |
kill -USR1 `cat /var/run/nginx.pid` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment