nz-talon 增加配置下发成功后,进行服务重启
This commit is contained in:
@@ -24,14 +24,18 @@ public class PromtailController extends BaseController{
|
||||
@Value("${confagent.promtail.query.auth:true}")
|
||||
private Boolean queryAuth;
|
||||
|
||||
private final String[] QUERY_API_SUFFIX = {"query","query_range","series","labels","values"};
|
||||
|
||||
@Value("${confagent.promtail.restart:systemctl restart promtail}")
|
||||
private String restartCmd;
|
||||
|
||||
@Value("${confagent.versionFile:promtail.version}")
|
||||
private String versionFile;
|
||||
|
||||
@Value("${confagent.promtail.startCmd:systemctl start promtail.service}")
|
||||
private String startCmd;
|
||||
|
||||
@Value("${confagent.promtail.stopCmd:systemctl stop promtail.service}")
|
||||
private String stopCmd;
|
||||
|
||||
private static String rootPath = Tool.WebPathUtil.getRootPath();
|
||||
|
||||
/**
|
||||
@@ -74,17 +78,38 @@ public class PromtailController extends BaseController{
|
||||
Map<String,String> cmdLine =(Map<String,String>) configs.get("cmdline");
|
||||
Map<String,Object> promtailConf =(Map<String,Object>) configs.get("config");
|
||||
|
||||
// boolean reload = false;
|
||||
// boolean restart = false;
|
||||
if(!Tool.MapUtil.isEmpty(cmdLine)){
|
||||
log.info("write promtail cmdLine conf:{}", Tool.JSONUtil.toJsonStr(cmdLine));
|
||||
writeServiceConfigFile(cmdLine,promtailCmdLinePath);
|
||||
// restart = true;
|
||||
}
|
||||
if(!Tool.MapUtil.isEmpty(promtailConf)){
|
||||
log.info("write promtail conf:{}", Tool.JSONUtil.toJsonStr(promtailConf));
|
||||
Tool.YamlUtil.writeAsMap(promtailConf,promtailConfPath);
|
||||
// reload = true;
|
||||
}
|
||||
|
||||
//重启服务promtail
|
||||
if(Tool.StrUtil.isNotBlank(stopCmd)) {
|
||||
log.info("stop cortex:"+stopCmd);
|
||||
try {
|
||||
Tool.RuntimeUtil.exec(stopCmd);
|
||||
}catch(Exception e) {
|
||||
log.error(e);
|
||||
return R.error(RCode.PROMTAIL_STOP_CMD_ERROR);
|
||||
}
|
||||
log.info("stop cortex:"+stopCmd+" end");
|
||||
}
|
||||
Tool.ThreadUtil.sleep(1000);
|
||||
if(Tool.StrUtil.isNotBlank(startCmd)) {
|
||||
log.info("start cortex:"+startCmd);
|
||||
try {
|
||||
// String[] b={"sh","-c",startCmd};
|
||||
// Tool.RuntimeUtil.exec(b);
|
||||
Tool.RuntimeUtil.exec(startCmd);
|
||||
}catch(Exception e) {
|
||||
log.error(e);
|
||||
return R.error(RCode.PROMTAIL_START_CMD_ERROR);
|
||||
}
|
||||
log.info("start cortex:"+startCmd+" end");
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
|
||||
Reference in New Issue
Block a user