From fcca33122427a87273cb59f44ce7c0a65fc7e269 Mon Sep 17 00:00:00 2001 From: dami Date: Sat, 2 Aug 2025 14:32:26 +0800 Subject: [PATCH] Update index.py --- plugins/loki/index.py | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/plugins/loki/index.py b/plugins/loki/index.py index 000f1563b..522442cf4 100755 --- a/plugins/loki/index.py +++ b/plugins/loki/index.py @@ -45,15 +45,18 @@ def getConf(): path = getServerDir() + "/conf/loki-config.yaml" return path - -def getInitDTpl(): - path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" +def getPromtailConf(): + path = getServerDir() + "/conf/promtail-config.yaml" return path def getConfTpl(): path = getPluginDir() + "/conf/loki-config.yaml" return path +def getPromtailConfTpl(): + path = getPluginDir() + "/conf/promtail-config.yaml" + return path + def getArgs(): args = sys.argv[3:] @@ -129,7 +132,14 @@ def initDreplace(): file_tpl = getConfTpl() dst_file = getConf() + if not os.path.exists(dst_file): + content = mw.readFile(file_tpl) + content = contentReplace(content) + mw.writeFile(dst_file, content) + + file_tpl = getPromtailConfTpl() + dst_file = getPromtailConf() if not os.path.exists(dst_file): content = mw.readFile(file_tpl) content = contentReplace(content) @@ -146,6 +156,17 @@ def initDreplace(): mw.writeFile(systemService, content) mw.execShell('systemctl daemon-reload') + # systemd + systemDir = mw.systemdCfgDir() + systemService = systemDir + '/promtail.service' + if os.path.exists(systemDir) and not os.path.exists(systemService): + systemServiceTpl = getPluginDir() + '/init.d/promtail.service.tpl' + service_path = mw.getServerDir() + content = mw.readFile(systemServiceTpl) + content = content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(systemService, content) + mw.execShell('systemctl daemon-reload') + return True @@ -153,10 +174,13 @@ def gOp(method): initDreplace() data = mw.execShell('systemctl ' + method + ' '+getPluginName()) - mw.execShell('systemctl ' + method + ' '+getPluginName()) - if data[1] == '': - return 'ok' - return data[1] + if data[1] != '': + return data[1] + + data = mw.execShell('systemctl ' + method + ' promtail') + if data[1] != '': + return data[1] + return 'ok' def start(): @@ -180,6 +204,11 @@ def initdStatus(): data = mw.execShell(shell_cmd) if data[0] == '': return 'fail' + + shell_cmd = 'systemctl status promtail|grep loaded|grep "enabled;"' + data = mw.execShell(shell_cmd) + if data[0] == '': + return 'fail' return 'ok' @@ -191,6 +220,10 @@ def initdInstall(): data = mw.execShell('systemctl enable loki') if data[1] != '': return data[1] + + data = mw.execShell('systemctl enable promtail') + if data[1] != '': + return data[1] return 'ok' @@ -202,6 +235,10 @@ def initdUinstall(): data = mw.execShell('systemctl disable loki') if data[1] != '': return data[1] + + data = mw.execShell('systemctl enable promtail') + if data[1] != '': + return data[1] return 'ok' def grafanaUrl():