2021-08-21 02:46:11 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# services.py - Utility functions for pvcnoded external services
|
|
|
|
# Part of the Parallel Virtual Cluster (PVC) system
|
|
|
|
#
|
2022-10-06 11:55:27 -04:00
|
|
|
# Copyright (C) 2018-2022 Joshua M. Boniface <joshua@boniface.me>
|
2021-08-21 02:46:11 -04:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, version 3.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
import daemon_lib.common as common
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
|
|
|
|
def start_zookeeper(logger, config):
|
2021-11-06 03:02:43 -04:00
|
|
|
if config["daemon_mode"] == "coordinator":
|
|
|
|
logger.out("Starting Zookeeper daemon", state="i")
|
2021-08-21 02:46:11 -04:00
|
|
|
# TODO: Move our handling out of Systemd and integrate it directly as a subprocess?
|
2021-11-06 03:02:43 -04:00
|
|
|
common.run_os_command("systemctl start zookeeper.service")
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
def start_libvirtd(logger, config):
|
2021-11-06 03:02:43 -04:00
|
|
|
if config["enable_hypervisor"]:
|
|
|
|
logger.out("Starting Libvirt daemon", state="i")
|
2021-08-21 02:46:11 -04:00
|
|
|
# TODO: Move our handling out of Systemd and integrate it directly as a subprocess?
|
2021-11-06 03:02:43 -04:00
|
|
|
common.run_os_command("systemctl start libvirtd.service")
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
def start_patroni(logger, config):
|
2021-11-06 03:02:43 -04:00
|
|
|
if config["enable_networking"] and config["daemon_mode"] == "coordinator":
|
|
|
|
logger.out("Starting Patroni daemon", state="i")
|
2021-08-21 02:46:11 -04:00
|
|
|
# TODO: Move our handling out of Systemd and integrate it directly as a subprocess?
|
2021-11-06 03:02:43 -04:00
|
|
|
common.run_os_command("systemctl start patroni.service")
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
def start_frrouting(logger, config):
|
2021-11-06 03:02:43 -04:00
|
|
|
if config["enable_networking"] and config["daemon_mode"] == "coordinator":
|
|
|
|
logger.out("Starting FRRouting daemon", state="i")
|
2021-08-21 02:46:11 -04:00
|
|
|
# TODO: Move our handling out of Systemd and integrate it directly as a subprocess?
|
2021-11-06 03:02:43 -04:00
|
|
|
common.run_os_command("systemctl start frr.service")
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
def start_ceph_mon(logger, config):
|
2021-11-06 03:02:43 -04:00
|
|
|
if config["enable_storage"] and config["daemon_mode"] == "coordinator":
|
|
|
|
logger.out("Starting Ceph Monitor daemon", state="i")
|
2021-08-21 02:46:11 -04:00
|
|
|
# TODO: Move our handling out of Systemd and integrate it directly as a subprocess?
|
2021-11-06 03:02:43 -04:00
|
|
|
common.run_os_command(
|
|
|
|
f'systemctl start ceph-mon@{config["node_hostname"]}.service'
|
|
|
|
)
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
def start_ceph_mgr(logger, config):
|
2021-11-06 03:02:43 -04:00
|
|
|
if config["enable_storage"] and config["daemon_mode"] == "coordinator":
|
|
|
|
logger.out("Starting Ceph Manager daemon", state="i")
|
2021-08-21 02:46:11 -04:00
|
|
|
# TODO: Move our handling out of Systemd and integrate it directly as a subprocess?
|
2021-11-06 03:02:43 -04:00
|
|
|
common.run_os_command(
|
|
|
|
f'systemctl start ceph-mgr@{config["node_hostname"]}.service'
|
|
|
|
)
|
2021-08-21 02:46:11 -04:00
|
|
|
|
|
|
|
|
2023-11-05 19:26:38 -05:00
|
|
|
def start_keydb(logger, config):
|
2023-11-27 13:32:47 -05:00
|
|
|
if (config["enable_api"] or config["enable_worker"]) and config[
|
|
|
|
"daemon_mode"
|
|
|
|
] == "coordinator":
|
2023-11-05 19:26:38 -05:00
|
|
|
logger.out("Starting KeyDB daemon", state="i")
|
|
|
|
# TODO: Move our handling out of Systemd and integrate it directly as a subprocess?
|
|
|
|
common.run_os_command("systemctl start keydb-server.service")
|
|
|
|
|
|
|
|
|
2023-11-27 13:32:47 -05:00
|
|
|
def start_worker(logger, config):
|
|
|
|
if config["enable_worker"]:
|
2023-11-16 02:25:02 -05:00
|
|
|
logger.out("Starting Celery Worker daemon", state="i")
|
2023-11-04 13:07:04 -04:00
|
|
|
# TODO: Move our handling out of Systemd and integrate it directly as a subprocess?
|
2023-11-15 19:13:48 -05:00
|
|
|
common.run_os_command("systemctl start pvcworkerd.service")
|
2023-11-04 13:07:04 -04:00
|
|
|
|
|
|
|
|
2021-08-21 02:46:11 -04:00
|
|
|
def start_system_services(logger, config):
|
|
|
|
start_zookeeper(logger, config)
|
|
|
|
start_libvirtd(logger, config)
|
|
|
|
start_patroni(logger, config)
|
|
|
|
start_frrouting(logger, config)
|
|
|
|
start_ceph_mon(logger, config)
|
|
|
|
start_ceph_mgr(logger, config)
|
2023-11-05 19:26:38 -05:00
|
|
|
start_keydb(logger, config)
|
2023-11-27 13:32:47 -05:00
|
|
|
start_worker(logger, config)
|
2021-08-21 02:46:11 -04:00
|
|
|
|
2023-10-23 22:24:03 -04:00
|
|
|
logger.out("Waiting 10 seconds for daemons to start", state="s")
|
|
|
|
sleep(10)
|