#!/usr/bin/perl -w

=head1 NAME

    mk-mysql-package-files - создание файлов для пакета с mysql

=head1 DESCRIPTION

    config, init, logrotate, директория, 

    если указаны параметры port=NNN и lfw_ports=STR:NUM,... создаётся конфиг для lfw
    если указаны параметры port=NNN и zabbix=1, создаётся конфиг для zabbix'а и необходимое для него (sudoers, в частности)

    Важно: файлы и директории не передаются во владение никаким специальным пользователям (mysql), chown надо делать в postinst к пакету с конфигами

=cut

use strict;
use warnings;

use SvnRelease::MkFiles;

my $mkfiles = SvnRelease::MkFiles->new(
    files => [
        {tmpl => 'mysql_init_d', file => "/etc/init.d/mysql.[% instance %]", perm => 0755, },
        {tmpl => 'mysql_config', file => "/etc/mysql/[% instance %].cnf", },
        {tmpl => 'mysql_server_id_cnf', file => "/etc/mysql/[% instance %].conf.d/server-id.cnf", },
        {tmpl => 'mysql_slave_host_cnf', file => "/etc/mysql/[% instance %].conf.d/slave-host.cnf", },
        #{tmpl => 'generate_audit_conf', file => "/etc/mysql/[% instance %].conf.d/audit.cnf", },
        {tmpl => 'generate_semisync_conf', file => "/etc/mysql/[% instance %].conf.d/semisync.cnf", 
			cond => sub {$_[0]->{is_pxc_instance}}},
        {tmpl => 'mysql_start', file => "/etc/mysql/[% instance %]-start", perm => 0755, },
        {tmpl => 'mysql_monitor', file => "/etc/mysql-monitor.d/[% instance %]", },
        {tmpl => 'lfw_d', file => "/etc/lfw.d/[% instance %]", 
                        cond => sub {$_[0]->{port} && $_[0]->{lfw_ports}}, },
        {tmpl => 'logrotate_d', file => "/etc/logrotate.d/mysql-[% instance %]", },
        {tmpl => 'debian_postinst', file => "/DEBIAN/postinst", perm => 0755, },
        {tmpl => 'debian_postrm', file => "/DEBIAN/postrm", perm => 0755, },
        {dir => "/etc/mysql/[% instance %].conf.d", perm => 0755 },
        {dir => "/opt/mysql.[% instance %]", perm => 0755 },
        {dir => "/var/log/mysql.[% instance %]", perm => 0755 },
        {tmpl => 'zabbix_conf', file => "/etc/zabbix/conf.d/mysql-[% instance %].conf", 
                        cond => sub {$_[0]->{port} && $_[0]->{zabbix}}},
        {tmpl => 'sudoers_d', file => "/etc/sudoers.d/lfw", perm => 0440,
                        cond => sub {$_[0]->{port} && $_[0]->{zabbix}}},
        #{tmpl => 'generate_mysql_wsrep_conf', file => '/usr/local/bin/generate-mysql-wsrep-conf-[% instance %]', perm => 0755,
        #                cond => sub {$_[0]->{is_pxc_instance}}},
        #{tmpl => 'generate_mysql_wsrep_conf_monitor_sh', file => '/usr/local/bin/generate-mysql-wsrep-conf-[% instance %]-monitor.sh', perm => 0755,
        #                cond => sub {$_[0]->{is_pxc_instance}}},
        #{tmpl => 'generate_mysql_wsrep_conf_monrun_conf', file => '/etc/monrun/conf.d/mysql_wsrep_cnf_[% instance %].conf',
        #                cond => sub {$_[0]->{is_pxc_instance}}},
        ],
    templates_fh => \*DATA,
    substvars => {
        'mysql:Depends' => sub {
            my ($vars) = @_;
            return join(', ',
                                'percona-server-server-5.5 | percona-server-server-5.6 | percona-server-server-5.7 | percona-xtradb-cluster-server-5.5 | percona-xtradb-cluster-server-5.6 | percona-xtradb-cluster-server-5.7',
                                'logrotate',
                                'yandex-du-lm (>= 2.25-1)',
                                'yandex-du-mysql-monitor (>= 3.17)',
                                'monrun',
                                ( $vars->{port} && $vars->{lfw_ports} ? ('yandex-du-lfw') : () ),
                                ( $vars->{is_pxc_instance} ? ('yandex-du-generate-mysql-wsrep-cnf (>=0.05-1)') : () ),
            );
        },
        'mysql:Conflicts' => 'apparmor',
    },
    );

my ($instance, @dummy) = $mkfiles->parse_options("instance_name");
if (@dummy || $instance !~ /^[a-z0-9_\-]+$/) {
    $mkfiles->usage();
}

$mkfiles->{vars}->{instance} = $instance;

$mkfiles->mk();

__DATA__
<< mysql_init_d
#!/bin/bash
#
### BEGIN INIT INFO
# Provides:          mysql
# Required-Start:    $syslog mysql-ndb-mgm
# Required-Stop:     $syslog
# Should-Start:      $local_fs $remote_fs $network $named $time
# Should-Stop:       $local_fs $remote_fs $network $named $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop the mysql database server daemon
# Description:       Controls the main MySQL database server daemon "mysqld"
#                    and its wrapper script "mysqld_safe".
### END INIT INFO
#
set -e
set -u
${DEBIAN_SCRIPT_DEBUG:+ set -v -x}

test -x /usr/sbin/mysqld || exit 0

. /lib/lsb/init-functions

SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
NAME=[% instance %]
CONF="/etc/mysql/$NAME.cnf"
MYADMIN="/usr/bin/mysqladmin --defaults-file=$CONF"
STARTUP_TIMEOUT=[% startup_timeout || '120' %]

test -d "/var/run/mysqld.$NAME" || mkdir "/var/run/mysqld.$NAME" && chown mysql:mysql "/var/run/mysqld.$NAME"

# priority can be overriden and "-s" adds output to stderr
ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mysql.$NAME -i"

# Safeguard (relative paths, core dumps..)
cd /
umask 077

# mysqladmin likes to read /root/.my.cnf. This is usually not what I want
# as many admins e.g. only store a password without a username there and
# so break my scripts.
export HOME=/etc/mysql/

# create first mysql.err log
LOGDIR="/var/log/mysql.$NAME"
[ -d $LOGDIR ] || mkdir $LOGDIR
[ -f $LOGDIR/mysql.err ] || touch $LOGDIR/mysql.err
chown mysql:mysql $LOGDIR/mysql.err ||:

## Fetch a particular option from mysql's invocation.
#
# Usage: void mysqld_get_param option
mysqld_get_param() {
	/usr/sbin/mysqld --defaults-file=$CONF --print-defaults \
		| tr " " "\n" \
		| grep -- "--$1" \
		| tail -n 1 \
		| cut -d= -f2
}

## Do some sanity checks before even trying to start mysqld.
sanity_checks() {
  # check for config file
  if [ ! -r $CONF ]; then
    log_warning_msg "$0: WARNING: $CONF cannot be read. See README.Debian.gz"
    echo                "WARNING: $CONF cannot be read. See README.Debian.gz" | $ERR_LOGGER
  fi

  # check for buggy options
  if grep -q ^expire.logs.days $CONF  &&  ! grep -q ^log.bin $CONF; then
    log_failure_msg "$0: ERROR: Using expire_logs_days without log_bin crashes the server. See README.Debian.gz"
    echo                "ERROR: Using expire_logs_days without log_bin crashes the server. See README.Debian.gz" | $ERR_LOGGER
    exit 1
  fi

  # check for diskspace shortage
  datadir=`mysqld_get_param datadir`
  if LC_ALL=C BLOCKSIZE= df --portability $datadir/. | tail -n 1 | awk '{ exit ($4>4096) }'; then
    log_failure_msg "$0: ERROR: The partition with $datadir is too full!"
    echo                "ERROR: The partition with $datadir is too full!" | $ERR_LOGGER
    exit 1
  fi

  #
  for conffile in $CONF /etc/mysql/$NAME.conf.d/*.cnf; do
    if grep -q FIXME $conffile; then
      log_failure_msg "$0: ERROR: Unfixed conf file: $conffile"
      echo                "ERROR: Unfixed conf file: $conffile" | $ERR_LOGGER
      exit 1
    fi
  done

}

## Checks if there is a server running and if so if it is accessible.
#
# check_alive insists on a pingable server
# check_dead also fails if there is a lost mysqld in the process list
#
# Usage: boolean mysqld_status [check_alive|check_dead] [warn|nowarn]
mysqld_status () {
    ping_output=`$MYADMIN ping 2>&1`; ping_alive=$(( ! $? ))

    ps_alive=0
    pidfile=`mysqld_get_param pid-file`
    if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi
    
    if [ "$1" = "check_alive"  -a  $ping_alive = 1 ] ||
       [ "$1" = "check_dead"   -a  $ping_alive = 0  -a  $ps_alive = 0 ]; then
	return 0 # EXIT_SUCCESS
    else
  	if [ "$2" = "warn" ]; then
  	    echo -e "$ps_alive processes alive and '$MYADMIN ping' resulted in\n$ping_output\n" | $ERR_LOGGER -p daemon.debug
	fi
  	return 1 # EXIT_FAILURE
    fi
}

#
# main()
#

case "${1:-''}" in
  'start')
    sanity_checks;
    # Start daemon
    log_daemon_msg "Starting MySQL database server" "mysqld"
    if mysqld_status check_alive nowarn; then
       log_progress_msg "already running"
       log_end_msg 0
    else
        /usr/bin/mysqld_safe --defaults-file=$CONF > /dev/null 2>&1 &
        MYSQL_SAFE_PID=$!
        # 6s was reported in #352070 to be too few when using ndbcluster
        for i in `seq 1 $STARTUP_TIMEOUT`; do
                sleep 1
            if mysqld_status check_alive nowarn ; then break; fi
            if ! kill -0 $MYSQL_SAFE_PID 2>/dev/null; then echo "mysqld_safe is not running"; break; fi
        log_progress_msg "."
        done
        if mysqld_status check_alive warn; then
                log_end_msg 0
            # Now start mysqlcheck or whatever the admin wants.
            output=`/etc/mysql/$NAME-start`
        [ -n "$output" ] && log_action_msg "$output"
        else
            log_end_msg 1
        log_failure_msg "Please take a look at the syslog"
        fi
    fi

    # Some warnings
        if $MYADMIN variables | egrep -q have_bdb.*YES; then
            echo "BerkeleyDB is obsolete, see /usr/share/doc/mysql-server-5.0/README.Debian.gz" | $ERR_LOGGER -p daemon.info
        fi
        if [ -f /etc/mysql/debian-log-rotate.conf ]; then
            echo "/etc/mysql/debian-log-rotate.conf is obsolete, see /usr/share/doc/mysql-server-5.0/NEWS.Debian.gz" | $ERR_LOGGER -p daemon.info
        fi

[% IF is_semisync_instance %]
    /usr/bin/mysql --defaults-file=$CONF -uroot --execute "SET GLOBAL rpl_semi_sync_master_enabled=OFF" ||:
    /usr/bin/mysql --defaults-file=$CONF -uroot --execute "SET GLOBAL rpl_semi_sync_slave_enabled=ON" ||:
    /usr/bin/mysql --defaults-file=$CONF -uroot --execute "STOP SLAVE" ||:
    /usr/bin/mysql --defaults-file=$CONF -uroot --execute "START SLAVE" ||:
[% END %]
    ;;

[% IF is_pxc_instance %]
  # Операция bootstrap-pxc доступна только для серверов с Percona XtraDB Cluster.
  # Она нужна для того, чтобы запустить сервер, который создаст новый кластер.
  # Это нужно делать, когда кластера ещё нет; если он уже есть, нужно
  # записать хотя бы один другой узел в wsrep_cluster_address в my.cnf
  # и запустить с помощью start.
  'bootstrap-pxc')
	sanity_checks;
	# Start daemon
	log_daemon_msg "Starting MySQL database server" "mysqld"
	if mysqld_status check_alive nowarn; then
	   log_progress_msg "already running"
	   log_end_msg 0
	else
  	    /usr/bin/mysqld_safe --defaults-file=$CONF --wsrep-new-cluster > /dev/null 2>&1 &
	    # 6s was reported in #352070 to be too few when using ndbcluster
	    for i in `seq 1 $STARTUP_TIMEOUT`; do
                sleep 1
	        if mysqld_status check_alive nowarn ; then break; fi
		log_progress_msg "."
	    done
	    if mysqld_status check_alive warn; then
                log_end_msg 0
	        # Now start mysqlcheck or whatever the admin wants.
	        output=`/etc/mysql/$NAME-start`
		[ -n "$output" ] && log_action_msg "$output"
	    else
	        log_end_msg 1
		log_failure_msg "Please take a look at the syslog"
	    fi
	fi

	# Some warnings
        if $MYADMIN variables | egrep -q have_bdb.*YES; then
            echo "BerkeleyDB is obsolete, see /usr/share/doc/mysql-server-5.0/README.Debian.gz" | $ERR_LOGGER -p daemon.info
        fi
        if [ -f /etc/mysql/debian-log-rotate.conf ]; then
            echo "/etc/mysql/debian-log-rotate.conf is obsolete, see /usr/share/doc/mysql-server-5.0/NEWS.Debian.gz" | $ERR_LOGGER -p daemon.info
        fi
	;;
[% END %]

  'stop')
	# * As a passwordless mysqladmin (e.g. via ~/.my.cnf) must be possible
	# at least for cron, we can rely on it here, too. (although we have 
	# to specify it explicit as e.g. sudo environments points to the normal
	# users home and not /root)
	log_daemon_msg "Stopping MySQL database server" "mysqld"
	if ! mysqld_status check_dead nowarn; then
	  set +e
	  shutdown_out=`$MYADMIN shutdown 2>&1`; r=$?
	  set -e
	  if [ "$r" -ne 0 ]; then
	    log_end_msg 1
	    [ "$VERBOSE" != "no" ] && log_failure_msg "Error: $shutdown_out"
	    log_daemon_msg "Killing MySQL database server by signal" "mysqld"
	    killall -15 mysqld
            server_down=
	    for i in 1 2 3 4 5 6 7 8 9 10; do
              sleep 1
              if mysqld_status check_dead nowarn; then server_down=1; break; fi
            done
          if test -z "$server_down"; then killall -9 mysqld; fi
	  fi
        fi

        if ! mysqld_status check_dead warn; then
	  log_end_msg 1
	  log_failure_msg "Please stop MySQL manually and read /usr/share/doc/mysql-server-5.0/README.Debian.gz!"
	  exit -1
	else
	  log_end_msg 0
        fi
	;;

  'restart')
	set +e; $SELF stop; set -e
	$SELF start 
	;;

  'reload'|'force-reload')
  	log_daemon_msg "Reloading MySQL database server" "mysqld"
	$MYADMIN reload
	log_end_msg 0
	;;

  'status')
	if mysqld_status check_alive nowarn; then
	  log_action_msg "$($MYADMIN version)"
	else
	  log_action_msg "MySQL is stopped."
	  exit 3
	fi
  	;;

  *)
	echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
	exit 1
	;;
esac

<< logrotate_d
# rotate mysql logs
/var/log/mysql.[% instance %]/mysql.err /var/log/mysql.[% instance %]/mysql-slow.log {
	daily
	rotate 7
	missingok
	create 644 mysql root
	compress
	sharedscripts
	postrotate
		test -x /usr/bin/mysqladmin || exit 0

		CONF=/etc/mysql/[% instance %].cnf
		MYADMIN="/usr/bin/mysqladmin --defaults-file=$CONF"
		if [ -z "`$MYADMIN ping 2>/dev/null`" ]; then
		  if ps cax | egrep -q "mysqld.*$CONF"; then
 		    exit 1
		  fi 
		else
		  $MYADMIN flush-logs
		fi
	endscript
}


<< lfw_d
---
server_port: [% port %]
ports:
[% FOR port = lfw_ports.split(',') %]  [% port.replace(":", ": ") %]
[% END %]


<< mysql_server_id_cnf
[mysqld]
server-id = FIXME


<< mysql_slave_host_cnf
[mysqld]
report-host = FIXME


<< mysql_start
#!/bin/bash
#
# This script is executed by "/etc/init.d/mysql" on every (re)start.
# 
# Changes to this file will be preserved when updating the Debian package.
#

source /usr/share/mysql/debian-start.inc.sh

NAME=[% instance %]
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/$NAME.cnf"
MYUPGRADE="/usr/bin/mysql_upgrade_shell --defaults-extra-file=/etc/mysql/$NAME.cnf"
MYCHECK="/usr/bin/mysqlcheck --defaults-file=/etc/mysql/$NAME.cnf"
MYCHECK_SUBJECT="WARNING: mysqlcheck has found corrupt tables"
MYCHECK_PARAMS="--all-databases --fast --silent"
MYCHECK_RCPT="root"

# The following commands should be run when the server is up but in background
# where they do not block the server start and in one shell instance so that
# they run sequentially. They are supposed not to echo anything to stdout.
# If you want to disable the check for crashed tables comment "mycheck" out.
# (There may be no output to stdout inside the background process!)
##echo "Checking for corrupt, not cleanly closed and upgrade needing tables."
##(
##  check_for_crashed_tables;
##  upgrade_system_tables_if_necessary;
##) >&2 &

exit 0



<< mysql_monitor
---
socket: /var/run/mysqld.[% instance %]/mysqld.sock
[% IF checksum_result_table %]checksum_result_table: [% checksum_result_table %][% END %]


<< mysql_config
# You can copy this to one of:
# /etc/mysql/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /var/lib/mysql) or
# ~/.my.cnf to set user-specific options.
# 
# One can use all long options that the program supports.
# Run the program with --help to get a list of available options

[safe_mysqld]
err-log		= /var/log/mysql.[% instance %]/mysql.err

[mysqld]
user		= mysql
pid-file	= /var/run/mysqld.[% instance %]/mysqld.pid
socket		= /var/run/mysqld.[% instance %]/mysqld.sock
port		= [% port || 3306 %]

character-set-server = utf8

#skip-networking
#skip-slave-start

# init file must provide server-id
log-slave-updates

log-slow-queries = /var/log/mysql.[% instance %]/mysql-slow.log
basedir		= /usr
datadir		= /opt/mysql.[% instance %]
tmpdir		= /opt/tmp
language	= /usr/share/mysql/english
skip-locking

#plugin-load	= audit_log=audit_log.so

log-bin			= /opt/mysql.[% instance %]/[% instance %]-bin
expire_logs_days        = [% expire_logs_days || 4 %]
max-binlog-size         = 1G

relay-log               = /opt/mysql.[% instance %]/[% instance %]-relay
relay-log-index         = /opt/mysql.[% instance %]/[% instance %]-relay.index
relay-log-info-file     = /opt/mysql.[% instance %]/[% instance %]-relay.info
slave_net_timeout = 300

log-error		= /var/log/mysql.[% instance %]/mysql.err

set-variable	= max_connections=2000
set-variable	= key_buffer_size=64M
set-variable	= max_allowed_packet=16M
set-variable	= max_heap_table_size=1M
set-variable	= join_buffer_size=4M
set-variable	= tmp_table_size=32M
set-variable	= open_files_limit=8192
set-variable	= group_concat_max_len=100000

default-storage-engine = InnoDB

innodb_file_per_table

innodb_data_file_path           = ibdata1:128M:autoextend
innodb_buffer_pool_size         = [% innodb_buffer_pool_size || '1G' %]
innodb_additional_mem_pool_size = 64M
#skip_innodb_doublewrite
#innodb_open_files = 300

innodb_lock_wait_timeout        = 300

innodb_log_group_home_dir       = /opt/mysql.[% instance %]
innodb_log_files_in_group       = 2
innodb_log_file_size            = [% innodb_log_file_size || '256M' %]
innodb_log_buffer_size          = 8M
innodb_flush_log_at_trx_commit  = 2


set-variable = old_passwords=1
set-variable    = max_connections=2000
set-variable    = binlog_cache_size=131072
set-variable    = back_log=500
set-variable    = sort_buffer=2M
set-variable    = record_buffer=2M
set-variable    = thread_cache=256
# Try number of CPU's*2 for thread_concurrency
set-variable    = thread_concurrency=16
set-variable    = myisam_sort_buffer_size=128M

[client]
socket		= /var/run/mysqld.[% instance %]/mysqld.sock

!include /etc/mysql/[% instance %]-local.cnf


<< debian_postinst
#!/bin/bash -e

. /usr/share/debconf/confmodule

chown mysql:mysql /var/log/mysql.[% instance %] /opt/mysql.[% instance %] 

[% FOR dir = ['data', 'bin-logs', 'relay-logs'] %] 
test -d /opt/mysql.[% instance %]/[% dir %] && chown mysql:mysql /opt/mysql.[% instance %]/[% dir %]
[% END %]

test -e /opt/tmp || mkdir /opt/tmp && chmod go+wt /opt/tmp

update-rc.d -f mysql remove >/dev/null
update-rc.d -f mysql.[% instance %] remove >/dev/null

update-rc.d mysql.[% instance %] start 20 3 4 5 . stop 20 0 1 2 6 . >/dev/null

if grep -q FIXME /etc/mysql/[% instance %].conf.d/server-id.cnf; then
    echo "generating /etc/mysql/[% instance %].conf.d/server-id.cnf"
    serverid=`od -An -N2 -l /dev/random`;
    echo -e "[mysqld]\nserver-id = $serverid" > /etc/mysql/[% instance %].conf.d/server-id.cnf
fi

if grep -q FIXME /etc/mysql/[% instance %].conf.d/slave-host.cnf; then
    echo "generating /etc/mysql/[% instance %].conf.d/slave-host.cnf"
    slave_host=`hostname --fqdn`
    if [ -n "$slave_host" ]; then
        sed -i "s/FIXME/$slave_host/" /etc/mysql/[% instance %].conf.d/slave-host.cnf
    else
        echo "could not get slave hostname, exiting"
        exit 1
    fi
fi

[% IF is_pxc_instance %]
    if [ ! -e /etc/mysql/[% instance %].conf.d/wsrep.cnf ]; then
        echo "generating /etc/mysql/[% instance %].conf.d/wsrep.cnf"
        /usr/local/bin/generate-mysql-wsrep-conf-[% instance %] ||:
    fi
[% END %]

/usr/sbin/regenerate-mysql-monitor-monrun ||:
/usr/sbin/generate-mysql-push-client-config ||:

<< debian_postrm
#!/bin/bash -e

. /usr/share/debconf/confmodule

update-rc.d -f mysql.[% instance %] remove >/dev/null

<< zabbix_conf
UserParameter=[% instance %].open.lfw,test "`sudo lfw [% instance %] | grep write | awk '{print $3}'`" -eq [% port %]; echo $?

<< sudoers_d
monitor ALL=NOPASSWD: /usr/local/bin/lfw [% instance %]

<< generate_mysql_wsrep_conf
#!/bin/bash -ex

/usr/local/bin/generate-mysql-wsrep-cnf.pl \
    --instance=[% instance %] \
    --cgroup=[% cgroup %] \
    --galera-port=[% galera_port %] \
    --template=/etc/mysql/[% instance %]-wsrep.cnf.tmpl \
    --outfile=/etc/mysql/[% instance %].conf.d/wsrep.cnf

<< generate_mysql_wsrep_conf_monitor_sh
#!/bin/bash

REALFILE=/etc/mysql/[% instance %].conf.d/wsrep.cnf

if [ ! -e $REALFILE ]; then
    echo "2;$REALFILE doesn't exist"
    exit 0
fi

TEMPFILE=/tmp/mysql-wsrep-cnf-[% instance %]-monitoring.out

GENERATE_CMD="/usr/local/bin/generate-mysql-wsrep-cnf.pl
    --instance=[% instance %]
    --cgroup=[% cgroup %]
    --galera-port=[% galera_port %]
    --template=/etc/mysql/[% instance %]-wsrep.cnf.tmpl
    --quiet
    --outfile=$TEMPFILE"

if ! $GENERATE_CMD; then
    echo "1;$GENERATE_CMD failed"
    exit 0
fi

if ! cmp -s $TEMPFILE $REALFILE; then
    echo "2;$REALFILE doesn't match the generated config ($TEMPFILE)"
    exit 0
fi

echo "0;OK"
exit 0

<< generate_mysql_wsrep_conf_monrun_conf
[mysql_wsrep_cnf_[% instance %]]
execution_interval=3600
execution_timeout=300
command=/usr/local/bin/generate-mysql-wsrep-conf-[% instance %]-monitor.sh
type=[% instance %]

<< generate_audit_conf
[mysqld]
audit_log_format = JSON
audit_log_handler = FILE
audit_log_policy = LOGINS
audit_log_file = audit.log
audit_log_rotations = 10
audit_log_rotate_on_size = 200M

<< generate_semisync_conf
[mysqld]
plugin-load = rpl_semi_sync_master=semisync_master.so
plugin-load = rpl_semi_sync_slave=semisync_slave.so
rpl_semi_sync_master_timeout = 600000
rpl_semi_sync_master_trace_level = 32
rpl_semi_sync_master_wait_for_slave_count = 1
rpl_semi_sync_master_wait_no_slave = ON
rpl_semi_sync_master_wait_point = AFTER_SYNC
rpl_semi_sync_slave_trace_level = 32

