import os from taskmaster.common import config as tm_config from taskmaster.utils import log from taskmaster.server.server import ServerDaemon #data = tm_config.load("../resources/config_temp.yml") #print(data.get('programs')) logger_std = log.get_logger('serverd') # server = ServerDaemon # server = None class ServerD(): def __init__(self): self.config_server = tm_config.ConfigServer( "../resources/config_temp.yml") self.server = ServerDaemon('/tmp/.pidfile', self.config_server) logger_std.info('Server Daemon has been initialized') logger_std.info('Starting server daemon') def start(self): logger_std.info('Starting serverd') self.server.start() def stop(self): logger_std.info('Stopping serverd') self.server.stop()
import os, signal, time from taskmaster.server.dashboard import dashboard from taskmaster.utils import log log = log.get_logger('sig_handler') def sigchld_handler(signum, frame): if signum != signal.SIGCHLD: return # waitpid and update pid list in dashboard while True: try: pid_wexit = os.waitpid(0, 0) dashboard.pid_wexit.append(pid_wexit) except OSError as err: if err.errno == 10: time.sleep(1) continue log.fatal('error occurred upon waiting pid [errno = {}]'.format( err.errno)) exit(1)
import os, sys, time, signal from taskmaster.common.process import Process, ProcessState from taskmaster.common.program import Program from taskmaster.utils import log from taskmaster.utils import utils from taskmaster.server.dashboard import dashboard from taskmaster.common import configmap from taskmaster.server.services import stop_programs log = log.get_logger('launch_manager') def launch_manager(): """ Launches all programs in the list contained in the dashboard :return: """ log.info('starting launch_manager') # kill old programs in reload or create reload_manager log.info('debug: fds_buff: {0}'.format(dashboard.fds_buff.keys())) for program in dashboard.programs.values(): launch_program(program) def remove_progs(): log.info('Removing programs')
import os, time from taskmaster.common.configmap import ProcessState from taskmaster.common.process import Process from taskmaster.server.dashboard import dashboard from taskmaster.server.launch_manager import launch_process from taskmaster.utils import log log = log.get_logger('state_manager') def state_manager(): # os.mkdir('/tmp/statedir') log.info('starting state_manager') while True: log.info('checking processes state') for pid_exit in list(dashboard.pid_wexit): log.info('updating state of pid: {0}'.format(pid_exit[0])) process = dashboard.pid_procs.get(pid_exit[0]) program = dashboard.programs.get(process.program_name) try: process.control_starting_state(program) if process.to_remove: clean_proccess(process, ProcessState.REMOVED) program.processes.pop(process.name) if process.state == ProcessState.RUNNING: log.info('process {0} exited with code {1}'.format( pid_exit[0], pid_exit[1]))
import socket # from taskmaster.server.server import ServerDaemon from taskmaster.utils import log from taskmaster.utils.utils import thread_start from taskmaster.server.service_manager import service_manager log = log.get_logger('clients_manager') def clients_manager(server): # def clients_manager(server_socket: socket.socket, config: ConfigServer): while True: cs, addr = server.socket.accept() thread_start(service_manager, (cs, addr, server.config))
import socket from taskmaster.utils import log from taskmaster.utils import utils from taskmaster.server import services log = log.get_logger('service_manager') services = { 'start': services.serve_start, 'stop': services.serve_stop, 'attach': services.serve_attach, 'reload': services.serve_relaod, 'status': services.serve_status, 'shutdown': services.serve_shutdown } def service_manager(cs: socket.socket, addr, config): username, auth = authenticate_client(cs, addr, config) if not auth: log.info('client {0} failed to authenticate'.format(username)) return serve_client(cs, addr, config) def authenticate_client(cs, addr, configServer) -> (str, bool): # username = cs.recv(256).decode('utf-8') # password = cs.recv(256).decode('utf-8') auth_query = cs.recv(1024).decode('utf-8') log.debug('received auth query: {0}'.format(auth_query))
import cmd import os, sys from taskmaster.common import config as tm_config from taskmaster.utils import log from taskmaster.client.tm_cmd import TaskmasterCmd from getpass import getpass import socket log = log.get_logger('client') ATTEMPT_MAX = 3 class Client(): def __init__(self, configFile: str = None): self.config = tm_config.ConfigClient(configFile) self.csocket = socket.socket() def start(self): print('Starting the client ...') if not self.connect(): return -1 if not self.try_authenticate(): return -1 return self.cli() def connect(self) -> bool: # return True # test if not self.config.host: self.config.host = input("Enter host ip: ")
import os, sys, time, pathlib from select import select from taskmaster.utils import log from taskmaster.server.dashboard import dashboard BUFF_SIZE = 4 TIME_SLEEP = 1 DECODE_FORMAT = 'UTF-8' log = log.get_logger('buff_manager') def buff_manager(): """\ Buffer Manager is responsible for dispatching standard out/err flow of running processes by by selecting open fds which are ready to read from and transport the data to the appropriate files. """ log.info('starting buff_manager') while 1: time.sleep(TIME_SLEEP) log.debug('checking fds') fds = list(dashboard.fds_buff.keys()) if not len(fds): log.debug('empty fd list') continue rfds = []
import yaml from taskmaster.utils import log logger_std = log.get_logger('config') section_base = ['connection'] section_server = ['server', 'programs'] section_client = ['client'] client_attr = { 'prompt': str, 'host': str, 'port': int, 'username': str, 'password': str } server_attr = { 'host': (str, '127.0.0.1'), 'port': (int, 4321), 'logfile': (str, '.tm_log'), 'loglevel': (str, 'info'), 'pidfile': (str, '.pidfile'), 'umask': (str, '00777'), 'clients': (dict, {}) } class Config: """\
from taskmaster.common import config as tm_config from taskmaster.utils import log #data = tm_config.load("../resources/config_temp.yml") #print(data.get('programs')) logger_std = log.get_logger(None) config_server = tm_config.ConfigServer('../resources/config_temp.yml') if not config_server.valid: logger_std.fatal('Exiting upon failed config upload') exit(1) for program in config_server.programs: print(program) print(config_server.server)
from taskmaster.utils import log from taskmaster.utils import utils from taskmaster.common.configmap import ProcessState from taskmaster.common import config as tm_config from taskmaster.server import dashboard as mod_dash from taskmaster.server.dashboard import dashboard from taskmaster.server.launch_manager import launch_process from taskmaster.server.launch_manager import reload_launch_manager from taskmaster.server.launch_manager import kill_process from taskmaster.server.launch_manager import kill_program log = log.get_logger('services') def serve_start(cs, query_list): log.info('serving: start: {0}'.format(query_list)) # utils.socket_send(cs, 'something there from start') # utils.socket_send(cs, '\r') prog_names = query_list[1:] log.debug('prog_names: {0}'.format(prog_names)) for prog_name in prog_names: if prog_name not in dashboard.programs.keys(): utils.socket_send(cs, 'program {0} not found'.format(prog_name)) else: utils.socket_send(cs, 'starting {0}'.format(prog_name)) program = dashboard.programs.get(prog_name) changed = 0
import signal from taskmaster.common.daemonizer import Daemon from taskmaster.common.config import ConfigServer from taskmaster.utils.sig_handler import sigchld_handler from taskmaster.utils.utils import thread_start, socket_bind from taskmaster.utils import log from taskmaster.server.state_manager import state_manager from taskmaster.server.launch_manager import launch_manager from taskmaster.server.buff_manager import buff_manager from taskmaster.server.clients_manager import clients_manager from taskmaster.server.dashboard import dashboard log = log.get_logger('server') class ServerDaemon(Daemon): def __init__(self, pidfile, config: ConfigServer): super().__init__(pidfile) self.config = config # self.addr = ('127.0.0.1', 4321) # temp: to be parsed from config file self.socket = socket.socket() # or in run self.socket_bound = False dashboard.init(config.data) # change position signal.signal(signal.SIGCHLD, sigchld_handler) def run(self): log.info('running the server daemon')