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 48 49 50 51 52 53 54 55 56 57 58
|
# Copyright (c) 2017-2019 David Steele <dsteele@gmail.com>
#
# SPDX-License-Identifier: GPL-2.0-or-later
# License-Filename: LICENSE
#
# Copyright 2016-2017 David Steele <steele@debian.org>
# This file is part of comitup
# Available under the terms of the GNU General Public License version 2
# or later
#
import logging
from .sysd import sd_start_unit, sd_stop_unit
log: logging.Logger = logging.getLogger("comitup")
COMITUP_SERVICE: str = "comitup-web.service"
web_service: str = ""
def start_service(service: str) -> None:
log.debug("starting %s web service", service)
sd_start_unit(service, "replace")
def stop_service(service: str) -> None:
log.debug("stopping %s web service", service)
sd_stop_unit(service, "replace")
callmatrix = {
("HOTSPOT", "start"): (lambda: stop_service, lambda: web_service),
("HOTSPOT", "pass"): (lambda: start_service, lambda: COMITUP_SERVICE),
("CONNECTING", "start"): (lambda: stop_service, lambda: COMITUP_SERVICE),
("CONNECTED", "start"): (lambda: start_service, lambda: web_service),
}
def state_callback(state: str, action: str) -> None:
try:
(fn_fact, svc_fact) = callmatrix[(state, action)]
except KeyError:
return
if svc_fact():
fn_fact()(svc_fact())
def init_webmgr(web_svc: str) -> None:
global web_service
stop_service(COMITUP_SERVICE)
web_service = web_svc
log.debug("web service is %s" % web_service)
|