2
# -*- mode: python; indent-tabs-mode: nil; -*-
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5
# Copyright (C) 2010,2011 Patrick Crews
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
""" mysqld.py: code to allow a serverManager
23
to provision and start up a mysqld server object
30
from lib.server_mgmt.server import Server
32
class mysqlServer(Server):
33
""" represents a mysql server, its possessions
34
(datadir, ports, etc), and methods for controlling
37
TODO: create a base server class that contains
38
standard methods from which we can inherit
39
Currently there are definitely methods / attr
44
def __init__( self, name, server_manager, code_tree, default_storage_engine
45
, server_options, requester, workdir_root):
46
super(drizzleServer, self).__init__( name
49
, default_storage_engine
53
self.preferred_base_port = 9306
56
self.drizzledump = self.code_tree.drizzledump
57
self.drizzle_client = self.code_tree.drizzle_client
58
self.drizzleimport = self.code_tree.drizzleimport
59
self.drizzleslap = self.code_tree.drizzleslap
60
self.server_path = self.code_tree.drizzle_server
61
self.drizzle_client_path = self.code_tree.drizzle_client
62
self.schemawriter = self.code_tree.schemawriter
63
self.trx_reader = self.code_tree.trx_reader
66
self.port_block = self.system_manager.port_manager.get_port_block( self.name
67
, self.preferred_base_port
69
self.master_port = self.port_block[0]
70
self.drizzle_tcp_port = self.port_block[1]
71
self.mc_port = self.port_block[2]
72
self.pbms_port = self.port_block[3]
73
self.rabbitmq_node_port = self.port_block[4]
74
self.json_server_port = self.port_block[5]
76
# Generate our working directories
77
self.dirset = { self.name : { 'var': {'std_data_ln':( os.path.join(self.code_tree.testdir,'std_data'))
81
,'master-data': {'local': { 'test':None
88
self.workdir = self.system_manager.create_dirset( workdir_root
90
self.vardir = os.path.join(self.workdir,'var')
91
self.tmpdir = os.path.join(self.vardir,'tmp')
92
self.rundir = os.path.join(self.vardir,'run')
93
self.logdir = os.path.join(self.vardir,'log')
94
self.datadir = os.path.join(self.vardir,'master-data')
96
self.error_log = os.path.join(self.logdir,('%s.err' %(self.name)))
97
self.pid_file = os.path.join(self.rundir,('%s.pid' %(self.name)))
98
self.socket_file = os.path.join(self.vardir, ('%s.sock' %(self.name)))
99
self.timer_file = os.path.join(self.logdir,('timer'))
101
# Do magic to create a config file for use with the slave
103
self.slave_config_file = os.path.join(self.logdir,'slave.cnf')
104
self.create_slave_config_file()
106
self.snapshot_path = os.path.join(self.tmpdir,('snapshot_%s' %(self.master_port)))
107
# We want to use --secure-file-priv = $vardir by default
108
# but there are times / tools when we need to shut this off
109
if self.no_secure_file_priv:
110
self.secure_file_string = ''
112
self.secure_file_string = "--secure-file-priv='%s'" %(self.vardir)
113
self.user_string = '--user=root'
115
self.initialize_databases()
116
self.take_db_snapshot()
118
self.logging.debug_class(self)
121
""" We print out some general useful info """
122
report_values = [ 'name'
127
, 'rabbitmq_node_port'
131
self.logging.info("%s server:" %(self.owner))
132
for key in report_values:
133
value = vars(self)[key]
134
self.logging.info("%s: %s" %(key.upper(), value))
136
def get_start_cmd(self):
137
""" Return the command string that will start up the server
138
as desired / intended
142
server_args = [ self.process_server_options()
143
, "--mysql-protocol.port=%d" %(self.master_port)
144
, "--mysql-protocol.connect-timeout=60"
145
, "--innodb.data-file-path=ibdata1:20M:autoextend"
146
, "--sort-buffer-size=256K"
147
, "--max-heap-table-size=1M"
148
, "--mysql-unix-socket-protocol.path=%s" %(self.socket_file)
149
, "--pid-file=%s" %(self.pid_file)
150
, "--drizzle-protocol.port=%d" %(self.drizzle_tcp_port)
151
, "--default-storage-engine=%s" %(self.default_storage_engine)
152
, "--datadir=%s" %(self.datadir)
153
, "--tmpdir=%s" %(self.tmpdir)
154
, self.secure_file_string
159
server_args.append('--gdb')
160
return self.system_manager.handle_gdb_reqs(self, server_args)
162
return "%s %s %s & " % ( self.cmd_prefix
164
, " ".join(server_args)
168
def get_stop_cmd(self):
169
""" Return the command that will shut us down """
171
return "%s --user=root --port=%d --connect-timeout=5 --silent --password= --shutdown " %(self.drizzle_client_path, self.master_port)
174
def get_ping_cmd(self):
175
"""Return the command string that will
176
ping / check if the server is alive
180
return "%s --ping --port=%d --user=root" % (self.drizzle_client_path, self.master_port)
182
def is_started(self):
183
""" Determine if the server is up and running -
184
this may vary from server type to server type
188
# We experiment with waiting for a pid file to be created vs. pinging
189
# This is what test-run.pl does and it helps us pass logging_stats tests
190
# while not self.ping_server(server, quiet=True) and timer != timeout:
192
return self.system_manager.find_path( [self.pid_file]