lib/guard/rails/runner.rb in guard-rails-0.4.4 vs lib/guard/rails/runner.rb in guard-rails-0.4.5

- old
+ new

@@ -17,16 +17,16 @@ wait_for_pid end def stop if File.file?(pid_file) - pid = File.read(pid_file).strip - system "kill -SIGINT #{pid}" - wait_for_no_pid if $?.exitstatus == 0 + pid = File.read(pid_file).strip.to_i + sig_sent = kill_process("INT", pid) + wait_for_no_pid if sig_sent # If you lost your pid_file, you are already died. - system "kill -KILL #{pid} >&2 2>#{::Guard::DEV_NULL}" + kill_process("KILL", pid) FileUtils.rm pid_file, :force => true end end def restart @@ -36,11 +36,11 @@ def build_command command = build_cli_command if options[:CLI] command ||= build_zeus_command if options[:zeus] command ||= build_rails_command - "#{environment.collect {|k,v| "#{k}=#{v} "}.join} cd \"#{@root}\" && #{command}" + "sh -c 'cd \"#{@root}\" && #{command} &'" end def environment rails_env = if options[:zeus] nil @@ -94,11 +94,11 @@ def build_rails_command "rails server #{build_options}" end def run_rails_command! - system "sh -c 'cd \"#{@root}\" && #{build_command} &'" + system(environment, build_command) end def has_pid? File.file?(pid_file) end @@ -107,11 +107,11 @@ sleep sleep_time end def kill_unmanaged_pid! if pid = unmanaged_pid - system "kill -KILL #{pid}" + kill_process("KILL", pid) FileUtils.rm pid_file wait_for_no_pid end end @@ -140,8 +140,17 @@ while !(check_for_existince ? has_pid? : !has_pid?) && count < MAX_WAIT_COUNT wait_for_pid_action count += 1 end !(count == MAX_WAIT_COUNT) + end + + def kill_process(signal, pid) + begin + Process.kill(signal, pid) + true + rescue Errno::EINVAL, Errno::ESRCH, RangeError + false + end end end end