#やりたいこと
rails5 + puma + nginxという環境でアプリケーションを動かしているのですが、ログローテーションをしてみたいと思っています。なお、railsとnginxのログはすでに以下の通りローテーション出来ています。ただpumaのログだけローテーション方法がよく分かっていません。
※puma.rbでのログ出力設定は以下の通りです。↓
stdout_redirect "/var/log/puma/puma.stdout.log", "/var/log/puma/puma.stderr.log", true
#####nginxのログローテーション設定
↓/etc/logrotate.d/nginx↓
/var/log/nginx/*log { create 0664 nginx root daily rotate 10 missingok notifempty compress sharedscripts postrotate /etc/init.d/nginx reopen_logs endscript }
→これでローテーション出来ています。
#####Railsのログローテーション設定
↓production.rb↓
config.logger = Logger.new("log/production.log", 5, 10 * 1024 * 1024)
→これでローテーション出来ています。
#pumaのlogrotate案1
以下のようにproduction.rbにLoggerを使う形で記述する。(これは何か間違っているような気がします。。)
↓production.rb↓
config.logger = Logger.new("log/production.log", 5, 10 * 1024 * 1024) config.logger = Logger.new("/var/log/puma/puma.stdout.log", 5, 10 * 1024 * 1024) config.logger = Logger.new("/var/log/puma/puma.stderr.log", 5, 10 * 1024 * 1024)
#pumaのlogrotate案2
前述のnginxのように、/etc/logrotate.dにpuma用ファイルを追加してローテーションする。
ただ、この場合、どのように設定して良いのか分かりません。。。
↓以下のような感じでしょうか??
/var/log/puma/*log { create 0666 root root daily rotate 7 missingok dateext compress notifempty sharedscripts postrotate [ -e /tmp/pids/puma.pid ] && kill -HUP `cat /tmp/pids/puma.pid` && kill -USR1 `cat /tmp/pids/puma.pid` endscript }
一応、以下のリンクで近しいようなものは確認できたのですが。。。
logrotate-puma-rails
unicornのroglorate説明
#お願い
もしpumaのログローテーション方法がわかる方がいれば教えて頂けると嬉しいです。
#追記
回答頂いた内容を踏まえ以下の通り実装し、24時間が経過し日付が変わったので、ローテーションされているか確認しました。
/etc/logrotate.d/puma
の実装内容
/var/log/puma/*log { daily missingok rotate 5 ifempty copytruncate compress delaycompress create 0644 root root su root root }
結果としてはローテーションされていませんでした。。ファイルはアクセスログとエラーログがそれぞれ一つある状態のままです。
➜ puma pwd /var/log/puma ➜ puma ls puma.stderr.log puma.stdout.log ➜ puma ls -l 合計 452 -rw-r--r-- 1 root root 222256 4月 19 03:22 puma.stderr.log -rw-r--r-- 1 root root 228936 4月 19 04:20 puma.stdout.log
以下の通り、ステータスを確認すると、puma.stdout.logとpuma.stderr.logは4/19になっています。実装したのは4/18なので、ローテーションされている??ということでしょうか?
➜ /etc cat /var/lib/logrotate.status logrotate state -- version 2 "/var/log/nginx/error.log" 2019-4-19 "/var/log/yum.log" 2019-4-18 "/var/log/redis/redis.log" 2019-4-14 "/var/log/dracut.log" 2017-3-24 "/var/log/puma/puma.stdout.log" 2019-4-19 "/var/lib/mysql/mysqld.log" 2017-3-25 "/var/log/monit" 2019-4-19 "/var/log/wtmp" 2017-3-24 "/var/log/spooler" 2019-4-14 "/var/log/puma/puma.stderr.log" 2019-4-19 "/var/log/btmp" 2019-4-1 "/var/log/maillog" 2019-4-14 "/var/log/secure" 2019-4-14 "/var/log/nginx/access.log" 2019-4-19 "/var/log/messages" 2019-4-14 "/var/account/pacct" 2017-3-24 "/var/log/cron" 2019-4-14
参考までに/etc/logrotate.conf
は以下の通りです。
➜ sudo cat /etc/logrotate.conf # see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # use date as a suffix of the rotated file dateext # uncomment this if you want your log files compressed #compress # RPM packages drop log rotation information into this directory include /etc/logrotate.d # no packages own wtmp and btmp -- we'll rotate them here /var/log/wtmp { monthly create 0664 root utmp minsize 1M rotate 1 } /var/log/btmp { missingok monthly create 0600 root utmp rotate 1 } # system-specific logs may be also be configured here.
またこの記事を参考に/usr/sbin/logrotate -dv /etc/logrotate.conf
を実行すると結果は以下の通りでした。
➜ /usr/sbin/logrotate -dv /etc/logrotate.conf reading config file /etc/logrotate.conf including /etc/logrotate.d Ignoring nginx.rpmnew, because of .rpmnew ending reading config file dracut reading config info for /var/log/dracut.log reading config file monit reading config info for /var/log/monit reading config file mysql reading config file nginx reading config info for /var/log/nginx/*log reading config file psacct reading config info for /var/account/pacct reading config file puma reading config info for /var/log/puma/*log error: puma:11 unknown option 'su' -- ignoring line error: puma:11 unexpected text reading config file redis reading config info for /var/log/redis/redis.log reading config file syslog reading config info for /var/log/cron /var/log/maillog /var/log/messages /var/log/secure /var/log/spooler reading config file yum reading config info for /var/log/yum.log reading config info for /var/log/wtmp reading config info for /var/log/btmp Handling 10 logs rotating pattern: /var/log/dracut.log 1048576 bytes (4 rotations) empty log files are not rotated, old logs are removed considering log /var/log/dracut.log log does not need rotating rotating pattern: /var/log/monit 102400 bytes (4 rotations) empty log files are not rotated, old logs are removed considering log /var/log/monit log does not need rotating not running postrotate script, since no logs were rotated rotating pattern: /var/log/nginx/*log after 1 days (52 rotations) empty log files are not rotated, old logs are removed considering log /var/log/nginx/access.log log does not need rotating considering log /var/log/nginx/error.log log does not need rotating not running postrotate script, since no logs were rotated rotating pattern: /var/account/pacct after 1 days (31 rotations) empty log files are not rotated, old logs are removed considering log /var/account/pacct log does not need rotating not running postrotate script, since no logs were rotated rotating pattern: /var/log/puma/*log after 1 days (5 rotations) empty log files are rotated, old logs are removed considering log /var/log/puma/puma.stderr.log log does not need rotating considering log /var/log/puma/puma.stdout.log log does not need rotating rotating pattern: /var/log/redis/redis.log weekly (10 rotations) empty log files are not rotated, old logs are removed considering log /var/log/redis/redis.log log does not need rotating rotating pattern: /var/log/cron /var/log/maillog /var/log/messages /var/log/secure /var/log/spooler weekly (4 rotations) empty log files are rotated, old logs are removed considering log /var/log/cron log does not need rotating considering log /var/log/maillog log does not need rotating considering log /var/log/messages log does not need rotating considering log /var/log/secure log does not need rotating considering log /var/log/spooler log does not need rotating not running postrotate script, since no logs were rotated rotating pattern: /var/log/yum.log yearly (4 rotations) empty log files are not rotated, old logs are removed considering log /var/log/yum.log log does not need rotating rotating pattern: /var/log/wtmp monthly (1 rotations) empty log files are rotated, only log files >= 1048576 bytes are rotated, old logs are removed considering log /var/log/wtmp log does not need rotating rotating pattern: /var/log/btmp monthly (1 rotations) empty log files are rotated, old logs are removed considering log /var/log/btmp log does not need rotating
/var/log/puma
の中にあるpuma.stdout.logとpuma.stderr.logの2ファイルはローテーションされているのでしょうか?おそらくされていないと思われるのですが、何か作成したファイルに問題がありますでしょうか?

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/18 03:43
2019/04/19 04:46
2019/04/19 04:54
2019/04/19 05:06
2019/04/19 05:07
2019/04/19 05:08
2019/04/19 05:26 編集
2019/04/19 05:24
2019/04/22 01:58