Initial commit
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..700fc5d
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,147 @@
+
+======
+Galera
+======
+
+Galera Cluster for MySQL is a true Multimaster Cluster based on synchronous replication. Galera Cluster is an easy-to-use, high-availability solution, which provides high system uptime, no data loss and scalability for future growth.
+
+Sample pillars
+==============
+
+Galera cluster master node
+
+.. code-block:: yaml
+
+    galera:
+      master:
+        enabled: true
+        name: openstack
+        bind:
+          address: 192.168.0.1
+          port: 3306
+        members:
+        - host: 192.168.0.1
+          port: 4567
+        - host: 192.168.0.2
+          port: 4567
+        admin:
+          user: root
+          password: pass
+        database:
+          name:
+            encoding: 'utf8'
+            users:
+            - name: 'username'
+              password: 'password'
+              host: 'localhost'
+              rights: 'all privileges'
+
+Galera cluster slave node
+
+.. code-block:: yaml
+
+    galera:
+      slave:
+        enabled: true
+        name: openstack
+        bind:
+          address: 192.168.0.2
+          port: 3306
+        members:
+        - host: 192.168.0.1
+          port: 4567
+        - host: 192.168.0.2
+          port: 4567
+        admin:
+          user: root
+          password: pass
+
+Usage
+=====
+
+MySQL Galera check sripts
+
+.. code-block:: bash
+    
+    mysql> SHOW STATUS LIKE 'wsrep%';
+
+    mysql> SHOW STATUS LIKE 'wsrep_cluster_size' ;"
+
+Galera monitoring command, performed from extra server
+
+.. code-block:: bash
+
+    garbd -a gcomm://ipaddrofone:4567 -g my_wsrep_cluster -l /tmp/1.out -d
+
+1. salt-call state.sls mysql
+2. Comment everything starting wsrep* (wsrep_provider, wsrep_cluster, wsrep_sst)
+3. service mysql start
+4. run on each node mysql_secure_install and filling root password.
+
+.. code-block:: bash
+
+    Enter current password for root (enter for none): 
+    OK, successfully used password, moving on...
+
+    Setting the root password ensures that nobody can log into the MySQL
+    root user without the proper authorisation.
+
+    Set root password? [Y/n] y
+    New password: 
+    Re-enter new password: 
+    Password updated successfully!
+    Reloading privilege tables..
+     ... Success!
+
+    By default, a MySQL installation has an anonymous user, allowing anyone
+    to log into MySQL without having to have a user account created for
+    them.  This is intended only for testing, and to make the installation
+    go a bit smoother.  You should remove them before moving into a
+    production environment.
+
+    Remove anonymous users? [Y/n] y
+     ... Success!
+
+    Normally, root should only be allowed to connect from 'localhost'.  This
+    ensures that someone cannot guess at the root password from the network.
+
+    Disallow root login remotely? [Y/n] n
+     ... skipping.
+
+    By default, MySQL comes with a database named 'test' that anyone can
+    access.  This is also intended only for testing, and should be removed
+    before moving into a production environment.
+
+    Remove test database and access to it? [Y/n] y
+     - Dropping test database...
+     ... Success!
+     - Removing privileges on test database...
+     ... Success!
+
+    Reloading the privilege tables will ensure that all changes made so far
+    will take effect immediately.
+
+    Reload privilege tables now? [Y/n] y
+     ... Success!
+
+    Cleaning up...
+
+5. service mysql stop
+6. uncomment all wsrep* lines except first server, where leave only in my.cnf wsrep_cluster_address='gcomm://'; 
+7. start first node
+8. Start third node which is connected to first one
+9. Start second node which is connected to third one
+10. After starting cluster, it must be change cluster address at first starting node without restart database and change config my.cnf.
+
+.. code-block:: bash
+
+    mysql> SET GLOBAL wsrep_cluster_address='gcomm://10.0.0.2';
+
+Read more
+=========
+
+* https://github.com/CaptTofu/ansible-galera
+* http://www.sebastien-han.fr/blog/2012/04/15/active-passive-failover-cluster-on-a-mysql-galera-cluster-with-haproxy-lsb-agent/
+* http://opentodo.net/2012/12/mysql-multi-master-replication-with-galera/
+* http://www.codership.com/wiki/doku.php
+* Best one: - http://www.sebastien-han.fr/blog/2012/04/01/mysql-multi-master-replication-with-galera/
diff --git a/galera/files/debian.cnf b/galera/files/debian.cnf
new file mode 100644
index 0000000..2be2e68
--- /dev/null
+++ b/galera/files/debian.cnf
@@ -0,0 +1,12 @@
+[client]
+host = localhost
+user = debian-sys-maint
+password = {{ pillar['mysql_config']['maintenance_password'] }}
+socket = /var/run/mysqld/mysqld.sock
+
+[mysql_upgrade]
+host = localhost
+user = debian-sys-maint
+password = {{ pillar['mysql_config']['maintenance_password'] }}
+socket = /var/run/mysqld/mysqld.sock
+basedir = /usr
\ No newline at end of file
diff --git a/galera/files/my.cnf b/galera/files/my.cnf
new file mode 100644
index 0000000..91628d3
--- /dev/null
+++ b/galera/files/my.cnf
@@ -0,0 +1,189 @@
+# All files in this package is subject to the GPL v2 license
+# More information is in the COPYING file in the top directory of this package.
+# Copyright (C) 2011 severalnines.com
+{%- if pillar.galera.master is defined %}
+{%- from "galera/map.jinja" import master with context %}
+{%- set service = master %}
+{%- endif %}
+{%- if pillar.galera.slave is defined %}
+{%- from "galera/map.jinja" import slave with context %}
+{%- set service = slave %}
+{%- endif %}
+[MYSQLD]
+user=mysql
+basedir=/usr/
+datadir=/var/lib/mysql
+socket=/var/run/mysqld/mysqld.sock
+pid_file=mysqld.pid
+port=3306
+log_error=/var/log/mysql.log
+log_warnings=2
+#log_output=FILE
+### INNODB OPTIONS 
+innodb_buffer_pool_size=9211M
+innodb_flush_log_at_trx_commit=2
+innodb_file_per_table=1
+innodb_data_file_path = ibdata1:100M:autoextend
+## You may want to tune the below depending on number of cores and disk sub
+innodb_read_io_threads=4
+innodb_write_io_threads=4
+innodb_io_capacity=200
+innodb_doublewrite=1
+innodb_log_file_size=1024M
+innodb_log_buffer_size=96M
+innodb_buffer_pool_instances=8
+innodb_log_files_in_group=2
+innodb_thread_concurrency=64
+#innodb_file_format=barracuda
+innodb_flush_method = O_DIRECT
+innodb_autoinc_lock_mode=2
+## avoid statistics update when doing e.g show tables
+innodb_stats_on_metadata=0
+default_storage_engine=innodb
+
+bind-address={{ service.bind.address }}
+
+# CHARACTER SET
+#collation_server = utf8_unicode_ci
+#init_connect='SET NAMES utf8'
+character_set_server = utf8
+
+# REPLICATION SPECIFIC
+#server_id must be unique across all mysql servers participating in replication.
+#server_id=SERVERID
+binlog_format=ROW
+#log_slave_updates=1
+#log_bin=binlog
+#relay_log=relay-bin
+#expire_logs_days=7
+#gtid_mode=ON
+#enforce_gtid_consistency=1
+# OTHER THINGS, BUFFERS ETC
+key_buffer_size = 24M
+tmp_table_size = 64M
+max_heap_table_size = 64M
+max_allowed_packet = 512M
+#sort_buffer_size = 256K
+#read_buffer_size = 256K
+#read_rnd_buffer_size = 512K
+#myisam_sort_buffer_size = 8M
+skip_name_resolve
+memlock=0
+sysdate_is_now=1
+max_connections=2000
+thread_cache_size=512
+query_cache_type = 0
+query_cache_size = 0
+table_open_cache=1024
+lower_case_table_names=0
+# 5.6 backwards compatibility
+#explicit_defaults_for_timestamp=1
+##
+## WSREP options
+##
+
+# Full path to wsrep provider library or 'none'
+wsrep_provider=/usr/lib/galera/libgalera_smm.so
+
+wsrep_node_address={{ service.bind.address }}
+# Provider specific configuration options
+wsrep_provider_options="gcache.size=8192M"
+
+# Logical cluster name. Should be the same for all nodes.
+wsrep_cluster_name="my_wsrep_cluster"
+
+# Group communication system handle
+#wsrep_cluster_address=gcomm://10.0.0.3:4567,10.0.0.4:4567,10.0.0.2:4567
+wsrep_cluster_address=gcomm://{% for member in service.members %}{{ member.host}}{% if not loop.last %},{% endif %}{% endfor %}
+
+# Human_readable node name (non-unique). Hostname by default.
+wsrep_node_name={{ service.bind.address }}
+
+# Address for incoming client connections. Autodetect by default.
+#wsrep_node_incoming_address=
+
+# How many threads will process writesets from other nodes
+wsrep_slave_threads=8
+
+# DBUG options for wsrep provider
+#wsrep_dbug_option
+
+# Generate fake primary keys for non-PK tables (required for multi-master
+# and parallel applying operation)
+wsrep_certify_nonPK=1
+
+# Location of the directory with data files. Needed for non-mysqldump
+# state snapshot transfers. Defaults to mysql_real_data_home.
+#wsrep_data_home_dir=
+
+# Maximum number of rows in write set
+wsrep_max_ws_rows=131072
+
+# Maximum size of write set
+wsrep_max_ws_size=1073741824
+
+# to enable debug level logging, set this to 1
+wsrep_debug=0
+
+# convert locking sessions into transactions
+wsrep_convert_LOCK_to_trx=0
+
+# how many times to retry deadlocked autocommits
+wsrep_retry_autocommit=1
+
+# change auto_increment_increment and auto_increment_offset automatically
+wsrep_auto_increment_control=1
+
+# replicate myisam
+wsrep_replicate_myisam=1
+# retry autoinc insert, which failed for duplicate key error
+wsrep_drupal_282555_workaround=0
+
+# enable "strictly synchronous" semantics for read operations
+wsrep_causal_reads=0
+
+# Command to call when node status or cluster membership changes.
+# Will be passed all or some of the following options:
+# --status  - new status of this node
+# --uuid    - UUID of the cluster
+# --primary - whether the component is primary or not ("yes"/"no")
+# --members - comma-separated list of members
+# --index   - index of this node in the list
+#wsrep_notify_cmd=
+
+##
+## WSREP State Transfer options
+##
+
+# State Snapshot Transfer method
+# ClusterControl currently DOES NOT support wsrep_sst_method=mysqldump
+wsrep_sst_method=xtrabackup
+
+# Address on THIS node to receive SST at. DON'T SET IT TO DONOR ADDRESS!!!
+# (SST method dependent. Defaults to the first IP of the first interface)
+#wsrep_sst_receive_address=
+
+# SST authentication string. This will be used to send SST to joining nodes.
+# Depends on SST method. For mysqldump method it is root:<root password>
+wsrep_sst_auth={{ service.admin.user }}:{{ service.admin.password }}
+
+# Desired SST donor name.
+#wsrep_sst_donor=
+
+# Protocol version to use
+# wsrep_protocol_version=
+[MYSQL]
+socket=/var/run/mysqld/mysqld.sock
+#default_character_set=utf8
+[client]
+socket=/var/run/mysqld/mysqld.sock
+default_character_set=utf8
+[mysqldump]
+max_allowed_packet = 512M
+socket=/var/run/mysqld/mysqld.sock
+default_character_set=utf8
+[MYSQLD_SAFE]
+pid_file=mysqld.pid
+log_error=/var/log/mysql.log
+basedir=/usr/
+datadir=/var/lib/mysql
diff --git a/galera/files/my.cnf.bootstrap b/galera/files/my.cnf.bootstrap
new file mode 100644
index 0000000..b5cbd93
--- /dev/null
+++ b/galera/files/my.cnf.bootstrap
@@ -0,0 +1,102 @@
+# All files in this package is subject to the GPL v2 license
+# More information is in the COPYING file in the top directory of this package.
+# Copyright (C) 2011 severalnines.com
+{%- if pillar.galera.master is defined %}
+{%- from "galera/map.jinja" import master with context %}
+{%- set service = master %}
+{%- endif %}
+{%- if pillar.galera.slave is defined %}
+{%- from "galera/map.jinja" import slave with context %}
+{%- set service = slave %}
+{%- endif %}
+[MYSQLD]
+user=mysql
+basedir=/usr/
+datadir=/var/lib/mysql
+socket=/var/run/mysqld/mysqld.sock
+pid_file=mysqld.pid
+port=3306
+log_error=/var/log/mysql.log
+log_warnings=2
+#log_output=FILE
+### INNODB OPTIONS 
+innodb_buffer_pool_size=9211M
+innodb_flush_log_at_trx_commit=2
+innodb_file_per_table=1
+innodb_data_file_path = ibdata1:100M:autoextend
+## You may want to tune the below depending on number of cores and disk sub
+innodb_read_io_threads=4
+innodb_write_io_threads=4
+innodb_io_capacity=200
+innodb_doublewrite=1
+innodb_log_file_size=1024M
+innodb_log_buffer_size=96M
+innodb_buffer_pool_instances=8
+innodb_log_files_in_group=2
+innodb_thread_concurrency=64
+#innodb_file_format=barracuda
+innodb_flush_method = O_DIRECT
+innodb_autoinc_lock_mode=2
+## avoid statistics update when doing e.g show tables
+innodb_stats_on_metadata=0
+default_storage_engine=innodb
+
+bind-address={{ service.bind.address }}
+
+# CHARACTER SET
+#collation_server = utf8_unicode_ci
+#init_connect='SET NAMES utf8'
+character_set_server = utf8
+
+# REPLICATION SPECIFIC
+#server_id must be unique across all mysql servers participating in replication.
+#server_id=SERVERID
+binlog_format=ROW
+#log_slave_updates=1
+#log_bin=binlog
+#relay_log=relay-bin
+#expire_logs_days=7
+#gtid_mode=ON
+#enforce_gtid_consistency=1
+# OTHER THINGS, BUFFERS ETC
+key_buffer_size = 24M
+tmp_table_size = 64M
+max_heap_table_size = 64M
+max_allowed_packet = 512M
+#sort_buffer_size = 256K
+#read_buffer_size = 256K
+#read_rnd_buffer_size = 512K
+#myisam_sort_buffer_size = 8M
+skip_name_resolve
+memlock=0
+sysdate_is_now=1
+max_connections=2000
+thread_cache_size=512
+query_cache_type = 0
+query_cache_size = 0
+table_open_cache=1024
+lower_case_table_names=0
+# 5.6 backwards compatibility
+#explicit_defaults_for_timestamp=1
+#
+
+# Desired SST donor name.
+#wsrep_sst_donor=
+
+# Protocol version to use
+# wsrep_protocol_version=
+[MYSQL]
+socket=/var/run/mysqld/mysqld.sock
+#default_character_set=utf8
+[client]
+socket=/var/run/mysqld/mysqld.sock
+default_character_set=utf8
+[mysqldump]
+max_allowed_packet = 512M
+socket=/var/run/mysqld/mysqld.sock
+default_character_set=utf8
+[MYSQLD_SAFE]
+pid_file=mysqld.pid
+log_error=/var/log/mysql.log
+basedir=/usr/
+datadir=/var/lib/mysql
diff --git a/galera/files/my.cnf.init b/galera/files/my.cnf.init
new file mode 100644
index 0000000..97ece92
--- /dev/null
+++ b/galera/files/my.cnf.init
@@ -0,0 +1,188 @@
+# All files in this package is subject to the GPL v2 license
+# More information is in the COPYING file in the top directory of this package.
+# Copyright (C) 2011 severalnines.com
+{%- if pillar.galera.master is defined %}
+{%- from "galera/map.jinja" import master with context %}
+{%- set service = master %}
+{%- endif %}
+{%- if pillar.galera.slave is defined %}
+{%- from "galera/map.jinja" import slave with context %}
+{%- set service = slave %}
+{%- endif %}
+[MYSQLD]
+user=mysql
+basedir=/usr/
+datadir=/var/lib/mysql
+socket=/var/run/mysqld/mysqld.sock
+pid_file=mysqld.pid
+port=3306
+log_error=/var/log/mysql.log
+log_warnings=2
+#log_output=FILE
+### INNODB OPTIONS 
+innodb_buffer_pool_size=9211M
+innodb_flush_log_at_trx_commit=2
+innodb_file_per_table=1
+innodb_data_file_path = ibdata1:100M:autoextend
+## You may want to tune the below depending on number of cores and disk sub
+innodb_read_io_threads=4
+innodb_write_io_threads=4
+innodb_io_capacity=200
+innodb_doublewrite=1
+innodb_log_file_size=1024M
+innodb_log_buffer_size=96M
+innodb_buffer_pool_instances=8
+innodb_log_files_in_group=2
+innodb_thread_concurrency=64
+#innodb_file_format=barracuda
+innodb_flush_method = O_DIRECT
+innodb_autoinc_lock_mode=2
+## avoid statistics update when doing e.g show tables
+innodb_stats_on_metadata=0
+default_storage_engine=innodb
+
+bind-address={{ service.bind.address }}
+
+# CHARACTER SET
+#collation_server = utf8_unicode_ci
+#init_connect='SET NAMES utf8'
+character_set_server = utf8
+
+# REPLICATION SPECIFIC
+#server_id must be unique across all mysql servers participating in replication.
+#server_id=SERVERID
+binlog_format=ROW
+#log_slave_updates=1
+#log_bin=binlog
+#relay_log=relay-bin
+#expire_logs_days=7
+#gtid_mode=ON
+#enforce_gtid_consistency=1
+# OTHER THINGS, BUFFERS ETC
+key_buffer_size = 24M
+tmp_table_size = 64M
+max_heap_table_size = 64M
+max_allowed_packet = 512M
+#sort_buffer_size = 256K
+#read_buffer_size = 256K
+#read_rnd_buffer_size = 512K
+#myisam_sort_buffer_size = 8M
+skip_name_resolve
+memlock=0
+sysdate_is_now=1
+max_connections=2000
+thread_cache_size=512
+query_cache_type = 0
+query_cache_size = 0
+table_open_cache=1024
+lower_case_table_names=0
+# 5.6 backwards compatibility
+#explicit_defaults_for_timestamp=1
+##
+## WSREP options
+##
+
+# Full path to wsrep provider library or 'none'
+wsrep_provider=/usr/lib/galera/libgalera_smm.so
+
+wsrep_node_address={{ service.bind.address }}
+# Provider specific configuration options
+wsrep_provider_options="gcache.size=8192M"
+
+# Logical cluster name. Should be the same for all nodes.
+wsrep_cluster_name="my_wsrep_cluster"
+
+# Group communication system handle
+wsrep_cluster_address=gcomm://
+
+# Human_readable node name (non-unique). Hostname by default.
+wsrep_node_name={{ service.bind.address }}
+
+# Address for incoming client connections. Autodetect by default.
+#wsrep_node_incoming_address=
+
+# How many threads will process writesets from other nodes
+wsrep_slave_threads=8
+
+# DBUG options for wsrep provider
+#wsrep_dbug_option
+
+# Generate fake primary keys for non-PK tables (required for multi-master
+# and parallel applying operation)
+wsrep_certify_nonPK=1
+
+# Location of the directory with data files. Needed for non-mysqldump
+# state snapshot transfers. Defaults to mysql_real_data_home.
+#wsrep_data_home_dir=
+
+# Maximum number of rows in write set
+wsrep_max_ws_rows=131072
+
+# Maximum size of write set
+wsrep_max_ws_size=1073741824
+
+# to enable debug level logging, set this to 1
+wsrep_debug=0
+
+# convert locking sessions into transactions
+wsrep_convert_LOCK_to_trx=0
+
+# how many times to retry deadlocked autocommits
+wsrep_retry_autocommit=1
+
+# change auto_increment_increment and auto_increment_offset automatically
+wsrep_auto_increment_control=1
+
+# replicate myisam
+wsrep_replicate_myisam=1
+# retry autoinc insert, which failed for duplicate key error
+wsrep_drupal_282555_workaround=0
+
+# enable "strictly synchronous" semantics for read operations
+wsrep_causal_reads=0
+
+# Command to call when node status or cluster membership changes.
+# Will be passed all or some of the following options:
+# --status  - new status of this node
+# --uuid    - UUID of the cluster
+# --primary - whether the component is primary or not ("yes"/"no")
+# --members - comma-separated list of members
+# --index   - index of this node in the list
+#wsrep_notify_cmd=
+
+##
+## WSREP State Transfer options
+##
+
+# State Snapshot Transfer method
+# ClusterControl currently DOES NOT support wsrep_sst_method=mysqldump
+wsrep_sst_method=xtrabackup
+
+# Address on THIS node to receive SST at. DON'T SET IT TO DONOR ADDRESS!!!
+# (SST method dependent. Defaults to the first IP of the first interface)
+#wsrep_sst_receive_address=
+
+# SST authentication string. This will be used to send SST to joining nodes.
+# Depends on SST method. For mysqldump method it is root:<root password>
+wsrep_sst_auth={{ service.admin.user }}:{{ service.admin.password }}
+
+# Desired SST donor name.
+#wsrep_sst_donor=
+
+# Protocol version to use
+# wsrep_protocol_version=
+[MYSQL]
+socket=/var/run/mysqld/mysqld.sock
+#default_character_set=utf8
+[client]
+socket=/var/run/mysqld/mysqld.sock
+default_character_set=utf8
+[mysqldump]
+max_allowed_packet = 512M
+socket=/var/run/mysqld/mysqld.sock
+default_character_set=utf8
+[MYSQLD_SAFE]
+pid_file=mysqld.pid
+log_error=/var/log/mysql.log
+basedir=/usr/
+datadir=/var/lib/mysql
diff --git a/galera/init.sls b/galera/init.sls
new file mode 100644
index 0000000..e5cf861
--- /dev/null
+++ b/galera/init.sls
@@ -0,0 +1,10 @@
+
+{%- if pillar.galera is defined %}
+include:
+{%- if pillar.galera.master is defined %}
+- galera.master
+{%- endif %}
+{%- if pillar.galera.slave is defined %}
+- galera.slave
+{%- endif %}
+{%- endif %}
diff --git a/galera/map.jinja b/galera/map.jinja
new file mode 100644
index 0000000..48896de
--- /dev/null
+++ b/galera/map.jinja
@@ -0,0 +1,24 @@
+
+{%- set master = salt['grains.filter_by']({
+  'Debian': {
+    'pkgs': ['mysql-server-wsrep', 'galera', 'rsync', 'python-mysqldb', 'libmysqlclient18', 'psmisc', 'netcat', 'percona-xtrabackup-21', 'socat'],
+    'service': 'mysql',
+    'config': '/etc/mysql/conf.d/wsrep.cnf',
+  },
+  'RedHat': {
+    'pkgs': ['MySQL-server', 'galera', 'MySQL-client', 'MySQL-python', 'rsync'],
+    'service': 'mysql',
+  },
+}, merge=salt['pillar.get']('galera:master')) %}
+
+{%- set slave = salt['grains.filter_by']({
+  'Debian': {
+    'pkgs': ['mysql-server-wsrep', 'galera', 'rsync', 'python-mysqldb', 'libmysqlclient18', 'psmisc', 'netcat', 'percona-xtrabackup-21', 'socat'],
+    'service': 'mysql',
+    'config': '/etc/mysql/conf.d/wsrep.cnf',
+  },
+  'RedHat': {
+    'pkgs': ['MySQL-server', 'galera', 'MySQL-client', 'MySQL-python', 'rsync'],
+    'service': 'mysql',
+  },
+}, merge=salt['pillar.get']('galera:slave')) %}
diff --git a/galera/master.sls b/galera/master.sls
new file mode 100644
index 0000000..f9525bd
--- /dev/null
+++ b/galera/master.sls
@@ -0,0 +1,88 @@
+{%- from "galera/map.jinja" import master with context %}
+{%- if master.enabled %}
+
+{%- if grains.os_family == "Debian2" %}
+
+galera_debconf:
+  debconf.set:
+  - name: mariadb-galera-server
+  - data:
+      'mysql-server/root_password': {'type':'string','value':'{{ server.admin.password }}'}
+      'mysql-server/root_password_again': {'type':'string','value':'{{ server.admin.password }}'}
+  - require_in:
+    - pkg: galera_packages
+
+{%- endif %}
+
+galera_packages:
+  pkg.installed:
+  - names: {{ master.pkgs }}
+
+galera_log_dir:
+  file.directory:
+  - name: /var/log/mysql
+  - makedirs: true
+  - mode: 755
+  - require:
+    - pkg: galera_packages
+
+{%- if not salt['cmd.run']('test -e /root/.galera_bootstrap') %}
+
+galera_bootstrap_temp_config:
+  file.managed:
+  - name: {{ master.config }}
+  - source: salt://mysql/files/my.cnf.bootstrap
+  - mode: 644
+  - template: jinja
+  - require: 
+    - pkg: galera_packages
+
+galera_bootstrap_start_service:
+  service.running:
+  - name: mysql
+  - require: 
+    - file: galera_bootstrap_temp_config
+
+galera_bootstrap_set_root_password:
+  cmd.run:
+  - name: mysqladmin password "{{ master.admin.password }}"
+  - require:
+    - service: galera_bootstrap_start_service
+
+mysql_bootstrap_update_maint_password:
+  cmd.run:
+  - name: mysql -u root -p{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.maintenance_password }}';"
+  - require:
+    - cmd: galera_bootstrap_set_root_password
+
+galera_packages_bootstrap_stop_service:
+  service.dead:
+  - name: mysql
+  - require:
+    - cmd: mysql_bootstrap_update_maint_password
+
+galera_bootstrap_init_config:
+  file.managed:
+  - name: {{ master.config }}
+  - source: salt://mysql/conf/my.cnf
+  - mode: 644
+  - template: jinja
+  - require: 
+    - service: galera_bootstrap_stop_service
+
+galera_bootstrap_temp_config:
+  file.touch:
+  - require:
+    - file: galera_bootstrap_init_config
+  - watch_in:
+    - service: galera_service
+
+{%- endif %}
+
+galera_service:
+  service.running:
+  - name: {{ master.service }}
+  - enable: true
+  - reload: true
+
+{%- endif %}
\ No newline at end of file
diff --git a/galera/slave.sls b/galera/slave.sls
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/galera/slave.sls
diff --git a/metadata/galera/service/master/cluster.yml b/metadata/galera/service/master/cluster.yml
new file mode 100644
index 0000000..69fe5d1
--- /dev/null
+++ b/metadata/galera/service/master/cluster.yml
@@ -0,0 +1,19 @@
+applications:
+- galera
+parameters:
+  _param:
+    galera_server_cluster_name: galeracluster
+    galera_server_bind_address: 0.0.0.0
+    galera_server_bind_port: 0.0.0.0
+    galera_server_admin_user: root
+    galera_server_admin_password: root
+  galera:
+    master:
+      enabled: true
+      name: ${_param:galera_server_cluster_name}
+      bind:
+        address: ${_param:galera_server_bind_address}
+        port: ${_param:galera_server_bind_port}
+      admin:
+        user: ${_param:galera_server_admin_user}
+        password: ${_param:galera_server_admin_password}
diff --git a/metadata/galera/service/slave/cluster.yml b/metadata/galera/service/slave/cluster.yml
new file mode 100644
index 0000000..6289325
--- /dev/null
+++ b/metadata/galera/service/slave/cluster.yml
@@ -0,0 +1,19 @@
+applications:
+- galera
+parameters:
+  _param:
+    galera_server_cluster_name: galeracluster
+    galera_server_bind_address: 0.0.0.0
+    galera_server_bind_port: 0.0.0.0
+    galera_server_admin_user: root
+    galera_server_admin_password: root
+  galera:
+    slave:
+      enabled: true
+      name: ${_param:galera_server_cluster_name}
+      bind:
+        address: ${_param:galera_server_bind_address}
+        port: ${_param:galera_server_bind_port}
+      admin:
+        user: ${_param:galera_server_admin_user}
+        password: ${_param:galera_server_admin_password}