[buildout]

extends =
  buildout.hash.cfg
  ../../component/restic/buildout.cfg
  ../../component/replication-manager/buildout.cfg
  ../../component/mariadb/buildout.cfg
  ../../component/nginx/buildout.cfg
  ../../component/haproxy/buildout.cfg
  ../../component/logrotate/buildout.cfg
  ../../component/percona-toolkit/buildout.cfg
  ../../component/gzip/buildout.cfg
  ../../component/sed/buildout.cfg
  ../../component/coreutils/buildout.cfg
  ../../component/grep/buildout.cfg
  ../../component/sysbench/buildout.cfg
  ../../component/proxysql/buildout.cfg
  ../../component/socat/buildout.cfg
  ../../component/rsync/buildout.cfg
  ../../component/jq/buildout.cfg
  ../../component/openssl/buildout.cfg
  ../../stack/supervisord/buildout.cfg
  ../../stack/monitor/buildout.cfg
  ../../stack/caucase/buildout.cfg

parts =
  slapos-cookbook
  mroonga-mariadb
  instance.cfg
  template-mariadb.cfg
  template-mysqld-wrapper
  caucase-eggs
  gowork

[template-mysqld-wrapper]
recipe = slapos.recipe.template
output = ${buildout:parts-directory}/${:_buildout_section_name_}/mysqld.in
inline =
  #!/bin/sh -e
  basedir='${mariadb:location}'
  datadir='{{datadir}}'
  marker=$datadir/.slapos_initializing
  system=$datadir/.system
  [ -d "$datadir/mysql" ] && [ ! -f "$marker" ] || {
    find "$datadir/" -mindepth 1 ! \( -path $marker -o -path $system -o -path "*$system/*" \) -delete || mkdir "$datadir"
    touch "$marker"
    "$basedir/scripts/mysql_install_db" \
      --defaults-file='{{defaults_file}}' \
      --skip-name-resolve \
      --auth-root-authentication-method=normal \
      --basedir="$basedir" --plugin_dir="$basedir/lib/plugin" \
      --datadir="$datadir"
    rm "$marker"
  }
  {%- if environ is defined %}
  {%-   for variable in environ.splitlines() %}
  {{ variable }} \
  {%-   endfor %}
  {%- endif %}
  exec "$basedir/bin/mysqld" --defaults-file='{{defaults_file}}' "$@"

[instance.cfg]
recipe = slapos.recipe.template:jinja2
output = ${buildout:directory}/instance.cfg
url = ${:_profile_base_location_}/${:filename}
context =
    key bash_location bash:location
    key bin_directory buildout:bin-directory
    key caucase_library caucase-jinja2-library:target
    key config_toml_in config-toml.in:target
    key config_cluster_toml_in config-cluster-toml.in:target
    key coreutils_location coreutils:location
    key curl_location curl:location
    key buildout_egg_directory buildout:eggs-directory
    key buildout_develop_directory buildout:develop-eggs-directory
    key buildout_directory buildout:directory
    key buildout_bin_directory buildout:bin-directory
    key dbjobs_in dbjobs-in:target
    key dash_location dash:location
    key jq_location jq:location
    key logrotate_cfg template-logrotate-base:output
    key gowork_bin gowork:bin
    key gzip_location gzip:location
    key haproxy_location haproxy:location
    key template_monitor monitor2-template:output
    key mariadb_link_binary template-mariadb.cfg:link-binary
    key mariadb_location mariadb:location
    key mysqld_start_template mysqld-need-start.sh.in:target
    key mroonga_mariadb_install_sql mroonga-mariadb:install-sql
    key mroonga_mariadb_plugin_dir mroonga-mariadb:plugin-dir
    key groonga_plugin_dir groonga:groonga-plugin-dir
    key groonga_mysql_normalizer_plugin_dir groonga-normalizer-mysql:groonga-plugin-dir
    key nginx_conf_in nginx.conf.in:target
    key nginx_location nginx:location
    key openssl_location openssl:location
    key percona_toolkit_location percona-toolkit:location
    key proxy_need_stop_start_template proxy-need-start-stop.sh.in:target
    key repman_src_location git.signal18.io_signal18_repman:location
    key rsync_location rsync:location
    key restic_bin_location restic:location
    key socat_location socat:location
    key supervisord_lib supervisord-library:target
    key supervisord_conf supervisord-conf:target
    key template_repman_manager_sh repman-manager-sh.in:target
    key template_mariadb template-mariadb.cfg:target
    key template_mariadb_initial_setup template-mariadb-initial-setup:target
    key template_monitor_cfg monitor2-template:output
    key template_my_cnf template-my-cnf:target
    key template_mysqld_wrapper template-mysqld-wrapper:output
    key template_init_root_sql mariadb-init-root-sql:target
    key template_init_root_wrapper init-root-wrapper-in:target
    key template_repman_cfg instance-repman.cfg:target
    key template_publish_slave template-publish-slave-information:target
    key template_slave_db_manage slave-db-manage.in:target
    key unixodbc_location unixodbc:location
    key sysbench_location sysbench:location
    key proxysql_location proxysql:location
    raw caucase_bin_client ${buildout:bin-directory}/caucase

[download-file]
recipe  = slapos.recipe.build:download
url     = ${:_profile_base_location_}/${:_update_hash_filename_}
destination = ${buildout:directory}/${:_buildout_section_name_}

[config-toml.in]
<= download-file

[config-cluster-toml.in]
<= download-file

[instance-repman.cfg]
<= download-file

[repman-manager-sh.in]
<= download-file

[template-mariadb.cfg]
<= download-file
link-binary =
  ${coreutils:location}/bin/basename
  ${coreutils:location}/bin/cat
  ${coreutils:location}/bin/cp
  ${coreutils:location}/bin/ls
  ${coreutils:location}/bin/tr
  ${coreutils:location}/bin/uname
  ${gettext:location}/lib/gettext/hostname
  ${grep:location}/bin/grep
  ${sed:location}/bin/sed
  ${mariadb:location}/bin/mysqlbinlog

[template-mariadb-initial-setup]
<= download-file

[template-publish-slave-information]
<= download-file

[template-my-cnf]
<= download-file

[mariadb-init-root-sql]
<= download-file

[init-root-wrapper-in]
<= download-file

[nginx.conf.in]
<= download-file

[dbjobs-in]
<= download-file

[mysqld-need-start.sh.in]
<= download-file

[proxy-need-start-stop.sh.in]
<= download-file

[slave-db-manage.in]
<= download-file