As you know, the LOGs became monsters when we have been satisfied. My application dumped out 4.4GB monsters for 4 months. I need to hunt them. So I reused Chef!
Here is my Chef recipe.
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
cron "remove-log" do | |
minute "37" | |
hour "04" | |
command "sh /usr/local/app/removelog.sh" | |
end |
Here is my shell hunts monsters.
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 | |
LOG_DIR="/usr/local/app/*/logs" | |
#old log erase | |
find ${LOG_DIR} -type f -name "myAllipcation*" -mtime +31 | xargs rm -f | |
find ${LOG_DIR} -type f -name "gc.log*" -mtime +31 | xargs rm -f |
After run Chef client, you can confirm cron job is activated.
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
[root@baepiff app]# crontab -l | |
# Chef Name: as-stat-remove-log | |
37 04 * * * sh /usr/local/app/removelog.sh |
If you want to configure detail level of cron, please look around the following URL.
http://wiki.opscode.com/display/chef/Resources#Resources-Cron