diff --git a/plugins/keepalived/config/keepalived.conf b/plugins/keepalived/config/keepalived.conf
index d9f7181e6..225ff0c1a 100644
--- a/plugins/keepalived/config/keepalived.conf
+++ b/plugins/keepalived/config/keepalived.conf
@@ -5,14 +5,14 @@ global_defs {
}
vrrp_script chk_mysql_port {
- script "{$PLUGIN_PATH}/scripts/chk_mysql.sh"
+ script "{$PLUGIN_PATH}/scripts/chk.sh mysql"
interval 2
weight –5
fall 2
rise 1
}
-vrrp_instance VI_1 {
+vrrp_instance VI_MYSQL {
state MASTER
interface {$ETH_XX}
virtual_router_id 51
diff --git a/plugins/keepalived/index.html b/plugins/keepalived/index.html
index f67413b19..3743d47af 100755
--- a/plugins/keepalived/index.html
+++ b/plugins/keepalived/index.html
@@ -6,8 +6,7 @@
自启动
配置修改
-
-
+ 脚本模板
diff --git a/plugins/keepalived/index.py b/plugins/keepalived/index.py
index 701627091..3c17abe97 100755
--- a/plugins/keepalived/index.py
+++ b/plugins/keepalived/index.py
@@ -97,6 +97,21 @@ def readConfigTpl():
content = contentReplace(content)
return mw.returnJson(True, 'ok', content)
+
+def defaultScriptsTpl():
+ path = getServerDir() + "/scripts/chk.sh"
+ return path
+
+def configScriptsTpl():
+ path = getServerDir() + '/scripts'
+ pathFile = os.listdir(path)
+ tmp = []
+ for one in pathFile:
+ file = path + '/' + one
+ tmp.append(file)
+ return mw.getJson(tmp)
+
+
def status():
data = mw.execShell(
"ps aux|grep keepalived |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'")
@@ -117,13 +132,27 @@ def contentReplace(content):
# 未找到
content = content.replace('{$ETH_XX}', 'eth1')
else:
- #
+ # 已找到
content = content.replace('{$ETH_XX}', ethx[0])
return content
+def copyScripts():
+ # 复制检查脚本
+ src_scripts_path = getPluginDir() + '/scripts'
+ dst_scripts_path = getServerDir() + '/scripts'
+ if not os.path.exists(dst_scripts_path):
+ cmd = 'cp -rf ' +src_scripts_path+' '+dst_scripts_path
+ t = mw.execShell(cmd)
+ acl_cmd = 'chmod +x '+dst_scripts_path+'/*.sh'
+ # print(acl_cmd)
+ mw.execShell(acl_cmd)
+ # print(t)
+ return True
+ return False
+
def initDreplace():
file_tpl = getInitDTpl()
@@ -150,13 +179,13 @@ def initDreplace():
dst_conf = getServerDir() + '/etc/keepalived/keepalived.conf'
dst_conf_init = getServerDir() + '/init.pl'
if not os.path.exists(dst_conf_init):
- conf_content = mw.readFile(getConfTpl())
-
- conf_content = contentReplace(conf_content)
- mw.writeFile(dst_conf, conf_content)
+ content = mw.readFile(getConfTpl())
+ content = contentReplace(content)
+ mw.writeFile(dst_conf, content)
mw.writeFile(dst_conf_init, 'ok')
- # route -n | grep ^0.0.0.0 | awk '{print $8}'
+ # 复制检查脚本
+ copyScripts()
# systemd
systemDir = mw.systemdCfgDir()
@@ -164,9 +193,9 @@ def initDreplace():
if os.path.exists(systemDir) and not os.path.exists(systemService):
systemServiceTpl = getPluginDir() + '/init.d/' + getPluginName() + '.service.tpl'
service_path = mw.getServerDir()
- se_content = mw.readFile(systemServiceTpl)
- se_content = contentReplace(se_content)
- mw.writeFile(systemService, se_content)
+ content = mw.readFile(systemServiceTpl)
+ content = contentReplace(content)
+ mw.writeFile(systemService, content)
mw.execShell('systemctl daemon-reload')
return file_bin
@@ -308,6 +337,10 @@ if __name__ == "__main__":
print(runLog())
elif func == 'config_tpl':
print(configTpl())
+ elif func == 'default_scripts_tpl':
+ print(defaultScriptsTpl())
+ elif func == 'config_scripts_tpl':
+ print(configScriptsTpl())
elif func == 'read_config_tpl':
print(readConfigTpl())
else:
diff --git a/plugins/keepalived/scripts/chk.sh b/plugins/keepalived/scripts/chk.sh
index 6f02ec93c..f57a896ad 100644
--- a/plugins/keepalived/scripts/chk.sh
+++ b/plugins/keepalived/scripts/chk.sh
@@ -1,6 +1,8 @@
#!/bin/bash
+# 计划任务,恢复后,可自动拉起keepalived
+# {$SERVER_PATH}/keepalived/scripts/chk.sh mysql
# check script bash
curPath=`pwd`
diff --git a/plugins/keepalived/scripts/chk_mysql.sh b/plugins/keepalived/scripts/chk_mysql.sh
index e5634f2e0..df224d95c 100644
--- a/plugins/keepalived/scripts/chk_mysql.sh
+++ b/plugins/keepalived/scripts/chk_mysql.sh
@@ -1,5 +1,8 @@
#!/bin/bash
+# 计划任务,恢复后,可自动拉起keepalived
+# {$SERVER_PATH}/keepalived/scripts/chk_mysql.sh
+
date +'%Y-%m-%d %H:%M:%S'
echo "start check mysql status ..."
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)