<commit_before>require 'fileutils'

module Guard
  class RailsRunner
    MAX_WAIT_COUNT = 10

    attr_reader :options

    def initialize(options)
      @options = options
    end

    def start
      kill_unmanaged_pid! if options[:force_run]
      run_rails_command!
      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
        system %{kill -KILL #{pid}} # TODO: if pid still exists
        FileUtils.rm pid_file, :force => true
      end
    end

    def restart
      stop
      start
    end

    def build_rails_command
      rails_options = [<commit_msg>ensure kill server<commit_after>require 'fileutils'

module Guard
  class RailsRunner
    MAX_WAIT_COUNT = 10

    attr_reader :options

    def initialize(options)
      @options = options
    end

    def start
      kill_unmanaged_pid! if options[:force_run]
      run_rails_command!
      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

        # If you lost your pid_file, you are already died.
        system %{kill -KILL #{pid} > /dev/null 2>&1}
        FileUtils.rm pid_file, :force => true
      end
    end

    def restart
      stop
      start
    end

    def build_rails_command
      rails_options = [
{'fraction_non_alphanumeric': 0.07650273224043716, 'fraction_numerical': 0.00546448087431694, 'mean_word_length': 2.1573275862068964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5868303', 'n_tokens_mistral': 479, 'n_tokens_neox': 447, 'n_words': 128}