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.
Asked
Active
Viewed 4,595 times
2 Answers
28
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.

Addy
- 1,817
- 2
- 18
- 23
-
I wonder why there is no postrotate script to tell. Any problems with this? – Chamnap May 04 '11 at 03:44
-
I have my production servers with this configuration.. and everything's working perfectly. – Addy May 07 '11 at 04:21
-
thank you guys, if you need to specify the size of log file use `size 100M` – Ilja Sep 09 '16 at 16:25
3
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.

Chirantan
- 15,304
- 8
- 49
- 75
-
1
-
1I have personally found the rails log rotation to be hit or miss. sometimes the rails logger gets stuck on logging to old files after rotation. – Addy Apr 12 '11 at 03:44
-
3Be careful with this... if you are running more than one instance of Rails through Passenger (ie. PassengerMinInstances), and you also have something like PassengerMaxRequests set in your Passenger config, then be aware that each new spawn of a Rails process will create a new file. We had our setup like this: "config.logger = Logger.new(config.log_path, 14, 200000000)" and it only ever kept 1 day's worth of logs, since 14 instances would spin up and down throughout the day based on load, creating a new file each time. They hardly ever hit the max size of 200000000. Go with syslog. – Harmon Apr 25 '12 at 23:56
-
Please mark Addy's answer as the right one. His answer is better than the one I posted. – Chirantan Feb 16 '16 at 10:13