Question

It is possible to do logrotate without restarting nginx (just send USR1 signal to nginx it will do the job). I wonder it is possible for my rails app (nginx passenger). It's not worth to restart my rails apps just to do a logrotate.

Was it helpful?

Solution

If you are talking about rails application log rotation, you can do that by putting

 config.logger = Logger.new(config.log_path, 10, 1024**2)

in your environment file. The 2nd argument is the number of .log files you’d like to keep, and the 3rd being the size in bytes that the files are allowed to reach before they’ll be rotated. This configuration means 10 files of 1 megabyte. May not be quite as configurable as logrotate perhaps (no support for compression etc.), but it lets you keep all your log files within your app. This usually works for me.

Also found this if want to stick to log rotation via nginx.

OTHER TIPS

logrotate configuration is pretty simple to get this down

/path/to/rails_apps/*/shared/log/*.log {
  daily
  missingok
  rotate 30
  compress
  delaycompress
  copytruncate
}

the copytruncate basically copies the content to new file and truncates the old file. this eliminates the need for restart.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top