<commit_before>init-db-with-utf8:
  cmd.run:
    - name: rm -rf /var/lib/pgsql/data && su postgres sh -c 'initdb --locale=en_US.UTF-8 /var/lib/pgsql/data > /var/lib/pgsql/initdb.log' && rm /var/log/pgsql_listen_address_configured
    - unless: grep -q UTF-8 /var/lib/pgsql/initdb.log

start-postgresql:
  service.running:
    - enable: True
    - require:
      - cmd: init-db-with-utf8
    - name: postgresql

/opt/salt/scripts/conf_pgsql_listen_address.sh:
  file.managed:
    - makedirs: True
    - mode: 755
    - source: salt://postgresql/scripts/conf_pgsql_listen_address.sh

configure-listen-address:
  cmd.run:
    - name: runuser -l postgres -c '/opt/salt/scripts/conf_pgsql_listen_address.sh' && echo $(date +%Y-%m-%d:%H:%M:%S) >> /var/log/pgsql_listen_address_configured
    - require:
      - file: /opt/salt/scripts/conf_pgsql_listen_address.sh
      - service: start-postgresql
    - unless: test -f /var/log/pgsql_listen_address_configured

/opt/salt/scripts/init_db.sh:
  file.managed:
    - makedirs: True
    - require:
      - cmd: configure-listen-address
    - mode: 755
    - source: salt://postgresql/scripts/init_db.sh
    - template: jinja

init-services-db:
  cmd.run:
    - name: runuser -l postgres -c '/opt/salt/scripts/init_db.sh' && echo $(date +%Y-%m-%d:%H:%M:%S) >> /var/log/init-services-db-executed
    - unless: test -f /var/log/init-services-db-executed
    - require:
      - file: /opt/salt/scripts/init_db.sh

{% if not salt['file.directory_exists']('/yarn-private') %}  # FIXME (BUG-92637): must be disabled for YCloud

restart-pgsql-if-reconfigured:
  service.running:
    - enable: True
    - name: postgresql
    - watch:
      - cmd: configure-listen-address
      - cmd: init-services-db

{% else %}

reload-postgresql:
  cmd.run:
    - name: service postgresql reload


{% endif %}<commit_msg>CB-1340 Postgres server listens on localhost only on YCloud<commit_after>init-db-with-utf8:
  cmd.run:
    - name: rm -rf /var/lib/pgsql/data && runuser -l postgres sh -c 'initdb --locale=en_US.UTF-8 /var/lib/pgsql/data > /var/lib/pgsql/initdb.log' && rm /var/log/pgsql_listen_address_configured
    - unless: grep -q UTF-8 /var/lib/pgsql/initdb.log

start-postgresql:
  service.running:
    - enable: True
    - require:
      - cmd: init-db-with-utf8
    - name: postgresql

/opt/salt/scripts/conf_pgsql_listen_address.sh:
  file.managed:
    - makedirs: True
    - mode: 755
    - source: salt://postgresql/scripts/conf_pgsql_listen_address.sh

configure-listen-address:
  cmd.run:
    - name: runuser -l postgres -c '/opt/salt/scripts/conf_pgsql_listen_address.sh' && echo $(date +%Y-%m-%d:%H:%M:%S) >> /var/log/pgsql_listen_address_configured
    - require:
      - file: /opt/salt/scripts/conf_pgsql_listen_address.sh
      - service: start-postgresql
    - unless: test -f /var/log/pgsql_listen_address_configured

/opt/salt/scripts/init_db.sh:
  file.managed:
    - makedirs: True
    - require:
      - cmd: configure-listen-address
    - mode: 755
    - source: salt://postgresql/scripts/init_db.sh
    - template: jinja

init-services-db:
  cmd.run:
    - name: runuser -l postgres -c '/opt/salt/scripts/init_db.sh' && echo $(date +%Y-%m-%d:%H:%M:%S) >> /var/log/init-services-db-executed
    - unless: test -f /var/log/init-services-db-executed
    - require:
      - file: /opt/salt/scripts/init_db.sh
      - cmd: configure-listen-address

{% if not salt['file.directory_exists']('/yarn-private') %}  # FIXME (BUG-92637): must be disabled for YCloud

restart-pgsql-if-reconfigured:
  service.running:
    - enable: True
    - name: postgresql
    - watch:
      - cmd: configure-listen-address
      - cmd: init-services-db

{% else %}

restart-postgresql:
  cmd.run:
    - name: service postgresql restart && while ! netstat -tlpn |grep -i "0 0.0.0.0:5432" &> /dev/null; do echo "waiting for postgres"; sleep 1; done
    - watch:
      - cmd: configure-listen-address
      - cmd: init-services-db


{% endif %}
{'fraction_non_alphanumeric': 0.15153807362581947, 'fraction_numerical': 0.011094301563287948, 'mean_word_length': 2.7673314339981006, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '3020206', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1505, 'n_words': 272}