nz-talon 增加配置下发成功后,进行服务重启
This commit is contained in:
@@ -24,14 +24,18 @@ public class PromtailController extends BaseController{
|
|||||||
@Value("${confagent.promtail.query.auth:true}")
|
@Value("${confagent.promtail.query.auth:true}")
|
||||||
private Boolean queryAuth;
|
private Boolean queryAuth;
|
||||||
|
|
||||||
private final String[] QUERY_API_SUFFIX = {"query","query_range","series","labels","values"};
|
|
||||||
|
|
||||||
@Value("${confagent.promtail.restart:systemctl restart promtail}")
|
@Value("${confagent.promtail.restart:systemctl restart promtail}")
|
||||||
private String restartCmd;
|
private String restartCmd;
|
||||||
|
|
||||||
@Value("${confagent.versionFile:promtail.version}")
|
@Value("${confagent.versionFile:promtail.version}")
|
||||||
private String versionFile;
|
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();
|
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,String> cmdLine =(Map<String,String>) configs.get("cmdline");
|
||||||
Map<String,Object> promtailConf =(Map<String,Object>) configs.get("config");
|
Map<String,Object> promtailConf =(Map<String,Object>) configs.get("config");
|
||||||
|
|
||||||
// boolean reload = false;
|
|
||||||
// boolean restart = false;
|
|
||||||
if(!Tool.MapUtil.isEmpty(cmdLine)){
|
if(!Tool.MapUtil.isEmpty(cmdLine)){
|
||||||
log.info("write promtail cmdLine conf:{}", Tool.JSONUtil.toJsonStr(cmdLine));
|
log.info("write promtail cmdLine conf:{}", Tool.JSONUtil.toJsonStr(cmdLine));
|
||||||
writeServiceConfigFile(cmdLine,promtailCmdLinePath);
|
writeServiceConfigFile(cmdLine,promtailCmdLinePath);
|
||||||
// restart = true;
|
|
||||||
}
|
}
|
||||||
if(!Tool.MapUtil.isEmpty(promtailConf)){
|
if(!Tool.MapUtil.isEmpty(promtailConf)){
|
||||||
log.info("write promtail conf:{}", Tool.JSONUtil.toJsonStr(promtailConf));
|
log.info("write promtail conf:{}", Tool.JSONUtil.toJsonStr(promtailConf));
|
||||||
Tool.YamlUtil.writeAsMap(promtailConf,promtailConfPath);
|
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();
|
return R.ok();
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ public enum RCode {
|
|||||||
CONFIG_SNMP_EXPORTER_RELOAD_FAILED(10007,"Reload snmp_exporter failed"),
|
CONFIG_SNMP_EXPORTER_RELOAD_FAILED(10007,"Reload snmp_exporter failed"),
|
||||||
|
|
||||||
PROMTAIL_CONFIG_VERSION_ISNULL(10008,"The promtail config version is required"),
|
PROMTAIL_CONFIG_VERSION_ISNULL(10008,"The promtail config version is required"),
|
||||||
|
|
||||||
|
PROMTAIL_START_CMD_ERROR(10009,"The promtail start command is error"),
|
||||||
|
PROMTAIL_STOP_CMD_ERROR(10010,"The promtail stop command is error"),
|
||||||
|
|
||||||
ERROR(999, "error"); //通用错误/未知错误
|
ERROR(999, "error"); //通用错误/未知错误
|
||||||
private RCode(Integer code, String msg) {
|
private RCode(Integer code, String msg) {
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ confagent:
|
|||||||
cmdLine: D:\config\config.conf
|
cmdLine: D:\config\config.conf
|
||||||
config: D:\config\promtail.yml
|
config: D:\config\promtail.yml
|
||||||
defaultIP: 192.168.40.42
|
defaultIP: 192.168.40.42
|
||||||
|
startCmd: sh -c start_promtail.sh
|
||||||
|
stopCmd: kill -9 26590
|
||||||
|
|
||||||
resourcePath: ./
|
resourcePath: ./
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ confagent:
|
|||||||
cmdLine: /home/fang/loki/config.conf
|
cmdLine: /home/fang/loki/config.conf
|
||||||
config: /home/fang/loki/promtail.yml
|
config: /home/fang/loki/promtail.yml
|
||||||
defaultIP: 127.0.0.1
|
defaultIP: 127.0.0.1
|
||||||
|
startCmd: systemctl start promtail
|
||||||
|
stopCmd: systemctl stop promtail
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
config: config/logback-spring.xml
|
config: config/logback-spring.xml
|
||||||
|
|||||||
Reference in New Issue
Block a user