【问题标题】:Use God with multiple applications and start them automatically after a reboot将 God 与多个应用程序一起使用,并在重新启动后自动启动它们
【发布时间】:2012-07-15 16:07:17
【问题描述】:

我目前正在尝试使用 god 监控总共三个 Rails/Rack 应用程序的各种进程/守护程序。监控效果很好,问题是我无法配置上帝在重启后自动启动所有进程。

我的设置:我正在使用 Centos 和 Plesk 运行 Linux VPS。 我有一个非 root linux 用户“deployer”,用于部署和运行三个 Rails/Rack 应用程序。两个应用程序正在使用乘客 apache 模块运行,第三个应用程序使用瘦服务器(这是必要的,因为该应用程序不能与 apache 一起使用)。使用乘客的两个 Rails 应用程序有额外的 rake 任务在后台运行 - 这些和瘦服务器由上帝监控。

神宝石在所有三个应用程序的宝石文件中指定。

在每个 deploy.rb 文件中,我都有一个看起来像这样的方法

namespace :misc do
    desc "restart woekers using gog; restart webserver"
    task :restart, roles: [:web, :resque] do
        run "touch #{current_path}/tmp/restart.txt"
        god.all.start
        god.all.reload
        god.all.terminate
        god.all.start
    end
end

重新启动服务器后,如果我手动为所有三个应用程序运行 cap misc:restart,所有进程都会启动并正确监控。

到目前为止,每次尝试在启动时自动启动 God 并启动所有必要的进程都失败了。 我尝试了很多不同的东西,但没有任何效果。到目前为止,我的方法是使用 @reboot 创建一个运行以下三个脚本的 cron 任务:

#!/bin/bash -l

cd /path/to/app/ && bundle exec god -c /path/to/app/config/god/resque.god && bundle exec god load /path/to/app/config/god/resque.god && bundle exec god start resque

这对第一个应用程序非常有用:上帝和所有进程都已启动。 当为第二个应用程序执行脚本时(当然使用正确的路径),上帝无法启动任务。 我启用了登录上帝,错误消息(在机架应用程序的情况下)是“瘦:找不到命令”。 当我先启动 Rack Application 时,thin 正确启动,没有找到其他任务的命令。

我不明白我的配置有什么问题。如上所示,我在上帝调用前添加了 bundle exec 命令(因此这些命令应该在其各自应用程序的环境中执行) - 然而,它只是不起作用。

如果有人能帮助我让上帝自动启动,我将不胜感激。

如果您需要更多信息,请随时询问!

提前致谢!

【问题讨论】:

    标签: ruby gem centos god process-monitoring


    【解决方案1】:

    我正在做类似的事情并采取了这种方法:

    使用 upstart 或类似的东西在系统启动时启动上帝守护进程,对我来说是这样完成的:

    /etc/init/god.conf

    description "god"
    
    start on runlevel [2]
    stop on runlevel [016]
    
    console owner
    
    exec /usr/local/rvm/bin/rvm_god -c /etc/god
    
    respawn
    

    那家伙用 -c 选项指定 one ruby​​ god 配置文件运行神:

    /etc/god

    # Load the configs
    
    God.load "/home/dangerousbeans/kitten_smusher/config/config.god"
    God.load "/home/dangerousbeans/irc_nommer/config/config.god"
    

    这个 ruby​​ dude 加载到单个应用程序 God 配置中,运行 God.load 会导致它们启动。

    当我使用 RVM 时,我猜单个文件看起来像这样: /home/dangerousbeans/irc_nommer/config/config.god

    God.watch do |w|
      w.dir = "/home/dangerousbeans/irc_nommer"
      w.name = "IRCnommer"
    
      # scary rvm magic begins
      gemsets_path = [
            "/home/dangerousbeans/.rvm/gems/ruby-1.9.3-p125@irc_nommer/bin",
            "/home/dangerousbeans/.rvm/rubies/ruby-1.9.3-p125/bin",
        "/home/dangerousbeans/.rvm/bin",
          ENV['PATH'] # inherit this
        ].join(':')
    
       w.env      = {
        "PATH"        => gemsets_path,
            "GEM_PATH"    => "/home/dangerousbeans/.rvm/gems/ruby-1.9.3-p125@irc_nommer"
        }
      # scary rvm magic ends
    
      w.log = "/tmp/ircnommer.log"
    
      w.start = "ruby /home/dangerousbeans/irc_nommer/irc_nommer.rb"
      w.keepalive
    end
    

    【讨论】:

      【解决方案2】:

      关键是手动和自动的环境不同,而上帝执行[start]命令。 所以你可以在命令中添加命令env。喜欢:

      God.watch do |w|
        w.start    = "cd #{your_app_directory}; env >> log/god.log; your-real-command >> log/god.log 2>&1"
      end
      

      在同一目录中键入env 时会有所不同。 检查差异并将所需/正确的段落添加到上帝的环境中。

      今天遇到一个问题,我在 1 台服务器上部署了 2 个 rails 应用程序,都使用了上帝。 App#2 无法正确启动命令。经过上述测试,我找到了原因:上帝保存了一个指向 App#1 的环境变量 [BUNDLE_GEMFILE]。所以我添加了一个简单的行然后错误消失了:

      God.watch do |w|
        w.env = {
          "BUNDLE_GEMFILE" => "#{$rails_root}/Gemfile"
        }
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多