【问题标题】:Autorotation unicorn log file自转独角兽日志文件
【发布时间】:2013-12-19 22:42:12
【问题描述】:

我在 Rails 应用程序中有独角兽配置文件​​:

config/unicorn.rb

app_name = "my_app"
root = "/home/user/my_sites/#{app_name}/current"

working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.err.log"
stdout_path "#{root}/log/unicorn.out.log"

listen "/tmp/unicorn.#{app_name}.sock"
worker_processes 2
timeout 30

before_exec do |_|
  ENV["BUNDLE_GEMFILE"] = File.join(root, 'Gemfile')
end

如何自动轮换这些日志文件?

对于 Rails 应用程序和 Rails 日志,我这样做: Rails.logger = Logger.new(Rails.root.join("log",Rails.env + ".log"), 3, 20*1024*1024)

独角兽的最佳解决方案是什么?

【问题讨论】:

    标签: ruby-on-rails unicorn


    【解决方案1】:

    /etc/logrotate.d 下创建一个名为unicorn 的文件名(或您的应用程序的名称)并添加以下行

    /var/log/unicorn/*log {
        daily
        rotate 10
        missingok
        notifempty
        compress
        sharedscripts
        postrotate
            /bin/kill -USR1 $(cat /var/log/unicorn/unicorn.pid 2>/dev/null) 2>/dev/null || :
        endscript
    }
    

    根据Unicorn's documentation

    USR1 - 重新打开 master 和所有 worker 拥有的所有日志,查看 Unicorn::Util.reopen_logs 了解什么是日志。

    所以/bin/kill -USR1 将使用来自/var/log/unicorn/unicorn.pidpid 将这个信号发送到unicorn 的进程(你可能需要根据你的更新)。

    postrotatelogrotate 的轮换结束时执行。

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-10
        • 2012-02-01
        • 1970-01-01
        • 2014-01-15
        • 2012-01-05
        • 2013-10-02
        相关资源
        最近更新 更多