-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathk2_server.py
More file actions
48 lines (40 loc) · 1.81 KB
/
k2_server.py
File metadata and controls
48 lines (40 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import time
from .web_server import WebServer
class K2Server(WebServer):
def __init__(self, k2_server_bin, working_dir, kphp_build_dir, options=None, auto_start=False):
"""
:param k2_server_bin: Path to the k2 server binary
:param working_dir: Working directory where the k2 server will be started
:param kphp_build_dir: Directory with compiled k2-components
:param options: Dictionary with additional options that will be used when starting the k2 server
Special values:
option: True - pass option without value
option: None - delete default option
"""
super(K2Server, self).__init__(k2_server_bin, working_dir, options)
self._images_dir = kphp_build_dir
self._working_dir = working_dir
self._linking_file = os.path.join(working_dir, "data/component-config.yaml")
self._json_log_file = None
self._options = {"start-node": True,
"--host": "127.0.0.1",
"--http_port": self.http_port,
"--rpc_port": self.rpc_port,
"--images-dir": self._images_dir,
"--linking": self._linking_file}
if options:
self.update_options(options)
if auto_start:
self.start()
def start(self, start_msgs=None):
if self._is_json_log_enabled():
self._json_log_file = os.path.join(self._working_dir, self._options["--log-file"])
else:
start_msgs = start_msgs or []
start_msgs.append("Starting to accept clients.")
super(K2Server, self).start(start_msgs)
def stop(self):
super(K2Server, self).stop()
def _is_json_log_enabled(self):
return "--log-file" in self._options