Beispiel #1
0
    def test_server_by_name(self):
        dpid = server.create_process("test_server_by_name", "sleep 60")  # 创建进程
        assert dpid
        process = server.get_process(program_id=dpid)
        assert server.get_process(program_id=dpid)["status"] == STATUS.RUNNING

        assert server.stop_process(program_name=process["name"])  # 正常停止
        assert server.get_process(program_id=dpid)["status"] == STATUS.STOPPED

        assert server.stop_process(program_name=process["name"])  # 停止已停止的进程
        assert server.get_process(program_id=dpid)["status"] == STATUS.STOPPED

        assert server.restart_process(program_name=process["name"])  # 重启已停止的进程
        assert server.get_process(program_id=dpid)["status"] == STATUS.RUNNING

        assert server.start_process(program_name=process["name"])  # 启动已启动的进程
        assert server.get_process(program_id=dpid)["status"] == STATUS.RUNNING

        assert server.restart_process(program_name=process["name"])  # 正常重启
        assert server.get_process(program_id=dpid)["status"] == STATUS.RUNNING

        assert server.stop_process(program_name=process["name"])  # 正常停止
        assert server.get_process(program_id=dpid)["status"] == STATUS.STOPPED

        assert server.start_process(program_name=process["name"])  # 正常启动
        assert server.get_process(program_id=dpid)["status"] == STATUS.RUNNING

        assert server.stop_process(program_name=process["name"])  # 清理
        assert server.get_process(program_id=dpid)["status"] == STATUS.STOPPED
Beispiel #2
0
def status():
    processes = sa.get_process()
    if processes is None:
        logging.error("获取进程信息失败")
        return

    titles = ["ID", "名称", "状态", "机器", "创建时间", "命令"]
    results = [titles]
    for process in processes:
        name = process["name"]
        _status = get_status_name(process["status"])
        machine = process["machine"] or "-"
        start_time = process["create_time"] or "-"
        command = process["command"] or "-"

        results.append([str(process["id"]), name, str(_status),
                        machine, start_time, command])

    if results:
        width_list = []
        for i in range(len(titles)):
            max_length = max(tools.char_length(result[i]) for result in results)
            width_list.append(max_length)

        for result in results:
            print('    '.join(["%-{}s".format(width
                                              - tools.unicode_count(field))
                               % field
                               for field, width in
                               zip(result, width_list)]))
Beispiel #3
0
 def test_auto_start(self):
     name = "test_auto_start"
     command = "sleep 60"
     dpid = server.create_process(name,
                                  command,
                                  auto_start=False,
                                  directory=tmp_for_test,
                                  stdout_logfile="test_auto_start.log",
                                  stderr_logfile="test_auto_start.log")
     assert dpid
     assert server.get_process(program_id=dpid)["status"] == STATUS.STOPPED
Beispiel #4
0
 def test_status(self):
     name = "test_status"
     command = "sleep 60"
     directory = "/tmp"
     environment = "A=a;B=b;C=c"
     auto_start = False
     auto_restart = True
     machines = '127.0.0.1;localhost'
     touch_timeout = 60
     stdout_logfile = '/tmp/stdout.log'
     stderr_logfile = '/tmp/stderr.log'
     max_fail_count = 10
     dpid = server.create_process(name,
                                  command,
                                  directory=directory,
                                  environment=environment,
                                  auto_start=auto_start,
                                  auto_restart=auto_restart,
                                  machines=machines,
                                  touch_timeout=touch_timeout,
                                  stdout_logfile=stdout_logfile,
                                  stderr_logfile=stderr_logfile,
                                  max_fail_count=max_fail_count)
     assert dpid
     process = server.get_process(program_id=dpid)
     assert process["id"] == dpid
     assert process["name"] == name
     assert process["command"] == command
     assert process["directory"] == directory
     assert process["environment"] == environment
     assert process["auto_start"] == auto_start
     assert process["auto_restart"] == auto_restart
     assert process["machines"] == machines
     assert process["touch_timeout"] == touch_timeout
     assert process["stdout_logfile"] == stdout_logfile
     assert process["stderr_logfile"] == stderr_logfile
     assert process["max_fail_count"] == max_fail_count
     assert server.stop_process(program_id=dpid)  # 清理