<commit_before>require "foreman/configuration"
require "foreman/export"

class Foreman::Export::Upstart

  attr_reader :engine

  def initialize(engine)
    @engine = engine
  end

  def export(app)
    FileUtils.mkdir_p "/etc/foreman"
    FileUtils.mkdir_p "/etc/init"

    config = Foreman::Configuration.new(app)

    write_file "/etc/init/#{app}.conf", <<-UPSTART_MASTER
pre-start script

bash << "EOF"
  mkdir -p /var/log/#{app}

  if [ -f /etc/foreman/#{app}.conf ]; then
    source /etc/foreman/#{app}.conf
  fi

  for process in $( echo "$#{app}_processes" ); do
    process_count_config="#{app}_$process"
    process_count=${!process_count_config}

    for ((i=1; i<=${process_count:=1}; i+=1)); do
      start #{app}-$process NUM=$i
    done
  done
EOF

end script
    UPSTART_MASTER

    engine.processes.values.each do |process|
      write_file "/etc/init/#{app}-#{process.name}.conf", <<-UPSTART_CHILD
instance $NUM
stop on stopping #{app}
respawn

chdir #{engine.directory}
exec #{process.command} >>/var/log/#{app}/#{process.name}.log 2>&1
      UPSTART_CHILD
    end

    engine.processes.each do |name, process|
      config.scale(name, 1)
    end
    config.write
  end

private ######################################################################

  def write_file(filename, contents)
    File.open(filename, "w") do |file|
      file.puts contents
    end
  end

end<commit_msg>dont roll back to 1 every export<commit_after>require "foreman/configuration"
require "foreman/export"

class Foreman::Export::Upstart

  attr_reader :engine

  def initialize(engine)
    @engine = engine
  end

  def export(app)
    FileUtils.mkdir_p "/etc/foreman"
    FileUtils.mkdir_p "/etc/init"

    config = Foreman::Configuration.new(app)

    write_file "/etc/init/#{app}.conf", <<-UPSTART_MASTER
pre-start script

bash << "EOF"
  mkdir -p /var/log/#{app}

  if [ -f /etc/foreman/#{app}.conf ]; then
    source /etc/foreman/#{app}.conf
  fi

  for process in $( echo "$#{app}_processes" ); do
    process_count_config="#{app}_$process"
    process_count=${!process_count_config}

    for ((i=1; i<=${process_count:=1}; i+=1)); do
      start #{app}-$process NUM=$i
    done
  done
EOF

end script
    UPSTART_MASTER

    engine.processes.values.each do |process|
      write_file "/etc/init/#{app}-#{process.name}.conf", <<-UPSTART_CHILD
instance $NUM
stop on stopping #{app}
respawn

chdir #{engine.directory}
exec #{process.command} >>/var/log/#{app}/#{process.name}.log 2>&1
      UPSTART_CHILD
    end

    engine.processes.each do |name, process|
      config.processes[name] ||= 1
    end
    config.write
  end

private ######################################################################

  def write_file(filename, contents)
    File.open(filename, "w") do |file|
      file.puts contents
    end
  end

end
{'fraction_non_alphanumeric': 0.19024045261669023, 'fraction_numerical': 0.004596888260254597, 'mean_word_length': 3.5629032258064517, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, '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': '7531478', 'n_tokens_mistral': 977, 'n_tokens_neox': 939, 'n_words': 211}