2
# -*- mode: c; c-basic-offset: 2; 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
def initialize_databases(self):
82
""" Call schemawriter to make db.opt files """
86
for database in databases:
87
db_path = os.path.join(self.datadir,'local',database,'db.opt')
88
cmd = "%s %s %s" %(self.schemawriter, database, db_path)
89
self.system_manager.execute_cmd(cmd)
91
def process_server_options(self):
92
"""Consume the list of options we have been passed.
93
Return a string with them joined
97
return " ".join(self.server_options)
99
def take_db_snapshot(self):
100
""" Take a snapshot of our vardir for quick restores """
102
self.logging.info("Taking clean db snapshot...")
103
if os.path.exists(self.snapshot_path):
104
# We need to remove an existing path as python shutil
105
# doesn't want an existing target
106
self.system_manager.remove_dir(self.snapshot_path)
107
self.system_manager.copy_dir(self.datadir, self.snapshot_path)
109
def restore_snapshot(self):
110
""" Restore from a stored snapshot """
113
self.logging.verbose("Restoring from db snapshot")
114
if not os.path.exists(self.snapshot_path):
115
self.logging.error("Could not find snapshot: %s" %(self.snapshot_path))
116
self.system_manager.remove_dir(self.datadir)
117
self.system_manager.copy_dir(self.snapshot_path, self.datadir)
119
def is_started(self):
120
""" Is the server running? Particulars are server-dependent """
124
def get_start_cmd(self):
125
""" Return the command the server_manager can use to start me """
129
def get_stop_cmd(self):
130
""" Return the command the server_manager can use to stop me """
132
return "Whoa, Nelly!"
134
def get_ping_cmd(self):
135
""" Return the command that can be used to 'ping' me
136
Very similar to is_started, but different
138
Determining if a server is still running (ping)
139
may differ from the method used to determine
147
""" Cleanup - just free ports for now..."""
148
self.system_manager.port_manager.free_ports(self.port_block)
150
def set_server_options(self, server_options):
151
""" We update our server_options to the new set """
152
self.server_options = server_options
155
""" Voodoo to reset ourselves """