Forked from Slach/pinba_with_mysql5.6_ubuntu_15.04_fabric.py
Created
May 23, 2018 14:12
-
-
Save yaowenqiang/a0686c9f7bc23512bfc3a7c2dd50f3ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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