lib/pact/mock_service/cli/pidfile.rb in pact-mock_service-2.1.0 vs lib/pact/mock_service/cli/pidfile.rb in pact-mock_service-2.1.1.pre.alpha.2

- old
+ new

@@ -1,6 +1,7 @@ require 'fileutils' +require 'pact/mock_service/os' module Pact module MockService class CLI < Thor @@ -71,26 +72,38 @@ sleep_time = 0.1 while process_running? && tries < 100 sleep sleep_time tries += 1 end - raise "Process #{pid_from_file} not stopped after {100 * sleep_time} seconds." if process_running? + raise "Process #{pid_from_file} not stopped after #{100 * sleep_time} seconds." if process_running? end def kill_process if file_exists? begin - `ps -ef | grep pact` - Process.kill 2, pid_from_file + windows? ? windows_kill : kill_2 waitpid delete rescue Errno::ESRCH $stderr.puts "Process in PID file #{pidfile_path} not running. Deleting PID file." delete end else $stderr.puts "No PID file found at #{pidfile_path}, server probably not running. Use `ps -ef | grep pact` if you suspect the process is still running." end + end + + def windows? + Pact::MockService::OS.windows? + end + + def kill_2 + Process.kill 2, pid_from_file + end + + def windows_kill + cmd = "taskkill /f /pid #{pid_from_file}" + `#{cmd}` end end end end end