Method: God::CLI::Command#check_command

Defined in:
lib/god/cli/command.rb

#check_commandObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/god/cli/command.rb', line 160

def check_command
  Thread.new do
    begin
      event_system = God::EventHandler.event_system
      puts "using event system: #{event_system}"
      
      if God::EventHandler.loaded?
        puts "starting event handler"
        God::EventHandler.start
      else
        puts "[fail] event system did not load"
        exit(1)
      end
      
      puts 'forking off new process'
      
      pid = fork do
        loop { sleep(1) }
      end
      
      puts "forked process with pid = #{pid}"
      
      God::EventHandler.register(pid, :proc_exit) do
        puts "[ok] process exit event received"
        exit!(0)
      end
      
      sleep(1)
      
      puts "killing process"
      
      ::Process.kill('KILL', pid)
    rescue => e
      puts e.message
      puts e.backtrace.join("\n")
    end
  end
  
  sleep(2)
  
  puts "[fail] never received process exit event"
  exit(1)
end