Example #1
0
    def __init__(self,
                 app=None,
                 pid_path=None,
                 work_directory=None,
                 uid=None,
                 gid=None):
        super(DaemonBase, self).__init__()

        self.app = app
        self.pid_path = pid_path if pid_path else self.config['pidfile']
        self.pidfile = PidFile(pid_path) if pid_path else PidFile(
            self.config['pidfile'])
        self.work_directory = work_directory if work_directory else self.config[
            'work_directory']
        self.stdout = sys.stdout if not self.config['detach_process'] else None
        self.stderr = sys.stderr if not self.config['detach_process'] else None
        self.detach_process = self.config['detach_process']
        self.uid = uid if uid else self.config['uid']
        self.gid = gid if gid else self.config['gid']

        self.daemon = DaemonContext(working_directory=self.work_directory,
                                    pidfile=self.pidfile,
                                    detach_process=self.detach_process,
                                    stdout=self.stdout,
                                    stderr=self.stderr,
                                    uid=self.uid,
                                    gid=self.gid,
                                    signal_map=self.get_signal_map())
        self.init_logger()
Example #2
0
 def start(app):
     app.config = app.readConfig(app.config_file)
     app.daemon = DaemonContext(
         pidfile=PidFile(app.pid),
         signal_map={
             signal.SIGTERM: app.program_cleanup,
             signal.SIGHUP: app.terminate,
             signal.SIGUSR1: app.reload_program_config
         }
         #                                   ,files_preserve=(sys.stdout)
         ,
         stdout=open("/tmp/daemon_stdout.log", 'w'),
         stderr=open("/tmp/daemon_stderr.log", 'w'),
         gid=app.config["daemon"]["groupid"])
     print("daemon created")
     if app.nodaemon:
         print("no daemon")
         app.daemon.detach_process = False
     else:
         app.daemon.detach_process = True
     try:
         print("before daemon")
         app.daemon.open()
         print("after daemon")
         app.createLogger()
         app.logger.debug('After open')
         app.run()
     except:
         print("Unexpected error:", sys.exc_info()[0])
         raise
Example #3
0
 def start(self, devel=False):
     self.config.read_file(open(self._config_file))
     if devel:
         self._app(devel=True)
     daemon = DaemonContext(pidfile=PidFile(self.pid))
     if self.nodaemon:
         daemon.detach_process = False
     dlog = open(self.config.get('main', 'dlog'), 'w')
     daemon.stderr = dlog
     daemon.stdout = dlog
     daemon.open()
     self._app()
Example #4
0
def main():
    args = parse_args(sys.argv[1:])

    if args.daemonize:
        pidfile = PidFile(args.pid_file)
        daemon = DaemonContext(pidfile=pidfile)
        syslog.syslog('Daemonizing')
        daemon.open()

    syslog.syslog('Daemonized')

    main_loop(args)
Example #5
0
 def start(self):
     console_log = logging.StreamHandler()
     console_log.setLevel('DEBUG')
     self.log.addHandler(console_log)
     if not self._cfg_open():
         print("could not process config")
         sys.exit(1)
     daemon = DaemonContext(pidfile=PidFile(self.pid))
     if self.nodaemon:
         daemon.detach_process = False
     dlog = open(self.config.get('main', 'dlog_file'), 'w')
     daemon.stderr = dlog
     daemon.stdout = dlog
     daemon.open()
     signal.signal(signal.SIGHUP, self._reload)
     signal.signal(signal.SIGTERM, self._quit)
     self.log.removeHandler(console_log)
     self._run()
Example #6
0
 def start(self, devel=False):
     self.config.read_file(open(self._config_file))
     self._config_dict = self._cfg_to_dict(self.config)
     try:
         jsonschema.validate(self.config_dict['main'], CHECK_CONFIG_MAIN)
     except jsonschema.exceptions.ValidationError as err:
         print("main section: {0}".format(err))
         sys.exit(1)
     if devel:
         self._app(devel=True)
         return
     daemon = DaemonContext(pidfile=PidFile(self.pid))
     if self.nodaemon:
         daemon.detach_process = False
     dlog = open(self.config.get('main', 'dlog'), 'w')
     daemon.stderr = dlog
     daemon.stdout = dlog
     daemon.open()
     self._app()
Example #7
0
def chellow_command():
    parser = argparse.ArgumentParser()
    parser.add_argument('action', choices=['start', 'stop', 'restart'])
    args = parser.parse_args()

    try:
        os.makedirs(app.instance_path)
    except BaseException:
        pass
    pidfile_path = os.path.join(app.instance_path, 'chellow.pid')
    pidfile = PidFile(pidfile_path)
    daemon = DaemonContext(
        pidfile=pidfile, stdin=sys.stdin, stderr=sys.stderr, stdout=sys.stdout)

    if args.action == 'start':
        chellow_start(daemon)
    elif args.action == 'stop':
        chellow_stop(pidfile_path)
    elif args.action == 'restart':
        chellow_stop(pidfile_path)
        chellow_start(daemon)
Example #8
0
def chellow_command():
    parser = argparse.ArgumentParser()
    parser.add_argument("action", choices=["start", "stop", "restart"])
    args = parser.parse_args()

    try:
        os.makedirs(app.instance_path)
    except BaseException:
        pass
    pidfile_path = os.path.join(app.instance_path, "chellow.pid")
    pidfile = PidFile(pidfile_path)
    daemon = DaemonContext(pidfile=pidfile,
                           stdin=sys.stdin,
                           stderr=sys.stderr,
                           stdout=sys.stdout)

    if args.action == "start":
        chellow_start(daemon)
    elif args.action == "stop":
        chellow_stop(pidfile_path)
    elif args.action == "restart":
        chellow_stop(pidfile_path)
        chellow_start(daemon)