bottletlsdaemon.py 文件源码

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

项目:agent 作者: upd89 项目源码 文件源码
def daemon_run(host="localhost", port="8080", pidfile=None, logfile=None,
               keyfile='priv.key', certfile='pub.crt', cafile='ca.crt',
               action="start"):
    """
    Get the bottle 'run' function running in the background as a daemonized
    process.

    :host: The host interface to listen for connections on. Enter 0.0.0.0
           to listen on all interfaces. Defaults to localhost.
    :port: The host port to listen on. Defaults to 8080.
    :pidfile: The file to use as the process id file. Defaults to "bottle.pid"
    :logfile: The file to log stdout and stderr from bottle to. Defaults to "bottle.log"

    """

    if pidfile is None:
        pidfile = os.path.join(
            os.getcwd(),
            "bottle.pid"
        )

    if logfile is None:
        logfile = os.path.join(
            os.getcwd(),
            "bottle.log"
        )

    if action == "start":
        log = open(logfile, "w+")
        context = daemon.DaemonContext(
            pidfile=__locked_pidfile(pidfile),
            stdout=log,
            stderr=log
        )

        with context:
            # bottle.run(host=host, port=port)
            srv = SSLWSGIRefServer(host=host, port=port, keyfile=keyfile,
                                   certfile=certfile, cafile=cafile)
            bottle.run(server=srv)
    else:
        with open(pidfile, "r") as p:
            pid = int(p.read())
            os.kill(pid, signal.SIGTERM)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号