Skip to content

Instantly share code, notes, and snippets.

@Slach
Last active August 31, 2018 09:18
Show Gist options
  • Save Slach/d61acbd153ea6d3e6c2b to your computer and use it in GitHub Desktop.
Save Slach/d61acbd153ea6d3e6c2b to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -
import cuisine
from fabric.contrib.project import rsync_project as fabric_rsync_project
from fabric.utils import abort as fabric_abort
from fabric import (
api,
)
def git_clone_or_pull(sudo_user, base_dir, git_url, branch='master', git_email='your@email', git_user='build'):
with api.settings(sudo_user=sudo_user):
if not cuisine.dir_exists(base_dir + '/.git'):
api.sudo('git clone %s %s' % (git_url, base_dir))
with api.cd(base_dir):
api.sudo('git checkout %s' % branch)
else:
with api.cd(base_dir):
api.sudo('git config user.email "%s"' % git_email)
api.sudo('git config user.name "%s"' % git_user)
api.sudo('git checkout %s' % branch)
with api.settings(warn_only=True):
api.sudo('git add *')
api.sudo('git commit -s -m "melesta automerge commit"')
api.sudo('git pull --rebase origin %s' % branch)
# for configure pinba run
# see https://github.com/tony2001/pinba_engine/wiki/Configuration
# nano /etc/mysql/conf.d/pinba.cnf
@api.task
def install_pinba():
cuisine.package_ensure((
'git',
'libncurses5-dev',
'libprotobuf-dev',
'libjemalloc-dev',
'libjemalloc1',
'libjudy-dev',
'libjudydebian1',
'protobuf-compiler',
'automake',
'autoconf',
'libprotobuf-lite9',
'libevent-dev',
'libevent-2.0-5',
'libevent-core-2.0-5',
'libevent-core-2.0-5',
'libevent-extra-2.0-5',
'libevent-openssl-2.0-5',
'libevent-pthreads-2.0-5',
'libboost-all-dev',
'cmake',
'mysql-server-5.6',
))
mysql_version=api.sudo('mysql --version | cut -d " " -f 6 | cut -d "," -f 1')
with cuisine.mode_sudo():
cuisine.dir_ensure('/opt/mysql_server_source',mode='0777')
mysql_dir = '/opt/mysql_server_source/mysql-5.6-%s' % mysql_version
api.sudo('cd /opt/mysql_server_source && apt-get source mysql-server-5.6')
api.sudo('cd %s && cmake ./' % mysql_dir)
git_clone_or_pull('root','/opt/pinba_mysql_engine/','https://github.com/tony2001/pinba_engine.git')
with api.cd('/opt/pinba_mysql_engine/'):
api.sudo('./buildconf.sh')
api.sudo('./configure --with-mysql=%s --libdir=/usr/lib/mysql/plugin' % mysql_dir)
api.sudo('make install')
pinba_installed = api.sudo(
'mysql --defaults-file=/etc/mysql/debian.cnf -e "SHOW STORAGE ENGINES;" | grep -i pinba | wc -l'
)
if pinba_installed == '0':
api.sudo('mysql --defaults-file=/etc/mysql/debian.cnf -e "INSTALL PLUGIN pinba SONAME \'libpinba_engine.so\';"')
pinba_installed = api.sudo(
'mysql --defaults-file=/etc/mysql/debian.cnf -e "SHOW STORAGE ENGINES;" | grep -i pinba | wc -l'
)
if pinba_installed == '0':
fabric_abort('Pinba Engine installation FAILED')
pinba_database_exists = api.sudo(
'mysql --defaults-file=/etc/mysql/debian.cnf -e "SHOW DATABASES;" | grep -i pinba | wc -l'
)
if pinba_database_exists == '0':
api.sudo('mysql --defaults-file=/etc/mysql/debian.cnf -e "CREATE DATABASE IF NOT EXISTS pinba;"')
api.sudo('mysql --defaults-file=/etc/mysql/debian.cnf pinba < default_tables.sql')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment