From d3a4db511a3e3d3e6b71141edf8b1e4634ec125a Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 28 Aug 2022 22:50:17 +0800 Subject: [PATCH] haproxy init --- plugins/haproxy/conf/haproxy.conf | 9 + plugins/haproxy/ico.png | Bin 0 -> 3548 bytes plugins/haproxy/index.html | 21 ++ plugins/haproxy/index.py | 355 +++++++++++++++++++++ plugins/haproxy/info.json | 19 ++ plugins/haproxy/init.d/haproxy.service.tpl | 12 + plugins/haproxy/init.d/haproxy.tpl | 82 +++++ plugins/haproxy/install.sh | 44 +++ plugins/haproxy/js/haproxy.js | 135 ++++++++ plugins/haproxy/versions/2.6/install.sh | 70 ++++ 10 files changed, 747 insertions(+) create mode 100755 plugins/haproxy/conf/haproxy.conf create mode 100644 plugins/haproxy/ico.png create mode 100755 plugins/haproxy/index.html create mode 100755 plugins/haproxy/index.py create mode 100755 plugins/haproxy/info.json create mode 100644 plugins/haproxy/init.d/haproxy.service.tpl create mode 100644 plugins/haproxy/init.d/haproxy.tpl create mode 100755 plugins/haproxy/install.sh create mode 100755 plugins/haproxy/js/haproxy.js create mode 100755 plugins/haproxy/versions/2.6/install.sh diff --git a/plugins/haproxy/conf/haproxy.conf b/plugins/haproxy/conf/haproxy.conf new file mode 100755 index 000000000..8885d0e78 --- /dev/null +++ b/plugins/haproxy/conf/haproxy.conf @@ -0,0 +1,9 @@ +global + log 127.0.0.1 local2 + chroot /var/lib/haproxy + pidfile /var/run/haproxy.pid + maxconn 4000 + user haproxy + group haproxy + daemon + stats socket /var/lib/haproxy/stats diff --git a/plugins/haproxy/ico.png b/plugins/haproxy/ico.png new file mode 100644 index 0000000000000000000000000000000000000000..3fc4e8c6d55326f934b10c6280b5c3dac30ad24f GIT binary patch literal 3548 zcmZ{mc{J4T+s8jMW0&Pih!jzTFf*26k{D!0_RQEB%NWWS8L}ial%*^sDcMsrWR0xZ z5+Q>^mZ)sWSh5b0-}Id4kMHw4=Q;Pe?)N#@^}62o^3Q$8Tbdj5@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(L|3$~^*_EkDIs_& zZDzG60`sf~Wp8Rdd1&F>liGufsgMd2SV*VrMJ;?OLC7L?!!hli?g!PE4($oYHIe*# zKYQ8N>8Tg|V+wTI7U?_vp;A5UekFk>qt=-&Tek-61;TeuxvS_6fLn)&K0l0?D0XVY zke_Fp9IvgonQ@K|o2Jx0*4f5?ubB(B<}Fhzpk~S5c^KBd?Yr6^=6)RTNSICjqtXYL zqfjrr*(NA!Z+Y$0k29jP=oU^ljGZ3hM&g`yJ(;&+FT_mydo4LvM_ipfb5HW;nNYtT zaq)y(<`KW%a3CD&GqIafEsRX%qY>6xB99m@4Vx8iUl8pG@u!gUyg6F;KV+`I2=N)8 zR6i0CFxhdc^<&{~RU$>!@9L<=Wx4%)XWR*x&#dvPSlhxVC|uI?P|K|J7`MVjP`E{H zpYzQ1Bz39)gefm7!-v<9o8EcrDoj5RvyadI>=`p-!1|Y;3N*3{^mGd(AUy&IECJw9 zI8+%1Q-*8Vz|@fHT1XAJ5)_JrLXD`D`Tx^EB76FHh5r8y>Qgu0+C2d7D@qN zg$E6)|HWYbx*(Bgf)CL<5YT|ZlM^r9WHDm@^7&uJ*2go@`!6CH4w+yf;{QU-d`N`A zP=5mOKf6-(_amOK#F_t>kC_dN0$`d@O$`K0O%1-c$WUM*!vFHQg1PZ05 z8^mOl(f=xAtucU?k1v6Bd==Foe_yhjCq-35Qx#=lXkem!RTZwOt*z?q<{v-~33c@) j6UnYV9%MgP7y<@`Ayinq609Zvy#WAYWNuiB!c+eP!!vpS literal 0 HcmV?d00001 diff --git a/plugins/haproxy/index.html b/plugins/haproxy/index.html new file mode 100755 index 000000000..f64aa937b --- /dev/null +++ b/plugins/haproxy/index.html @@ -0,0 +1,21 @@ +
+
+
+

服务

+

自启动

+

配置修改

+

运行日志

+

查询日志

+

运行状态

+

说明

+
+
+
+
+
+
+ \ No newline at end of file diff --git a/plugins/haproxy/index.py b/plugins/haproxy/index.py new file mode 100755 index 000000000..c79e2a831 --- /dev/null +++ b/plugins/haproxy/index.py @@ -0,0 +1,355 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import re +import string +import subprocess + +sys.path.append(os.getcwd() + "/class/core") +import mw + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'haproxy' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getInitDFile(): + if app_debug: + return '/tmp/' + getPluginName() + return '/etc/init.d/' + getPluginName() + + +def getConfTpl(): + path = getPluginDir() + "/conf/haproxy.conf" + return path + + +def getConf(): + path = getServerDir() + "/sphinx.conf" + return path + + +def getInitDTpl(): + path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" + return path + + +def getArgs(): + args = sys.argv[2:] + tmp = {} + args_len = len(args) + + if args_len == 1: + t = args[0].strip('{').strip('}') + t = t.split(':') + tmp[t[0]] = t[1] + elif args_len > 1: + for i in range(len(args)): + t = args[i].split(':') + tmp[t[0]] = t[1] + return tmp + + +def checkArgs(data, ck=[]): + for i in range(len(ck)): + if not ck[i] in data: + return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) + return (True, mw.returnJson(True, 'ok')) + + +def configTpl(): + path = getPluginDir() + '/tpl' + pathFile = os.listdir(path) + tmp = [] + for one in pathFile: + file = path + '/' + one + tmp.append(file) + return mw.getJson(tmp) + + +def readConfigTpl(): + args = getArgs() + data = checkArgs(args, ['file']) + if not data[0]: + return data[1] + + content = mw.readFile(args['file']) + content = contentReplace(content) + return mw.returnJson(True, 'ok', content) + + +def contentReplace(content): + service_path = mw.getServerDir() + content = content.replace('{$ROOT_PATH}', mw.getRootDir()) + content = content.replace('{$SERVER_PATH}', service_path) + content = content.replace('{$SERVER_APP}', service_path + '/haproxy') + return content + + +def status(): + data = mw.execShell( + "ps -ef|grep haproxy |grep -v grep | grep -v python | awk '{print $2}'") + if data[0] == '': + return 'stop' + return 'start' + + +def mkdirAll(): + content = mw.readFile(getConf()) + rep = 'path\s*=\s*(.*)' + p = re.compile(rep) + tmp = p.findall(content) + + for x in tmp: + if x.find('binlog') != -1: + mw.execShell('mkdir -p ' + x) + else: + mw.execShell('mkdir -p ' + os.path.dirname(x)) + + +def initDreplace(): + + file_tpl = getInitDTpl() + service_path = os.path.dirname(os.getcwd()) + + initD_path = getServerDir() + '/init.d' + if not os.path.exists(initD_path): + os.mkdir(initD_path) + file_bin = initD_path + '/' + getPluginName() + + # initd replace + if not os.path.exists(file_bin): + content = mw.readFile(file_tpl) + content = contentReplace(content) + mw.writeFile(file_bin, content) + mw.execShell('chmod +x ' + file_bin) + + # config replace + conf_bin = getConf() + if not os.path.exists(conf_bin): + conf_content = mw.readFile(getConfTpl()) + conf_content = contentReplace(conf_content) + mw.writeFile(getServerDir() + '/haproxy.conf', conf_content) + + # systemd + systemDir = mw.systemdCfgDir() + systemService = systemDir + '/haproxy.service' + systemServiceTpl = getPluginDir() + '/init.d/haproxy.service.tpl' + if os.path.exists(systemDir) and not os.path.exists(systemService): + service_path = mw.getServerDir() + se_content = mw.readFile(systemServiceTpl) + se_content = se_content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(systemService, se_content) + mw.execShell('systemctl daemon-reload') + + mkdirAll() + return file_bin + + +def checkIndexSph(): + content = mw.readFile(getConf()) + rep = 'path\s*=\s*(.*)' + p = re.compile(rep) + tmp = p.findall(content) + for x in tmp: + if x.find('binlog') != -1: + continue + else: + p = x + '.sph' + if os.path.exists(p): + return False + return True + + +def sphOp(method): + file = initDreplace() + + if not mw.isAppleSystem(): + data = mw.execShell('systemctl ' + method + ' haproxy') + if data[1] == '': + return 'ok' + return 'fail' + + data = mw.execShell(file + ' ' + method) + if data[1] == '': + return 'ok' + return data[1] + + +def start(): + return sphOp('start') + + +def stop(): + return sphOp('stop') + + +def restart(): + return sphOp('restart') + + +def reload(): + return sphOp('reload') + + +def rebuild(): + file = initDreplace() + subprocess.Popen(file + ' rebuild &', + stdout=subprocess.PIPE, shell=True) + # data = mw.execShell(file + ' rebuild') + return 'ok' + + +def initdStatus(): + if mw.isAppleSystem(): + return "Apple Computer does not support" + + shell_cmd = 'systemctl status haproxy | grep loaded | grep "enabled;"' + data = mw.execShell(shell_cmd) + if data[0] == '': + return 'fail' + return 'ok' + + +def initdInstall(): + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl enable haproxy') + return 'ok' + + +def initdUinstall(): + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl disable haproxy') + return 'ok' + + +def runLog(): + path = getConf() + content = mw.readFile(path) + rep = 'log\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0] + + +def getPort(): + path = getConf() + content = mw.readFile(path) + rep = 'listen\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0] + + +def queryLog(): + path = getConf() + content = mw.readFile(path) + rep = 'query_log\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0] + + +def runStatus(): + s = status() + if s != 'start': + return mw.returnJson(False, '没有启动程序') + + sys.path.append(getPluginDir() + "/class") + import sphinxapi + + sh = sphinxapi.SphinxClient() + port = getPort() + sh.SetServer('127.0.0.1', port) + info_status = sh.Status() + + rData = {} + for x in range(len(info_status)): + rData[info_status[x][0]] = info_status[x][1] + + return mw.returnJson(True, 'ok', rData) + + +def sphinxConfParse(): + file = getConf() + bin_dir = getServerDir() + content = mw.readFile(file) + rep = 'index\s(.*)' + sindex = re.findall(rep, content) + indexlen = len(sindex) + cmd = {} + if indexlen > 0: + cmd_index = [] + cmd_delta = [] + for x in range(indexlen): + if sindex[x].find(':') != -1: + cmd_delta.append(sindex[x]) + else: + cmd_index.append(sindex[x]) + + cmd['index'] = cmd_index + cmd['delta'] = cmd_delta + cmd['cmd'] = bin_dir + '/bin/bin/indexer -c ' + bin_dir + '/sphinx.conf' + return cmd + + +def sphinxCmd(): + data = sphinxConfParse() + if 'index' in data: + return mw.returnJson(True, 'ok', data) + else: + return mw.returnJson(False, 'no index') + + +if __name__ == "__main__": + func = sys.argv[1] + if func == 'status': + print(status()) + elif func == 'start': + print(start()) + elif func == 'stop': + print(stop()) + elif func == 'restart': + print(restart()) + elif func == 'reload': + print(reload()) + elif func == 'rebuild': + print(rebuild()) + elif func == 'initd_status': + print(initdStatus()) + elif func == 'initd_install': + print(initdInstall()) + elif func == 'initd_uninstall': + print(initdUinstall()) + elif func == 'conf': + print(getConf()) + elif func == 'config_tpl': + print(configTpl()) + elif func == 'read_config_tpl': + print(readConfigTpl()) + elif func == 'run_log': + print(runLog()) + elif func == 'query_log': + print(queryLog()) + elif func == 'run_status': + print(runStatus()) + elif func == 'sphinx_cmd': + print(sphinxCmd()) + else: + print('error') diff --git a/plugins/haproxy/info.json b/plugins/haproxy/info.json new file mode 100755 index 000000000..98700f813 --- /dev/null +++ b/plugins/haproxy/info.json @@ -0,0 +1,19 @@ +{ + "sort": 7, + "ps": "可靠、高性能的TCP/HTTP负载平衡器", + "name": "haproxy", + "title": "haproxy", + "shell": "install.sh", + "versions":["2.6"], + "updates":["2.6"], + "tip": "soft", + "checks": "server/haproxy", + "path": "server/haproxy", + "display": 1, + "author": "midoks", + "date": "2022-08-26", + "home": "https://www.haproxy.org/", + "doc1": "https://www.haproxy.org/", + "type": 0, + "pid": "4" +} \ No newline at end of file diff --git a/plugins/haproxy/init.d/haproxy.service.tpl b/plugins/haproxy/init.d/haproxy.service.tpl new file mode 100644 index 000000000..ce417c2be --- /dev/null +++ b/plugins/haproxy/init.d/haproxy.service.tpl @@ -0,0 +1,12 @@ +[Unit] +Description=he Reliable, High Performance TCP/HTTP Load Balancer +After=network.target + +[Service] +Type=forking +ExecStart={$SERVER_PATH}/sphinx/bin/bin/searchd -c {$SERVER_PATH}/sphinx/sphinx.conf +ExecReload=/bin/kill -USR2 $MAINPID +Restart=on-failure + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/plugins/haproxy/init.d/haproxy.tpl b/plugins/haproxy/init.d/haproxy.tpl new file mode 100644 index 000000000..4652aa078 --- /dev/null +++ b/plugins/haproxy/init.d/haproxy.tpl @@ -0,0 +1,82 @@ +#! /bin/bash +# +# searchd: sphinx Daemon +# +# chkconfig: - 90 25 +# description: sphinx Daemon +# +### BEGIN INIT INFO +# Provides: sphinx +# Required-Start: $syslog +# Required-Stop: $syslog +# Should-Start: $local_fs +# Should-Stop: $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: sphinx - Document Index Daemon +# Description: sphinx - Document Index Daemon +### END INIT INFO + +APP_PATH={$SERVER_APP} +APP_CONF={$SERVER_APP}/sphinx.conf +prog="sphinx" + +start () { + echo -n $"Starting $prog: " + ${APP_PATH}/bin/bin/searchd -c ${APP_CONF} + if [ "$?" != 0 ] ; then + echo " failed" + exit 1 + else + echo " done" + fi +} + +rebuild () { + ${APP_PATH}/bin/bin/indexer -c ${APP_CONF} --all --rotate & +} + + +stop () { + echo -n $"Stopping $prog: " + if [ ! -e ${APP_PATH}/index/searchd.pid ]; then + echo -n $"$prog is not running." + exit 1 + fi + kill `cat ${APP_PATH}/index/searchd.pid` + if [ "$?" != 0 ] ; then + echo " failed" + exit 1 + else + rm -f ${APP_PATH}/index/searchd.pid + echo " done" + fi +} + +restart () { + $0 stop + sleep 2 + $0 start +} + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart|reload) + restart + ;; + rebuild) + rebuild + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|reload}" + exit 1 + ;; +esac + +exit $? \ No newline at end of file diff --git a/plugins/haproxy/install.sh b/plugins/haproxy/install.sh new file mode 100755 index 000000000..5f656275b --- /dev/null +++ b/plugins/haproxy/install.sh @@ -0,0 +1,44 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") +install_tmp=${rootPath}/tmp/mw_install.pl + + +action=$1 +type=$2 + +echo $action $type + +if [ "${2}" == "" ];then + echo '缺少安装脚本...' > $install_tmp + exit 0 +fi + +if [ ! -d $curPath/versions/$2 ];then + echo '缺少安装脚本2...' > $install_tmp + exit 0 +fi + +if [ "${action}" == "uninstall" ];then + + if [ -f /usr/lib/systemd/system/haproxy.service ] || [ -f /lib/systemd/system/haproxy.service ];then + systemctl stop haproxy + systemctl disable haproxy + rm -rf /usr/lib/systemd/system/haproxy.service + rm -rf /lib/systemd/system/haproxy.service + systemctl daemon-reload + fi +fi + +sh -x $curPath/versions/$2/install.sh $1 + +if [ "${action}" == "install" ] && [ -d $serverPath/haproxy ];then + #初始化 + cd ${rootPath} && python3 ${rootPath}/plugins/haproxy/index.py start ${type} + cd ${rootPath} && python3 ${rootPath}/plugins/haproxy/index.py initd_install ${type} +fi diff --git a/plugins/haproxy/js/haproxy.js b/plugins/haproxy/js/haproxy.js new file mode 100755 index 000000000..37448384c --- /dev/null +++ b/plugins/haproxy/js/haproxy.js @@ -0,0 +1,135 @@ +function spPostMin(method, args, callback){ + + var req_data = {}; + req_data['name'] = 'haproxy'; + req_data['func'] = method; + + if (typeof(args) != 'undefined' && args!=''){ + req_data['args'] = JSON.stringify(args); + } + + $.post('/plugins/run', req_data, function(data) { + if (!data.status){ + layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + +function spPost(method, args, callback){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + spPostMin(method,args,function(data){ + layer.close(loadT); + if(typeof(callback) == 'function'){ + callback(data); + } + }); +} + +function rebuild(){ + var con = ''; + $(".soft-man-con").html(con); +} + +function rebuildIndex(){ + spPost('rebuild', '', function(data){ + if (data.data == 'ok'){ + layer.msg('在重建中..',{icon:1,time:2000,shade: [0.3, '#000']}); + } else { + layer.msg(data.data,{icon:2,time:2000,shade: [0.3, '#000']}); + } + }); +} + +function secToTime(s) { + var t; + if(s > -1){ + var hour = Math.floor(s/3600); + var min = Math.floor(s/60) % 60; + var sec = s % 60; + if(hour < 10) { + t = '0'+ hour + ":"; + } else { + t = hour + ":"; + } + + if(min < 10){t += "0";} + t += min + ":"; + if(sec < 10){t += "0";} + t += sec.toFixed(2); + } + return t; +} + + +function runStatus(){ + spPost('run_status', '', function(data){ + var rdata = $.parseJSON(data.data); + if (!rdata['status']){ + layer.msg(rdata['msg'],{icon:2,time:2000,shade: [0.3, '#000']}); + return; + } + var idata = rdata.data; + // console.log(idata); + var con = '
\ + \ + \ + \ + \ + \ + \ +
运行时间' + secToTime(idata.uptime) + '每秒查询' + parseInt(parseInt(idata.queries) / parseInt(idata.uptime)) + '
总连接次数' + idata.connections + 'work_queue_length' +idata.work_queue_length + '
agent_connect' + idata.agent_connect+ 'workers_active' + idata.workers_active + '
agent_retry' + idata.agent_retry + 'workers_total' + idata.workers_total + '
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
command_delete' + idata.command_delete + 'command_delete
command_excerpt' + idata.command_excerpt + 'command_excerpt
command_flushattrs' + idata.command_flushattrs + 'command_flushattrs
command_keywords' + idata.command_keywords + 'command_keywords
command_persist' + idata.command_persist + 'command_persist
command_search' + idata.command_search + 'command_search
command_status' + idata.command_status + 'command_status
command_update' + idata.command_update + 'command_update
'; + + $(".soft-man-con").html(con); + }); +} + +function readme(){ + spPost('sphinx_cmd', '', function(data){ + + var rdata = $.parseJSON(data.data); + if (!rdata['status']){ + layer.msg(rdata['msg'],{icon:2,time:2000,shade: [0.3, '#000']}); + return; + } + + var con = '
    '; + + con += '
  • 如果数据量比较大,第一次启动会失败!(可通过手动建立索引)
  • '; + //主索引 + for (var i = 0; i < rdata['data']['index'].length; i++) { + var index_t = rdata['data']['index'][i]; + con += '
  • 主索引:' + rdata['data']['cmd'] + ' '+ index_t +' --rotate
  • '; + } + + for (var i = 0; i < rdata['data']['delta'].length; i++) { + var delta_t = rdata['data']['delta'][i]; + var list = delta_t.split(':'); + // console.log(list); + con += '
  • 增量索引:' + rdata['data']['cmd'] + ' '+ list[0] +' --rotate
  • '; + con += '
  • 合并索引:' + rdata['data']['cmd'] + ' --merge '+ list[1] + ' ' + list[0] +' --rotate
  • '; + } + con += '
'; + + $(".soft-man-con").html(con); + }); + +} + diff --git a/plugins/haproxy/versions/2.6/install.sh b/plugins/haproxy/versions/2.6/install.sh new file mode 100755 index 000000000..74ae7e193 --- /dev/null +++ b/plugins/haproxy/versions/2.6/install.sh @@ -0,0 +1,70 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") +sysName=`uname` + +install_tmp=${rootPath}/tmp/mw_install.pl + + +bash ${rootPath}/scripts/getos.sh +OSNAME=`cat ${rootPath}/data/osname.pl` +OSNAME_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'` + + +VERSION=2.6.4 +MIN_VERSION=2.6 +Install_App() +{ + + echo '正在安装脚本文件...' > $install_tmp + mkdir -p $serverPath/haproxy + + APP_DIR=${serverPath}/source/haproxy + mkdir -p $APP_DIR + + if [ ! -f ${APP_DIR}/haproxy-${VERSION}.tar.gz ];then + if [ $sysName == 'Darwin' ]; then + wget -O ${APP_DIR}/haproxy-${VERSION}.tar.gz https://www.haproxy.org/download/${MIN_VERSION}/src/haproxy-${VERSION}.tar.gz + else + curl -sSLo ${APP_DIR}/haproxy-${VERSION}.tar.gz https://www.haproxy.org/download/${MIN_VERSION}/src/haproxy-${VERSION}.tar.gz + fi + fi + + if [ ! -f ${APP_DIR}/haproxy-${VERSION}.tar.gz ];then + curl -sSLo ${APP_DIR}/haproxy-${VERSION}.tar.gz https://www.haproxy.org/download/${MIN_VERSION}/src/haproxy-${VERSION}.tar.gz + fi + + + cd ${APP_DIR} && tar -zxvf haproxy-${VERSION}.tar.gz + + if [ "$OSNAME" == "macos" ];then + cd ${APP_DIR}/haproxy-${VERSION} && make TARGET=osx && make install PREFIX=$serverPath/haproxy + else + cd ${APP_DIR}/haproxy-${VERSION} && make TARGET=linux-glibc && make install PREFIX=$serverPath/haproxy + fi + + echo $MIN_VERSION > $serverPath/haproxy/version.pl + echo 'Install_HA' > $install_tmp +} + +Uninstall_App() +{ + if [ -f $serverPath/haproxy/initd/haproxy ];then + $serverPath/haproxy/initd/haproxy stop + fi + + rm -rf $serverPath/haproxy + echo "Uninstall_HA" > $install_tmp +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_App +else + Uninstall_App +fi