-
Notifications
You must be signed in to change notification settings - Fork 1
/
mysql.py
107 lines (82 loc) · 3.52 KB
/
mysql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python
import os
import glob
import sys
import time
from fabric.api import *
from fabric.contrib import *
from fabric.colors import *
import jinja2
import MySQLdb
sys.path.append(os.getcwd() + "/lib")
from daemonMysql import Mysql
@task
def help():
print (green("""
# Description
This cook will be cook the MySQL.
He can do install, update, remove, start, stop, restart, configure of
a single server and set replication master-slave, master-master.
# Default settings is character=utf8, skip_networking=0, version=5.1
"""+blue("""
# Get list of methods
fab -f mysql.py -l
# Install a single server with the default settings
fab -f mysql.py single -H lab1rhce -u root -pteligent
# Install a single server with specified settings:
# character=latin1,version=5.1,skip_networking=1
fab -f mysql.py single:character=latin1,version=5.1,skip_networking=1 -H lab1rhce -u root -pteligent
# Install master-slave with the default settings
fab -f mysql.py single -P -H lab1rhce,lab2rhce -u root -pteligent
fab -f mysql.py master_slave:slave=lab2rhce,master=lab1rhce
# Install master-slave with specified settings:
# character=latin1
fab -f mysql.py single:character=latin1 -P -H lab1rhce,lab2rhce -u root -pteligent
fab -f mysql.py master_slave:slave=lab2rhce,master=lab1rhce
# Install master-master with the default settings
fab -f mysql.py single -P -H lab1rhce,lab2rhce -u root -pteligent
fab -f mysql.py master_master:lab1rhce,lab2rhce
# Install master-master with specified settings:
# character=latin1
fab -f mysql.py single:character=latin1 -P -H lab1rhce,lab2rhce -u root -pteligent
fab -f mysql.py master_master:lab1rhce,lab2rhce
# Manual start MySQL
fab -f mysql.py init:start -P -H lab1,lab2 -u root -p password
# Manual stop MySQL
fab -f mysql.py init:stop -P -H lab1,lab2 -u root -p password
# Manual restart MySQL
fab -f mysql.py init:restart -P -H lab1,lab2 -u root -p password
# Manual remove MySQL
fab -f mysql.py init:remove -P -H lab1,lab2 -u root -p password
# Manual update MySQL
fab -f mysql.py init:update -P -H lab1,lab2 -u root -p password
# Manual install MySQL
fab -f mysql.py init:install -P -H lab1,lab2 -u root -p password
""")))
@task
def single(character="utf8",skip_networking="0",version="5.1"):
mysql=Mysql(name="mysqld", config="/etc")
mysql.yum("mysql mysql-server", "install")
mysql.single(character=character,skip_networking=skip_networking,version=version)
mysql.chkconfig("on")
mysql.init("start")
mysql.postinstall()
@task
def master_slave(master,slave):
mysql=Mysql(name="mysqld", config="/etc", type=None)
mysql.get_master_info(master)
mysql.set_replication(slave)
@task
def master_master(master,slave):
mysql=Mysql(name="mysqld", config="/etc", type=None)
mysql.get_master_info(master)
if mysql.set_replication(slave) == 0:
mysql.get_master_info(slave)
mysql.set_replication(master)
@task
def init(action):
mysql=Mysql(name="mysqld", config="/etc")
if action == "start" or action == "restart" or action == "stop":
mysql.init(action)
if action == "remove" or action == "install" or action == "update":
mysql.yum("mysql mysql-server",action)