[docs]defstart(daemonize=False,log_level=logging.INFO,dev_mode=False,**kwargs):""" A wrapper for :func:`run` that optionally runs it in a forked daemon process. :param kwargs: rest of arguments is forwarded to :func:`run` """# reimport into scopeimportajifdaemonize:context=daemon.DaemonContext(pidfile=PidFile('/var/run/ajenti.pid'),detach_process=True,files_preserve=list(range(1024)),# force-closing files breaks gevent badly)withcontext:aj.log.init_log_directory()aj.log.init_log_file(log_level)importaj.coretry:aj.core.run(dev_mode=dev_mode,**kwargs)# pylint: disable=W0703exceptExceptionase:handle_crash(e)else:ifnotdev_mode:aj.log.init_log_directory()aj.log.init_log_file(log_level)importaj.coretry:aj.core.run(dev_mode=dev_mode,**kwargs)exceptKeyboardInterrupt:pass# pylint: disable=W0703exceptExceptionase:handle_crash(e)
[docs]defhandle_crash(exc):# todo rework thisnow=datetime.now().strftime('%Y-%m-%d-%Hh%M')logging.error('Fatal crash occured')traceback.print_exc()exc.traceback=traceback.format_exc()report_path=f'/var/log/ajenti/crash-{now}.txt'try:report=open(report_path,'w')exceptExceptionase:report_path=f'./crash-{now}.txt'report=open(report_path,'w')fromaj.utilimportmake_reportreport.write(make_report(exc))report.close()logging.error(f'Crash report written to {report_path}')logging.error('Please submit it to https://github.com/ajenti/ajenti/issues/new')