<commit_before>module Conjure
  module Service
    class RailsServer < Basic
      def initialize(host, app_name, rails_environment = "production")
        @app_name = app_name
        config = host.config
        ruby_version = file_contents(config, "../.ruby-version").strip
        @container = host.containers.create(
          label: "rails",
          base_image: "ubuntu",
          setup_commands: [
            "apt-get install -y curl git",
            "curl -L https://get.rvm.io | bash -s stable",
            "rvm install #{ruby_version}",
            "bash -c 'source /usr/local/rvm/scripts/rvm; rvm use #{ruby_version}@global --default'",
            "apt-get install -y #{apt_packages_required_for_gems.join ' '}",
            "echo 'deb http://us.archive.ubuntu.com/ubuntu/ precise universe' >>/etc/apt/sources.list",
            "apt-get install -y python-software-properties software-properties-common",
            "add-apt-repository -y ppa:chris-lea/node.js-legacy",
            "apt-get update",
            "apt-get install -y nodejs",

          ],
          environment: {
            PATH:"/usr/local/rvm/gems/ruby-1.9.3-p448@global/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            RAILS_ENV: rails_environment,
            GITHUB_TOKEN: ENV["GITHUB_TOKEN"],
            FRECKLE_SUBDOMAIN: "neomind",
          },
          ports: [80],
          host_volumes: {"/rails_app" => "/#{@app_name}"},
        )
      end

      def run
        @container.command "cd #{@app_name}; bundle --deployment"
        @container.command "cd #{@app_name}; bundle exec rake db:setup"
        @container.run "cd #{@app_name}; bundle exec rails server -p 80"
      end

      def apt_packages_required_for_gems
        ["libpq-dev"]
      end
    end
  end
end<commit_msg>Remove pid from any previously stopped instance when starting rails server<commit_after>module Conjure
  module Service
    class RailsServer < Basic
      def initialize(host, app_name, rails_environment = "production")
        @app_name = app_name
        config = host.config
        ruby_version = file_contents(config, "../.ruby-version").strip
        @container = host.containers.create(
          label: "rails",
          base_image: "ubuntu",
          setup_commands: [
            "apt-get install -y curl git",
            "curl -L https://get.rvm.io | bash -s stable",
            "rvm install #{ruby_version}",
            "bash -c 'source /usr/local/rvm/scripts/rvm; rvm use #{ruby_version}@global --default'",
            "apt-get install -y #{apt_packages_required_for_gems.join ' '}",
            "echo 'deb http://us.archive.ubuntu.com/ubuntu/ precise universe' >>/etc/apt/sources.list",
            "apt-get install -y python-software-properties software-properties-common",
            "add-apt-repository -y ppa:chris-lea/node.js-legacy",
            "apt-get update",
            "apt-get install -y nodejs",

          ],
          environment: {
            PATH:"/usr/local/rvm/gems/ruby-1.9.3-p448@global/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            RAILS_ENV: rails_environment,
            GITHUB_TOKEN: ENV["GITHUB_TOKEN"],
            FRECKLE_SUBDOMAIN: "neomind",
          },
          ports: [80],
          host_volumes: {"/rails_app" => "/#{@app_name}"},
        )
      end

      def run
        @container.command "cd #{@app_name}; bundle --deployment"
        @container.command "cd #{@app_name}; bundle exec rake db:setup"
        @container.run "cd #{@app_name}; rm -f tmp/pids/server.pid; bundle exec rails server -p 80"
      end

      def apt_packages_required_for_gems
        ["libpq-dev"]
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1368, 'fraction_numerical': 0.005333333333333333, 'mean_word_length': 2.1206322795341097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '6594903', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1166, 'n_words': 246}