2

I have a multi-threaded rails application, and it has many workers, which pull messages from resque queue and log messages. I have put linux logrotate to rotate the log and and then upload to S3.

After uploading and deleting a file, I see that the disk space is still used, and is not released. When I execute the command below, I see lots of files.

lsof | grep deleted
ruby      14530           fadmin    7w      REG              202,1 1972144092  407325 /home/log/production_database.log.1 (deleted)
ruby-time 14536 20352     fadmin    7w      REG              202,1 1972144092  407325 /home/log/production_database.log.1 (deleted)

It fills the disk space every time. It releases space only if I kill all Ruby processes.

Can I know what the best way is to rotate logs, and how I should avoid the problem?

2 Answers 2

2

finally below option work with logrotate .. without the need to kill or restart the ruby process

/home/log/*.log {
    maxsize 1M
    missingok
    rotate 20
    notifempty
    nocreate
    copytruncate
    su root root
}

Major parameters which resolve my problem is

copytruncate – Copy the log file and then empties it. This makes sure that the log file Rails is writing to always exists so you won’t get problems because the file does not actually change. If you don’t use this, you would need to restart your Rails application each time.

0

Theres a solution from here http://www.akitaonrails.com/2013/06/28/if-rotacao-de-logs-em-apps-rails#.UdTZ4T7wKeI that uses the logger config to rotate the files, example:

config.logger = Logger.new(Rails.root.join("log",Rails.env + ".log"), 5, 100*1024*1024)

Not the answer you're looking for? Browse other questions tagged or ask your own question.