Skip to content
Snippets Groups Projects
Commit bb4c1632 authored by Michael DM Dryden's avatar Michael DM Dryden
Browse files

Fix path resolution and storing process state.

parent 0a669401
No related merge requests found
Pipeline #36 skipped
......@@ -34,6 +34,8 @@ logger = logging.getLogger(__name__)
package_directory = os.path.dirname(os.path.abspath(__file__))
conf_file = os.path.join(package_directory, 'server_conf.xml')
process = None
class InputError(Exception):
"""Exception raised for errors in the input.
......@@ -89,15 +91,20 @@ class DbConnection(object):
Arguments:
port: port to connect to
"""
def __init__(self, port=9998, data_path=expanduser('~/.mr_db')):
def __init__(self, port=9998, root_dir=None):
addr = ('localhost', port)
full_path = os.path.abspath("%s/blob" % data_path)
if root_dir is None:
root_dir = expanduser('~/.mr_db')
root_dir = expanduser(root_dir)
full_path = os.path.abspath("%s/data/blob" % root_dir)
if not os.path.exists(full_path):
os.makedirs(full_path)
self.storage = ClientStorage.ClientStorage(addr,
blob_dir="%s/blob" % data_path,
blob_dir="%s/data/blob" % root_dir,
shared_blob_dir=True,
client_label='dstat-interface',
max_disconnect_poll=4,
......@@ -125,6 +132,8 @@ def start_server(root_dir=None, port=9998,
if root_dir is None:
root_dir = expanduser('~/.mr_db')
else:
root_dir = expanduser(root_dir)
data_dir = "%s/data" % root_dir
log_dir = "%s/logs" % root_dir
pid_file = "%s/zeo.pid" % root_dir
......@@ -172,6 +181,8 @@ def start_server(root_dir=None, port=9998,
return process
def stop_server():
global process
if process is not None:
if process.is_running():
process.terminate()
......@@ -179,6 +190,7 @@ def stop_server():
if process.is_running():
process.kill()
process.wait()
process = None
if __name__ == '__main__':
start_server()
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment