def stop_process(options): """Stop the synergy-data daemons""" import logging from supervisor import supervisor_helper as helper from model.box_configuration_entry import BoxConfigurationEntry if options.app is not None and options.app != process_context.PROCESS_SUPERVISOR: # mark individual process for termination # real work is performed by Supervisor if options.app not in PROCESSES_FOR_XXL: sys.stdout.write("ERROR: requested process must be withing allowed list of: %r \n" % PROCESSES_FOR_XXL) sys.exit(1) box_id = helper.get_box_id(logging) box_configuration = helper.retrieve_configuration(logging, box_id) box_configuration.set_process_state(options.app, BoxConfigurationEntry.STATE_OFF) helper.update_configuration(logging, box_configuration) else: # stop Supervisor try: pid = _get_supervisor_pid() if pid is None: message = "ERROR: Can not find Supervisor pidfile. Supervisor not running?\n" sys.stderr.write(message) sys.exit(1) # Try killing the daemon process sys.stdout.write("INFO: Killing %r \n" % process_context.PROCESS_SUPERVISOR) while 1: os.kill(pid, signal.SIGTERM) time.sleep(0.1) ProcessContext.remove_pid_file(process_context.PROCESS_SUPERVISOR) except Exception as e: sys.stderr.write("Exception on killing %s : %s \n" % (process_context.PROCESS_SUPERVISOR, str(e))) sys.exit(0)
def start_process(options, daemonize): """Start up supervisor and proper synergy-data daemons""" import logging import psutil from settings import settings from supervisor import supervisor_helper as helper from model.box_configuration_entry import BoxConfigurationEntry box_id = helper.get_box_id(logging) if options.app is not None and options.app != process_context.PROCESS_SUPERVISOR: # mark individual process for execution # real work is performed by Supervisor if options.app not in PROCESSES_FOR_XXL: sys.stdout.write("ERROR: requested process must be withing allowed list of: %r \n" % PROCESSES_FOR_XXL) sys.exit(1) box_configuration = helper.retrieve_configuration(logging, box_id) box_configuration.set_process_state(options.app, BoxConfigurationEntry.STATE_ON) helper.update_configuration(logging, box_configuration) else: # start Supervisor try: pid = _get_supervisor_pid() if pid is not None: if psutil.pid_exists(pid): message = "ERROR: Supervisor is already running with pid %r\n" % pid sys.stderr.write(message) sys.exit(1) p = psutil.Popen( [get_python(), PROJECT_ROOT + "/" + PROCESS_STARTER, process_context.PROCESS_SUPERVISOR], close_fds=True, cwd=settings["process_cwd"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) sys.stdout.write( "Started %s with pid = %r with configuration for BOX_ID=%r \n" % (process_context.PROCESS_SUPERVISOR, p.pid, box_id) ) except Exception as e: sys.stderr.write("Exception on starting %s : %s \n" % (process_context.PROCESS_SUPERVISOR, str(e)))