Skip to content

Instantly share code, notes, and snippets.

@philipsoutham
Last active July 25, 2016 21:14
Show Gist options
  • Save philipsoutham/a4bb7c3d190a74a8092c to your computer and use it in GitHub Desktop.
Save philipsoutham/a4bb7c3d190a74a8092c to your computer and use it in GitHub Desktop.
cloud-config for provisioning MariaDB on CoreOS
#cloud-config
coreos:
etcd:
addr: $private_ipv4:4001
peer-addr: $private_ipv4:7001
discovery: https://discovery.etcd.io/<token>
fleet:
public-ip: $private_ipv4
units:
- name: format-ephemeral.service
command: start
content: |
[Unit]
Description=Formats the ephemeral drive
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/wipefs -f /dev/xvdb
ExecStart=/usr/sbin/mkfs.btrfs -f /dev/xvdb
- name: mnt.mount
command: start
content: |
[Unit]
Description=Mount ephemeral to /mnt
Requires=format-ephemeral.service
After=format-ephemeral.service
Before=subvolume-ephemeral.service
[Mount]
What=/dev/xvdb
Where=/mnt
Type=btrfs
- name: subvolume-ephemeral.service
command: start
content: |
[Unit]
Description=Subvolumes the ephemeral drive
Requires=mnt.mount
After=mnt.mount
Before=var-lib-docker.mount
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/btrfs subvolume create /mnt/mysql
- name: var-lib-mysql.mount
command: start
content: |
[Unit]
Description=Mount ephemeral to /var/lib/mysql
Requires=subvolume-ephemeral.service
After=subvolume-ephemeral.service
Before=init-mariadb.service
[Mount]
What=/dev/xvdb
Where=/var/lib/mysql
Type=btrfs
Options=subvol=mysql
- name: init-mariadb.service
command: start
content: |
[Unit]
Description=Initializes MariaDB
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/docker pull psoutham/mariadb
ExecStart=/usr/bin/docker run --rm -it --name mysql -v /var/lib/mysql:/var/lib/mysql psoutham/mariadb mysql_install_db
ExecStart=/usr/bin/docker run --rm -it -v /var/lib/mysql:/var/lib/mysql --name mysql psoutham/mariadb /bin/sh -c "(mysqld_safe&) && mysqladmin --silent --wait=30 ping || exit 1 && mysql -e 'GRANT ALL PRIVILEGES ON *.* TO \"root\"@\"%\";'"
- name: mariadb.service
command: start
content: |
[Unit]
Description=MariaDB
Requires=init-mariadb.service docker.service
After=init-mariadb.service docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill mysql
ExecStartPre=-/usr/bin/docker rm mysql
ExecStartPre=/bin/sh -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled"
ExecStartPre=/bin/sh -c "echo never > /sys/kernel/mm/transparent_hugepage/defrag"
ExecStartPre=/usr/bin/docker pull psoutham/mariadb
ExecStart=/usr/bin/docker run --rm -v /var/lib/mysql:/var/lib/mysql --name mysql -p 3306:3306 psoutham/mariadb
ExecStop=-/usr/bin/docker run --link=mysql:db --rm -it --name mysql_client psoutham/mariadb /bin/sh -c 'mysqladmin -u root -h $DB_PORT_3306_TCP_ADDR -P $DB_PORT_3306_TCP_PORT shutdown && sleep 6'
ExecStop=-/usr/bin/docker stop mysql
- name: etcd.service
command: start
- name: fleet.service
command: start
@philipsoutham
Copy link
Author

This will nuke your data upon reboot.

@arkaitzmugica
Copy link

On DigitalOcean:

Failed Units: 2
format-ephemeral.service
init-mariadb.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment