bot.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:zoneminder-slack-bot 作者: rjclark 项目源码 文件源码
def start(self):
        """
        If configured, converts to a daemon. Otherwise start connected to the current console.
        """

        run_as_daemon = self.config.getboolean('Runtime', 'daemon', fallback=False)
        uid = self.config.get('Runtime', 'daemon user', fallback=None)
        gid = self.config.get('Runtime', 'daemon group', fallback=None)
        pidfile = self.config.get('Runtime', 'daemon pid file', fallback=None)

        if uid:
            uid = getpwnam(uid).pw_uid
        if gid:
            gid = getgrnam(gid).gr_gid

        if run_as_daemon:
            LOGGER.info('Starting as a daemon process')
            import daemon
            import daemon.pidfile

            if pidfile:
                # We need to create the enclosing directory (if it does not exist) before
                # starting the daemon context as we might lose the permissions to create
                # that directory
                piddir = os.path.dirname(pidfile)
                if not os.path.isdir(piddir):
                    os.makedirs(piddir, 0o0755)
                    os.chown(piddir, uid, gid)

                # Convert the filename to the appropriate type for the deamon module.
                pidfile = daemon.pidfile.TimeoutPIDLockFile(pidfile)

            with daemon.DaemonContext(uid=uid, gid=gid, pidfile=pidfile):
                self._start()

        self._start()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号