monitor.py 文件源码

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

项目:cgroup_py 作者: rperigo 项目源码 文件源码
def runCheck(initType, scrn):
    if initType == "systemd":
        try:
            getStatus = subprocess.Popen(['systemctl', 'status', 'cgroup_py'], stdout=subprocess.PIPE)
        except subprocess.CalledProcessError as e:
            eMsg = "Unable to get status of cgroup_py daemon. Exiting!"
            scrn.addstr(1,1,eMsg)
            time.sleep(2)
            sys.exit(2)
        statlines = getStatus.communicate()[0].splitlines()
        for l in statlines:
            if "Active:" in l:
                status = l.split(':')[1]
                if 'active' in status and not 'inactive' in status:
                    pass
                else:
                    eMsg = "Cgroup_py daemon does not appear to be active. Exiting."
                    scrn.erase()
                    scrn.addstr(1,1,eMsg)
                    scrn.refresh()
                    time.sleep(2)
                    sys.exit(2)
    elif initType == "sysV":
        try:
            getStatus = subprocess.Popen(['/etc/init.d/cgroup_py', 'status'], stdout=subprocess.PIPE)
        except subprocess.CalledProcessError as e:
            eMsg = "Unable to get status of cgroup_py daemon. Exiting!"
            scrn.addstr(1,1, eMsg)
            time.sleep(2)
            sys.exit(2)
        if not "running" in getStatus.communicate()[0]:
            eMsg = "Cgroup_py daemon doesn't appear to be running. Exiting."
            scrn.addstr(1,1, eMsg, curses.A_NORMAL)
            scrn.refresh()
            time.sleep(2)
            sys.exit(2)
        else:
            print "Cgroup_py daemon found."
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号