Skip to content

Instantly share code, notes, and snippets.

@nikushi
Last active August 29, 2015 13:59
Show Gist options
  • Save nikushi/10572535 to your computer and use it in GitHub Desktop.
Save nikushi/10572535 to your computer and use it in GitHub Desktop.

bin/yohoushiからunicorn, serverengineを起動する直前まで

bin/yohoushi
 |
 v
lib/yohoushi/cli.rb

   options[:config]    = File.expand_path('config/yohoushi.god', ENV['RAILS_ROOT']) # yohoushi custom
   require File.expand_path('vendor/extensions/god/cli/run', ENV['RAILS_ROOT']) # yohoushi custom
   options = {
     daemonize: false,
     port: 17165,
     syslog: true,
     events: true,
     config: "config/yohoushi.god",
   }
   God::CLI::Run.new(options)
     #dispatch
     #run_in_front
     #default_run
     #load_config
     #load_god_file('config/yohoushi.god')
        load 'config/yohoushi.god'

 |
 v

config/yohoushi.god
  God.load "config/unicorn.god"        https://github.com/mojombo/god/blob/master/lib/god.rb#L641
    Kernel.load 'config/unicorn.god'   https://github.com/mojombo/god/blob/master/lib/god.rb#L643
  God.load "serverengine.god"          
     Kernel.load 'config/serverengine.god' 

config/unicorn.god

config/unicorn.god
    God.watch           # God配下へ登録され起動される
       w.start = "cd #{RAILS_ROOT} && RAILS_ENV=#{RAILS_ENV} #{BIN_PATH}/unicorn -c #{RAILS_ROOT}/config/unicorn.conf -E #{RAILS_ENV} -D"

config/serverengine.god

config/serverengine.god
    God.watch
        w.start   = "cd #{RAILS_ROOT} && RAILS_ENV=#{RAILS_ENV} #{BIN_PATH}/serverengine start -p #{PID_DIR}/serverengine.pid -d"

serverengineの起動シーケンス

bin/serverengine start -p tmp/serverengine.pid -d
 |
 v
lib/serverengine/cli.rb
    ServerEngine::CLI.start(ARGV)
    
    ServerEngine::CLI#initialize
      @options = {
        "config" => 'config/serverengine.conf',
        "daemonize" => true,
        "module_name" => "Worker",
        "interval" => 60,
        ...# see all params in config/serverengine.conf
      }
    ServerEngine::CLI#start
      load_enviroment(nil)  # load rails
      opts = {
        daemonize: true,
        interval: 60,
        }
      ServerEngine.create(nil, Worker, opts).run
 |
 v
app/worker/worker.rb
  #initialize
    @processor = Processor.new(logger, {daemonize:true, interval: 60})
  #reload
  #run
    @processor.process
 |
 v
app/woroker/processor.rb
  #initialize
    @config = {daemonize:true, interval: 60}
  #process
    ### 実際の処理
      - GFからグラフを取得
      - YohoushiのDBにグラフパス格納

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment