<commit_before>require 'rbconfig'
require 'commands/servers/base'

unless defined?(Mongrel)
  puts "PROBLEM: Mongrel is not available on your system (or not in your path)"
  exit 1
end

require 'initializer'
Rails::Initializer.run(:initialize_logger)

require 'optparse'

detach = false
ip = nil
port = nil
mime = 'config/mime.yml'

ARGV.clone.options do |opt|
  opt.on("-p", "--port=port", Integer,
          "Runs Rails on the specified port.",
          "Default: 3000") { |p| port = p }
  opt.on("-a", "--address=ip", String,
          "Binds Rails to the specified ip.",
          "Default: 0.0.0.0") { |i| ip = i }
  opt.on("-m", "--mime=path", String,
          "Path to custom mime file.",
          "Default: config/mime.yml (if it exists)") { |m| mime = m }
  opt.on('-h', '--help', 'Show this message.') { puts opt; exit 0 }
  opt.on('-d', '-d', 'Call with -d to detach') { detach = true }
  opt.parse!
end

default_port, default_ip = 3000, '0.0.0.0'
puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}"

log_file = Pathname.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log").cleanpath

tail_thread = nil

if !detach
  puts "=> Call with -d to detach"
  puts "=> Ctrl-C to shutdown server"
  detach = false
  tail_thread = tail(log_file)
end

trap(:INT) { exit }

if File.exist?(File.join(RAILS_ROOT, mime)) && !ARGV.any? { |a| a =~ /^--?m/ }
  ARGV << "--mime=#{mime}"
end

begin
  ARGV.unshift("start")
  load 'mongrel_rails'
ensure
  unless detach
    tail_thread.kill if tail_thread
    puts 'Exiting'<commit_msg>Make script/server work with -d and -e on Mongrel<commit_after>require 'rbconfig'
require 'commands/servers/base'

unless defined?(Mongrel)
  puts "PROBLEM: Mongrel is not available on your system (or not in your path)"
  exit 1
end

require 'optparse'

OPTIONS = {
  :port        => 3000,
  :ip          => "0.0.0.0",
  :environment => (ENV['RAILS_ENV'] || "development").dup,
  :detach      => false
}

ARGV.clone.options do |opts|
  opts.on("-p", "--port=port", Integer, "Runs Rails on the specified port.", "Default: 3000") { |v| OPTIONS[:port] = v }
  opts.on("-b", "--binding=ip", String, "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
  opts.on("-d", "--daemon", "Make server run as a Daemon.") { OPTIONS[:detach] = true }
  opts.on("-e", "--environment=name", String,
          "Specifies the environment to run this server under (test/development/production).",
          "Default: development") { |v| OPTIONS[:environment] = v }

  opts.separator ""

  opts.on("-h", "--help", "Show this help message.") { puts opts; exit }

  opts.parse!
end

puts "=> Rails application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"

if OPTIONS[:detach]
  `mongrel_rails start -d -p #{OPTIONS[:port]} -a #{OPTIONS[:ip]} -e #{OPTIONS[:environment]}`
else
  require 'initializer'
  Rails::Initializer.run(:initialize_logger)

  puts "=> Call with -d to detach"
  puts "=> Ctrl-C to shutdown server"
  tail_thread = tail(Pathname.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log").cleanpath)

  trap(:INT) { exit }

  begin
    `mongrel_rails start -p #{OPTIONS[:port]} -a #{OPTIONS[:ip]} -e #{OPTIONS[:environment]}`
  ensure
    tail_thread.kill if tail_thread
    puts 'Exiting'
{'fraction_non_alphanumeric': 0.17816620668506594, 'fraction_numerical': 0.010732904017172647, 'mean_word_length': 3.4684931506849317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '1201156', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1169, 'n_words': 324}