How to remove Log files Openshift via CronTab?

Today when i tried to push my code, I got the “error: file write error (Disk quota exceeded)” message. I was wondering how it could happen. Then i logged in via shell and checked the disk usage, then i found that the log folder is using more than 950 MB Disk.

Found all the access/error log from the day of creation of the app in php-5.3/logs. Wondering why don’t open shift has the “Log rotation service” .

Openshift remove logs via Cronjob

Fix this problem as well, please following step by step below:

The first step using Rhc client tool to add Cron 1.4:

  1. rhc cartridge add -a $app -c cron-1.4

The second step using SSH to login to Apps, then:

  1. rhc ssh sdlksjdlskj3l4j34lj43@@xxxxxxxxxx-xxxxxx.rhcloud.com
  2. cd app-root/runtime/repo/.openshift
  3. cd cron
  4. //I want to Deadline delete logs in 30 days. You can choose one of them in folder cron.
  5. cd monthly
  6. nano rmlogs

The third step copy and paste this cronjob command line in notepad:

CronTab   
  1. cd $OPENSHIFT_LOGS_DIR
  2. find . -type f \( -name access_log-\* -or -name error_log-\* -or -name backup_logs-\* \) -mtime +30 -exec rm {} \;
  3.  
  4. # Add this to the above command to backup as a gzipped tarball: | xargs tar -czvf backup-logs-$(date +%Y%m%d).tar.gz
  5. # Add this to the above command to delete 'em: -exec rm {} \; or | xargs rm)

Dont forget chmod for this file:

  1. chmod u+x rmlogs

Test it:

  1. ./rmlogs