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
44
, default_storage_engine
48
self.skip_keys = [ 'server_manager'
51
, 'preferred_base_port'
52
, 'no_secure_file_priv'
53
, 'secure_file_string'
56
self.debug = server_manager.debug
57
self.verbose = server_manager.verbose
59
self.owner = requester
60
self.server_options = server_options
61
self.default_storage_engine = default_storage_engine
62
self.server_manager = server_manager
63
# We register with server_manager asap
64
self.server_manager.log_server(self, requester)
66
self.system_manager = self.server_manager.system_manager
67
self.code_tree = code_tree
68
self.valgrind = self.system_manager.valgrind
69
self.gdb = self.system_manager.gdb
71
self.valgrind_time_buffer = 10
73
self.valgrind_time_buffer = 1
74
self.cmd_prefix = self.system_manager.cmd_prefix
75
self.logging = self.system_manager.logging
76
self.no_secure_file_priv = self.server_manager.no_secure_file_priv
78
self.status = 0 # stopped, 1 = running
80
self.failed_test = 0 # was the last test a failure? our state is suspect
81
self.server_start_timeout = 60 * self.valgrind_time_buffer
83
self.need_reset = False
85
def initialize_databases(self):
86
""" Call schemawriter to make db.opt files """
90
for database in databases:
91
db_path = os.path.join(self.datadir,'local',database,'db.opt')
92
cmd = "%s %s %s" %(self.schemawriter, database, db_path)
93
self.system_manager.execute_cmd(cmd)
95
def process_server_options(self):
96
"""Consume the list of options we have been passed.
97
Return a string with them joined
101
return " ".join(self.server_options)
103
def take_db_snapshot(self):
104
""" Take a snapshot of our vardir for quick restores """
106
self.logging.info("Taking clean db snapshot...")
107
if os.path.exists(self.snapshot_path):
108
# We need to remove an existing path as python shutil
109
# doesn't want an existing target
110
self.system_manager.remove_dir(self.snapshot_path)
111
self.system_manager.copy_dir(self.datadir, self.snapshot_path)
113
def restore_snapshot(self):
114
""" Restore from a stored snapshot """
116
self.logging.verbose("Restoring from db snapshot")
117
if not os.path.exists(self.snapshot_path):
118
self.logging.error("Could not find snapshot: %s" %(self.snapshot_path))
119
self.system_manager.remove_dir(self.datadir)
120
self.system_manager.copy_dir(self.snapshot_path, self.datadir)
122
def is_started(self):
123
""" Is the server running? Particulars are server-dependent """
125
return "You need to implement is_started"
127
def get_start_cmd(self):
128
""" Return the command the server_manager can use to start me """
130
return "You need to implement get_start_cmd"
132
def get_stop_cmd(self):
133
""" Return the command the server_manager can use to stop me """
135
return "You need to implement get_stop_cmd"
137
def get_ping_cmd(self):
138
""" Return the command that can be used to 'ping' me
139
Very similar to is_started, but different
141
Determining if a server is still running (ping)
142
may differ from the method used to determine
147
return "You need to implement get_ping_cmd"
150
""" Cleanup - just free ports for now..."""
151
self.system_manager.port_manager.free_ports(self.port_block)
153
def set_server_options(self, server_options):
154
""" We update our server_options to the new set """
155
self.server_options = server_options
158
""" Voodoo to reset ourselves """