forked from Kippiii/jabberwocky-container-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
41 lines (31 loc) · 1023 Bytes
/
server.py
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
import json
import logging
import os
import psutil
from src.containers.container_manager_server import ContainerManagerServer
from src.system.syspath import get_server_info_file, get_server_log_file
def server_is_running() -> bool:
"""
Determines if the server is running.
:return: True is sever is running, False if not.
"""
if not get_server_info_file().is_file():
return False
with open(get_server_info_file(), "r", encoding="utf-8") as f:
info = json.load(f)
pid = info["pid"]
boot = info["boot"]
if boot > psutil.boot_time() and psutil.pid_exists(pid):
return True
else:
os.remove(get_server_info_file())
return False
if __name__ == "__main__":
logging.basicConfig(filename=get_server_log_file(), filemode="w")
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
server = ContainerManagerServer(logger=logger)
try:
server.listen()
except Exception as ex:
raise ex