def test_daemonize(self): def check_pid(pid): try: os.kill(pid, 0) except OSError: return False else: return True daemonize() self.assertEqual(self.forked, 2)
def start(profile): tamer = DaemonTamer(profile) daemonize() arbiter = tamer.make_arbiter() restart = True while restart: try: future = arbiter.start() restart = False if check_future_exception_and_log(future) is None: restart = arbiter._restarting except Exception as e: # emergency stop arbiter.loop.run_sync(arbiter._emergency_stop) raise(e) except KeyboardInterrupt: pass finally: arbiter = None sys.exit(0)
def start(): daemonize() # ~ arbiter = get_arbiter([get_streamer('bla')], # ~ controller='tcp://127.0.0.1:6000', # ~ logoutput='arbiter.log', loglevel='INFO', debug=False, statsd=True) arbiter = get_arbiter([get_daemon_properties('ricoh')], controller='tcp://127.0.0.1:6000', logoutput='arbiter.log', loglevel='INFO', debug=False, statsd=True) restart = True while restart: try: future = arbiter.start() restart = False if check_future_exception_and_log(future) is None: restart = arbiter._restarting except Exception as e: # emergency stop arbiter.loop.run_sync(arbiter._emergency_stop) raise(e) except KeyboardInterrupt: pass finally: arbiter = None sys.exit(0)
def test_daemonize(self): daemonize() self.assertEqual(self.forked, 2)
def main(profile, loggerconfig, foreground, pidfile): """Run an aiida daemon""" import zmq try: zmq_version = [int(part) for part in zmq.__version__.split('.')[:2]] if len(zmq_version) < 2: raise ValueError() except (AttributeError, ValueError): print('Unknown PyZQM version - aborting...') sys.exit(0) if zmq_version[0] < 13 or (zmq_version[0] == 13 and zmq_version[1] < 1): print('circusd needs PyZMQ >= 13.1.0 to run - aborting...') sys.exit(0) loglevel = 'INFO' logoutput = '-' if not foreground: logoutput = 'balrog-{}.log'.format(profile) daemonize() # Create the arbiter profile_config = ProfileConfig(profile) arbiter = get_arbiter( controller=profile_config.get_endpoint(0), pubsub_endpoint=profile_config.get_endpoint(1), stats_endpoint=profile_config.get_endpoint(2), logoutput=logoutput, loglevel=loglevel, debug=False, statsd=True, pidfile='balrog-{}.pid'.format( profile ), # aiida.common.setup.AIIDA_CONFIG_FOLDER + '/daemon/aiida-{}.pid'.format(uuid) watchers=[{ 'name': profile_config.daemon_name, 'cmd': profile_config.cmd_string, 'virtualenv': VIRTUALENV, 'copy_env': True, 'stdout_stream': { 'class': 'FileStream', 'filename': '{}.log'.format(profile_config.daemon_name) }, 'env': { 'PYTHONUNBUFFERED': 'True' } }]) # go ahead and set umask early if it is in the config if arbiter.umask is not None: os.umask(arbiter.umask) pidfile = pidfile or arbiter.pidfile or None if pidfile: pidfile = Pidfile(pidfile) try: pidfile.create(os.getpid()) except RuntimeError as e: print(str(e)) sys.exit(1) # configure the logger loglevel = loglevel or arbiter.loglevel or 'info' logoutput = logoutput or arbiter.logoutput or '-' loggerconfig = loggerconfig or arbiter.loggerconfig or None configure_logger(logger, loglevel, logoutput, loggerconfig) # Main loop restart = True while restart: try: arbiter = arbiter future = arbiter.start() restart = False if check_future_exception_and_log(future) is None: restart = arbiter._restarting except Exception as e: # emergency stop arbiter.loop.run_sync(arbiter._emergency_stop) raise (e) except KeyboardInterrupt: pass finally: arbiter = None if pidfile is not None: pidfile.unlink() sys.exit(0)
def _start_circus(foreground): """ This will actually launch the circus daemon, either daemonized in the background or in the foreground, printing all logs to stdout. .. note:: this should not be called directly from the commandline! """ from circus import get_arbiter from circus import logger as circus_logger from circus.circusd import daemonize from circus.pidfile import Pidfile from circus.util import check_future_exception_and_log, configure_logger client = DaemonClient() loglevel = client.loglevel logoutput = '-' if not foreground: logoutput = client.circus_log_file arbiter_config = { 'controller': client.get_controller_endpoint(), 'pubsub_endpoint': client.get_pubsub_endpoint(), 'stats_endpoint': client.get_stats_endpoint(), 'logoutput': logoutput, 'loglevel': loglevel, 'debug': False, 'statsd': True, 'pidfile': client.circus_pid_file, 'watchers': [{ 'name': client.daemon_name, 'cmd': client.cmd_string, 'virtualenv': client.virtualenv, 'copy_env': True, 'stdout_stream': { 'class': 'FileStream', 'filename': client.daemon_log_file, }, 'env': get_env_with_venv_bin(), }] } # yapf: disable if not foreground: daemonize() arbiter = get_arbiter(**arbiter_config) pidfile = Pidfile(arbiter.pidfile) try: pidfile.create(os.getpid()) except RuntimeError as exception: click.echo(str(exception)) sys.exit(1) # Configure the logger loggerconfig = None loggerconfig = loggerconfig or arbiter.loggerconfig or None configure_logger(circus_logger, loglevel, logoutput, loggerconfig) # Main loop should_restart = True while should_restart: try: arbiter = arbiter future = arbiter.start() should_restart = False if check_future_exception_and_log(future) is None: should_restart = arbiter._restarting # pylint: disable=protected-access except Exception as exception: # Emergency stop arbiter.loop.run_sync(arbiter._emergency_stop) # pylint: disable=protected-access raise exception except KeyboardInterrupt: pass finally: arbiter = None if pidfile is not None: pidfile.unlink() sys.exit(0)