<commit_before>#!/bin/bash
# vim: set ft=sh

set -e

<%
  require "shellwords"

  def esc(x)
    Shellwords.shellescape(x)
  end
%>

RUN_DIR=/var/vcap/sys/run/atc
LOG_DIR=/var/vcap/sys/log/atc
SIGNING_KEY=/var/vcap/packages/generated_signing_key/id_rsa
PIDFILE=$RUN_DIR/atc.pid

source /var/vcap/packages/pid_utils/pid_utils.sh

<%
  postgres_addr = ""
  postgres_role_name = ""
  postgres_role_password = ""
  postgres_database = ""

  if_p("postgresql.address", "postgresql.role.name", "postgresql.role.password", "postgresql.database") do |addr, rn, rp, db|
    postgres_addr = addr
    postgres_role_name = rn
    postgres_role_password = rp
    postgres_database = db
  end

  if postgres_addr.empty?
    db = link("db")

    postgres_addr = "#{db.instances.first.address}:#{db.p("bind_port")}"
    postgres_database = p("postgresql_database")

    postgres_db = db.p("databases").find { |db| db["name"] == postgres_database }
    if postgres_db.nil?
      raise "database '#{db_name}' not provided by 'postgresql' link"
    end

    postgres_role_name = postgres_db["role"]
    postgres_role_password = <PASSWORD>["password"]
  end
%>

case $1 in

  start)
    pid_guard $PIDFILE "atc"

    mkdir -p $RUN_DIR
    chown -R vcap:vcap $RUN_DIR

    mkdir -p $LOG_DIR
    chown -R vcap:vcap $LOG_DIR

    echo $$ > /var/vcap/sys/run/atc/atc.pid

    chown vcap:vcap $SIGNING_KEY
    chmod 0400 $SIGNING_KEY

    exec chpst -u vcap:vcap /var/vcap/packages/atc/bin/atc \
      --bind-ip <%= p("bind_ip") %> \
      --bind-port <%= p("bind_port") %> \
      <% if_p("tls_bind_port", "tls_cert", "tls_key") do |port, _, _| %> \
      --tls-bind-port <%= port %> \
      --tls-cert /var/vcap/jobs/atc/config/tls_cert \
      --tls-key /var/vcap/jobs/atc/config/tls_key \
      <% end %> \
      --peer-url <%= p("peer_url", "http://#{spec.address}:#{p("bind_port")}") %> \
      --external-url <%= esc(p("external_url")) %> \
      --postgres-data-source <%= esc("postgres://#{postgres_role_name}:#{postgres_role_password}@#{postgres_addr}/#{postgres_database}?sslmode=disable") %> \
      <% if p("development_mode") %> \
      --development-mode \
      <% end %> \
      <% if p("allow_self_signed_certificates") %> \
      --allow-self-signed-certificates \
      <% end %> \
      --basic-auth-username <%= esc(p("basic_auth_username")) %> \
      --basic-auth-password <%= esc(p("<PASSWORD>")) %> \
      <% p("github_auth.authorize").each do |a| %> \
        <% if org = a["organization"] %> \
          <% if a["teams"] == "all" %> \
      --github-auth-organization <%= esc(org) %> \
          <% elsif a["teams"].respond_to?(:each) %> \
            <% a["teams"].each do |team| %> \
      --github-auth-team <%= esc("#{org}/#{team}") %> \<commit_msg>rotate logs on atc VM before starting it<commit_after>#!/bin/bash
# vim: set ft=sh

set -e

<%
  require "shellwords"

  def esc(x)
    Shellwords.shellescape(x)
  end
%>

RUN_DIR=/var/vcap/sys/run/atc
LOG_DIR=/var/vcap/sys/log/atc
SIGNING_KEY=/var/vcap/packages/generated_signing_key/id_rsa
PIDFILE=$RUN_DIR/atc.pid

source /var/vcap/packages/pid_utils/pid_utils.sh

<%
  postgres_addr = ""
  postgres_role_name = ""
  postgres_role_password = ""
  postgres_database = ""

  if_p("postgresql.address", "postgresql.role.name", "postgresql.role.password", "postgresql.database") do |addr, rn, rp, db|
    postgres_addr = addr
    postgres_role_name = rn
    postgres_role_password = rp
    postgres_database = db
  end

  if postgres_addr.empty?
    db = link("db")

    postgres_addr = "#{db.instances.first.address}:#{db.p("bind_port")}"
    postgres_database = p("postgresql_database")

    postgres_db = db.p("databases").find { |db| db["name"] == postgres_database }
    if postgres_db.nil?
      raise "database '#{db_name}' not provided by 'postgresql' link"
    end

    postgres_role_name = postgres_db["role"]
    postgres_role_password = postgres_db["password"]
  end
%>

case $1 in

  start)
    pid_guard $PIDFILE "atc"

    mkdir -p $RUN_DIR
    chown -R vcap:vcap $RUN_DIR

    mkdir -p $LOG_DIR
    chown -R vcap:vcap $LOG_DIR

    echo $$ > /var/vcap/sys/run/atc/atc.pid

    chown vcap:vcap $SIGNING_KEY
    chmod 0400 $SIGNING_KEY

    logrotate -f /etc/logrotate.d/vcap

    exec chpst -u vcap:vcap /var/vcap/packages/atc/bin/atc \
      --bind-ip <%= p("bind_ip") %> \
      --bind-port <%= p("bind_port") %> \
      <% if_p("tls_bind_port", "tls_cert", "tls_key") do |port, _, _| %> \
      --tls-bind-port <%= port %> \
      --tls-cert /var/vcap/jobs/atc/config/tls_cert \
      --tls-key /var/vcap/jobs/atc/config/tls_key \
      <% end %> \
      --peer-url <%= p("peer_url", "http://#{spec.address}:#{p("bind_port")}") %> \
      --external-url <%= esc(p("external_url")) %> \
      --postgres-data-source <%= esc("postgres://#{postgres_role_name}:#{postgres_role_password}@#{postgres_addr}/#{postgres_database}?sslmode=disable") %> \
      <% if p("development_mode") %> \
      --development-mode \
      <% end %> \
      <% if p("allow_self_signed_certificates") %> \
      --allow-self-signed-certificates \
      <% end %> \
      --basic-auth-username <%= esc(p("basic_auth_username")) %> \
      --basic-auth-password <%= esc(p("basic_auth_password")) %> \
      <% p("github_auth.authorize").each do |a| %> \
        <% if org = a["organization"] %> \
          <% if a["teams"] == "all" %> \
      --github-auth-organization <%= esc(org) %> \
          <% elsif a["teams"].respond_to?(:each) %> \
            <% a["teams"].each do |team| %> \
      --github-auth-team <%= esc("#{org}/#{team}") %> \
{'fraction_non_alphanumeric': 0.18905383652298335, 'fraction_numerical': 0.0017885888034340906, 'mean_word_length': 2.8538938662991042, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 53, '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': '901983', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2103, 'n_words': 322}