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
""" server.py: generic server object used by the server
23
manager. This contains the generic methods for all
24
servers. Specific types (Drizzle, MySQL, etc) should
33
""" the server class from which other servers
34
will inherit - contains generic methods
35
certain methods will be overridden by more
43
, default_storage_engine
47
self.skip_keys = [ 'server_manager'
50
, 'preferred_base_port'
51
, 'no_secure_file_priv'
52
, 'secure_file_string'
55
self.debug = server_manager.debug
56
self.verbose = server_manager.verbose
58
self.owner = requester
59
self.server_options = server_options
60
self.default_storage_engine = default_storage_engine
61
self.server_manager = server_manager
62
# We register with server_manager asap
63
self.server_manager.log_server(self, requester)
65
self.system_manager = self.server_manager.system_manager
66
self.valgrind = self.system_manager.valgrind
67
self.gdb = self.system_manager.gdb
69
self.valgrind_time_buffer = 10
71
self.valgrind_time_buffer = 1
72
self.cmd_prefix = self.system_manager.cmd_prefix
73
self.logging = self.system_manager.logging
74
self.no_secure_file_priv = self.server_manager.no_secure_file_priv
76
self.status = 0 # stopped, 1 = running
78
self.failed_test = 0 # was the last test a failure? our state is suspect
79
self.server_start_timeout = 60 * self.valgrind_time_buffer
81
self.need_reset = False
83
def initialize_databases(self):
84
""" Call schemawriter to make db.opt files """
88
for database in databases:
89
db_path = os.path.join(self.datadir,'local',database,'db.opt')
90
cmd = "%s %s %s" %(self.schemawriter, database, db_path)
91
self.system_manager.execute_cmd(cmd)
93
def process_server_options(self):
94
"""Consume the list of options we have been passed.
95
Return a string with them joined
99
return " ".join(self.server_options)
101
def take_db_snapshot(self):
102
""" Take a snapshot of our vardir for quick restores """
104
self.logging.info("Taking clean db snapshot...")
105
if os.path.exists(self.snapshot_path):
106
# We need to remove an existing path as python shutil
107
# doesn't want an existing target
108
self.system_manager.remove_dir(self.snapshot_path)
109
self.system_manager.copy_dir(self.datadir, self.snapshot_path)
111
def restore_snapshot(self):
112
""" Restore from a stored snapshot """
115
self.logging.verbose("Restoring from db snapshot")
116
if not os.path.exists(self.snapshot_path):
117
self.logging.error("Could not find snapshot: %s" %(self.snapshot_path))
118
self.system_manager.remove_dir(self.datadir)
119
self.system_manager.copy_dir(self.snapshot_path, self.datadir)
121
def is_started(self):
122
""" Is the server running? Particulars are server-dependent """
126
def get_start_cmd(self):
127
""" Return the command the server_manager can use to start me """
131
def get_stop_cmd(self):
132
""" Return the command the server_manager can use to stop me """
134
return "Whoa, Nelly!"
136
def get_ping_cmd(self):
137
""" Return the command that can be used to 'ping' me
138
Very similar to is_started, but different
140
Determining if a server is still running (ping)
141
may differ from the method used to determine
149
""" Cleanup - just free ports for now..."""
150
self.system_manager.port_manager.free_ports(self.port_block)
152
def set_server_options(self, server_options):
153
""" We update our server_options to the new set """
154
self.server_options = server_options
157
""" Voodoo to reset ourselves """