Initial server source import
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
APP_DIRECTORY = Path('/opt/truf/app')
|
||||
sys.path.insert(0, str(APP_DIRECTORY))
|
||||
|
||||
from host_agent_runtime import FixedHostOperationDispatcher
|
||||
from host_agent_server import (
|
||||
HostAgentServerError,
|
||||
inherited_systemd_listener,
|
||||
serve_forever,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 1:
|
||||
raise HostAgentServerError('arguments_forbidden')
|
||||
listener = inherited_systemd_listener()
|
||||
stop_event = threading.Event()
|
||||
dispatcher = FixedHostOperationDispatcher()
|
||||
|
||||
def request_stop(_signum, _frame):
|
||||
stop_event.set()
|
||||
|
||||
signal.signal(signal.SIGTERM, request_stop)
|
||||
signal.signal(signal.SIGINT, request_stop)
|
||||
try:
|
||||
with listener:
|
||||
serve_forever(
|
||||
listener, handler=dispatcher.handle, stop_event=stop_event,
|
||||
)
|
||||
finally:
|
||||
dispatcher.close()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
result = main()
|
||||
except BaseException as exc:
|
||||
if not isinstance(exc, Exception):
|
||||
raise
|
||||
print(
|
||||
'host operations agent failed (' + type(exc).__name__ + '); details withheld',
|
||||
file=sys.stderr,
|
||||
)
|
||||
result = 1
|
||||
raise SystemExit(result)
|
||||
Reference in New Issue
Block a user