コード例 #1
0
    filter_inject = filter_read.read()
    with open('%s/security/config.xml' % GEOSERVER_DATA_DIR) as config_read:
        full_config = config_read.read()
        if 'anonReload' in full_config:
            logging.info('Configuration already supports anonymous REST reloads.')
        # Only shim in anonymous reload and restart GeoServer if it hasn't been done before
        else:
            config_read.seek(0)
            with open('%s/security/config.xml-output' % GEOSERVER_DATA_DIR, 'w') as config_write:
                line_value = config_read.readline()
                while len(line_value):
                    config_write.write('%s' % line_value)
                    if '<filterChain' in line_value:
                        config_write.write('%s' % filter_inject)
                    line_value = config_read.readline()

            shutil.move('%s/security/config.xml-output' % GEOSERVER_DATA_DIR,
                        '%s/security/config.xml' % GEOSERVER_DATA_DIR)

            response = MARATHON_CLIENT.kill_tasks(GEOSERVER_APP)

            if not len(response) == 1:
                logging.critical('Error restarting GeoServer')
                sys.exit(1)

MARATHON_CLIENT.scale_app(GEOSERVER_APP, GEOSERVER_INSTANCES)

block_for_healthy_app(MARATHON_CLIENT, GEOSERVER_APP, GEOSERVER_INSTANCES)

logging.info('Bootstrap complete.')
コード例 #2
0
        full_config = config_read.read()
        if 'anonReload' in full_config:
            logging.info('Configuration already supports anonymous REST reloads.')
        # Only shim in anonymous reload and restart GeoServer if it hasn't been done before
        else:
            config_read.seek(0)
            with open('%s/security/config.xml-output' % GEOSERVER_DATA_DIR, 'w') as config_write:
                line_value = config_read.readline()
                while len(line_value):
                    config_write.write('%s' % line_value)
                    if '<filterChain' in line_value:
                        config_write.write('%s' % filter_inject)
                    line_value = config_read.readline()

            shutil.move('%s/security/config.xml-output' % GEOSERVER_DATA_DIR,
                        '%s/security/config.xml' % GEOSERVER_DATA_DIR)

            response = MARATHON_CLIENT.kill_tasks(GEOSERVER_APP)

            if not len(response) == 1:
                logging.critical('Error restarting GeoServer')
                sys.exit(1)

wait_for_deployment(MARATHON_CLIENT, GEOSERVER_APP)

MARATHON_CLIENT.scale_app(GEOSERVER_APP, GEOSERVER_INSTANCES)

block_for_healthy_app(MARATHON_CLIENT, GEOSERVER_APP, GEOSERVER_INSTANCES)

logging.info('Bootstrap complete.')
コード例 #3
0
#print(app_info)
print(app_info.instances)

# 重启APP
#maraclient.restart_app(app_id=appId)


from marathon.models import MarathonApp

#创建APP
#maraclient.create_app("/web/nginx",MarathonApp(mem=256, cpus=0.1)

#扩缩容APP
#maraclient.scale_app("nginx",instances=1)
#maraclient.scale_app("nginx",delta=-1)

# 列出task
# tasks = maraclient.list_tasks("nginx")
# print(tasks)

# 杀死某个task,某个应用可能有多个实例,则表示有多个task,注意此处的scale,如果设置
# 为True,表示进行杀死之后,不在恢复(实例数会减少)
# 为False,表示杀死之后,还会恢复(实例数不减少),默认是False
# taskid = "nginx.8b8dcb3b-771b-11eb-bf57-024256e7a552"
# result = maraclient.kill_task("nginx",task_id=taskid,scale=False)
# print(result)

# 杀死所有该应用的task,停止应用用这个方法。
res = maraclient.kill_tasks("nginx",scale=True)
print(res)
コード例 #4
0
# version:v3
from marathon import MarathonClient
server = "http://10.30.0.6:8080"

#实例化
maraclient = MarathonClient(servers=server)

# 获取marathon的应用模块列表
allapp = maraclient.list_apps()

# 提取应用模块的名称,即id
allapp_list = [str(i.id) for i in allapp]
#print(allapp_list)

# 读取待下线模块文本,一行一个,但是不带分组.
with open(r"applist_offline.txt", encoding="utf-8", mode="r") as f:
    for i in f:
        i = i.rstrip("\n")
        for j in allapp_list:
            temp_name = j.split("/")[-1]
            # 此步骤就是为了构建完整的模块名称。
            if i == temp_name:
                try:
                    res = maraclient.kill_tasks(j, scale=True)
                except Exception as e:
                    # print("出错了,错误代码%s" %e)
                    print("应用%s已经停止或者不存在" % j)
                else:
                    print("应用%s停止成功" % j)