From 034939a0c5f9f21e09c9cce9aa424bec2a222186 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 1 Aug 2019 16:46:34 +0800 Subject: [PATCH] solr add --- plugins/solr/ico.png | Bin 0 -> 978 bytes plugins/solr/index.html | 21 ++++ plugins/solr/index.py | 200 +++++++++++++++++++++++++++++++++++ plugins/solr/info.json | 16 +++ plugins/solr/init.d/solr.tpl | 78 ++++++++++++++ plugins/solr/install.sh | 46 ++++++++ plugins/solr/js/solr.js | 86 +++++++++++++++ 7 files changed, 447 insertions(+) create mode 100644 plugins/solr/ico.png create mode 100755 plugins/solr/index.html create mode 100755 plugins/solr/index.py create mode 100755 plugins/solr/info.json create mode 100644 plugins/solr/init.d/solr.tpl create mode 100755 plugins/solr/install.sh create mode 100755 plugins/solr/js/solr.js diff --git a/plugins/solr/ico.png b/plugins/solr/ico.png new file mode 100644 index 0000000000000000000000000000000000000000..91f601fc3d1fc683009bdc56ce4190fa71007ab6 GIT binary patch literal 978 zcmex=``2_j6xdp@o1cgOJMMZh|#U;cRDJhSy?$nc)58+NCy88 zFbHxms4y5XGb%AK2{JMZGX6ipPyuoxE6AyEz{bSF%Fe;aDZs$Q#K6kT!oQ504(bQCR2&vu_yk+ua7uiJTFYdA1u+i4a zFuK*7Lw+*jFXj5*9q0W&-$>YQV}-dE333Kl#_MymhTx zVy0MEaHjEM`wiuS!rAhAYu5f}Fg|hm;-{jTO^X$3@&v#5#><{GowwntWm@v;HBW+4 zw}o;2w3Sq9{aq|%bneg9S$;X^H}fYvKAwA6rt;?1msc!(b57k|8#({}yoeXqmI`!5 zYb~7_vD~0bxo1VCd5C&$)8~+*-!`3jb#kt+e{jjGbM;<|r}~n^rbPA>G1)9u{P)C< z|92cq?)#ri;>$|*)i3%gTbnC3b8Eax+IC-)J$jR)PiLOLHBm`xW9;9k^~%oDvMvAa z-t?Nr@Jj81dRpq%>A|zM&3$9^VtwXbXYYWQH*zoT5IK44_Sx4CXV!3QA6Jrm{ABq- z9)2OiSzA|a`L_KPTjA1r#&Wa$lV`kq7G^6dx_Zfl<5r*35~NELELJ4{i*De1CVl11 z>VU8OeM^@w*T1%S^1V~mQN?aTUvDfrr*UVi`4SJUm9oJHCEAnE-!hMjmR@eMW?lU{ z%$6j~q&4mnk z^^>>hZ +
+
+

服务

+

自启动

+

管理

+

日志

+

说明

+
+
+
+
+
+ + + \ No newline at end of file diff --git a/plugins/solr/index.py b/plugins/solr/index.py new file mode 100755 index 000000000..c9b8fc028 --- /dev/null +++ b/plugins/solr/index.py @@ -0,0 +1,200 @@ +# coding: utf-8 + +import time +import random +import os +import json +import re +import sys + +sys.path.append(os.getcwd() + "/class/core") +import public + +app_debug = False +if public.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'solr' + + +def getPluginDir(): + return public.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return public.getServerDir() + '/' + getPluginName() + + +def getInitDFile(): + if app_debug: + return '/tmp/' + getPluginName() + return '/etc/init.d/' + getPluginName() + + +def getInitDTpl(): + return getPluginDir() + "/init.d/" + getPluginName() + ".tpl" + +def getLog(): + return getServerDir() + "/server/logs/solr.log" + +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, public.returnJson(False, '参数:(' + ck[i] + ')没有!')) + return (True, public.returnJson(True, 'ok')) + + +def status(): + pn = getPluginName(); + data = public.execShell("ps -ef|grep "+pn+" |grep -v grep | grep -v python | awk '{print $2}'") + if data[0] == '': + return 'stop' + return 'start' + + +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) + + + user = 'www' + if public.getOs() == 'darwin': + user = public.execShell("who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() + + file_bin = initD_path + '/' + getPluginName() + if not os.path.exists(file_bin): + content = public.readFile(file_tpl) + content = content.replace('{$SERVER_PATH}', service_path) + content = content.replace('{$RUN_USER}', user) + public.writeFile(file_bin, content) + public.execShell('chmod +x ' + file_bin) + + return file_bin + +def start(): + file = initDreplace() + data = public.execShell(file + ' start') + if data[1] == '': + return 'ok' + return 'fail' + + +def stop(): + file = initDreplace() + data = public.execShell(file + ' stop') + if data[1] == '': + return 'ok' + return 'fail' + + +def restart(): + file = initDreplace() + data = public.execShell(file + ' restart') + if data[1] == '': + return 'ok' + return 'fail' + + +def reload(): + file = initDreplace() + data = public.execShell(file + ' reload') + if data[1] == '': + return 'ok' + return 'fail' + + +def initdStatus(): + initd_bin = getInitDFile() + if os.path.exists(initd_bin): + return 'ok' + return 'fail' + +def initdInstall(): + import shutil + + source_bin = initDreplace() + initd_bin = getInitDFile() + shutil.copyfile(source_bin, initd_bin) + public.execShell('chmod +x ' + initd_bin) + + if not app_debug: + public.execShell('chkconfig --add ' + getPluginName()) + return 'ok' + +def initdUinstall(): + if not app_debug: + public.execShell('chkconfig --del ' + getPluginName()) + + initd_bin = getInitDFile() + + if os.path.exists(initd_bin): + os.remove(initd_bin) + return 'ok' + + +def collectionList(): + path = getServerDir()+'/server/solr' + listDir = os.listdir(path) + data = [] + for dirname in listDir: + dirpath = path+'/'+dirname + if not os.path.isdir(dirpath): + continue + if dirname == 'configsets': + continue + + tmp = {} + tmp['name'] = dirname + data.append(tmp) + return public.returnJson(True, 'OK', data) + + +# rsyncdReceive +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 == 'initd_status': + print initdStatus() + elif func == 'initd_install': + print initdInstall() + elif func == 'initd_uninstall': + print initdUinstall() + elif func == 'run_log': + print getLog() + elif func == 'collection_list': + print collectionList() + else: + print 'error' diff --git a/plugins/solr/info.json b/plugins/solr/info.json new file mode 100755 index 000000000..201017635 --- /dev/null +++ b/plugins/solr/info.json @@ -0,0 +1,16 @@ +{ + "id":10, + "title":"Solr", + "tip":"soft", + "name":"solr", + "type":"软件", + "ps":"Solr是一个独立的企业级搜索应用服务器", + "versions":"8.2.0", + "shell":"install.sh", + "checks":"server/solr", + "path": "server/solr", + "author":"midoks", + "home":"https://lucene.apache.org/solr/", + "date":"2019-08-01", + "pid":"2" +} \ No newline at end of file diff --git a/plugins/solr/init.d/solr.tpl b/plugins/solr/init.d/solr.tpl new file mode 100644 index 000000000..c2194130a --- /dev/null +++ b/plugins/solr/init.d/solr.tpl @@ -0,0 +1,78 @@ +#!/bin/sh +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +### BEGIN INIT INFO +# Provides: solr +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: Controls Apache Solr as a Service +### END INIT INFO + +# Example of a very simple *nix init script that delegates commands to the bin/solr script +# Typical usage is to do: +# +# cp bin/init.d/solr /etc/init.d/solr +# chmod 755 /etc/init.d/solr +# chown root:root /etc/init.d/solr +# update-rc.d solr defaults +# update-rc.d solr enable + +# Where you extracted the Solr distribution bundle +SOLR_INSTALL_DIR="{$SERVER_PATH}/solr" + +if [ ! -d "$SOLR_INSTALL_DIR" ]; then + echo "$SOLR_INSTALL_DIR not found! Please check the SOLR_INSTALL_DIR setting in your $0 script." + exit 1 +fi + +# Path to an include file that defines environment specific settings to override default +# variables used by the bin/solr script. It's highly recommended to define this script so +# that you can keep the Solr binary files separated from live files (pid, logs, index data, etc) +# see bin/solr.in.sh for an example +SOLR_ENV="{$SERVER_PATH}/solr/bin/solr.in.sh" + +if [ ! -f "$SOLR_ENV" ]; then + echo "$SOLR_ENV not found! Please check the SOLR_ENV setting in your $0 script." + exit 1 +fi + +# Specify the user to run Solr as; if not set, then Solr will run as root. +# Running Solr as root is not recommended for production environments +RUNAS="{$RUN_USER}" + +# verify the specified run as user exists +runas_uid="`id -u "$RUNAS"`" +if [ $? -ne 0 ]; then + echo "User $RUNAS not found! Please create the $RUNAS user before running this script." + exit 1 +fi + +case "$1" in + start|stop|restart|status) + SOLR_CMD="$1" + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit +esac + +if [ -n "$RUNAS" ]; then + sh -c "SOLR_INCLUDE=\"$SOLR_ENV\" \"$SOLR_INSTALL_DIR/bin/solr\" $SOLR_CMD" - "$RUNAS" +else + SOLR_INCLUDE="$SOLR_ENV" "$SOLR_INSTALL_DIR/bin/solr" "$SOLR_CMD" +fi diff --git a/plugins/solr/install.sh b/plugins/solr/install.sh new file mode 100755 index 000000000..cef5f1baf --- /dev/null +++ b/plugins/solr/install.sh @@ -0,0 +1,46 @@ +#!/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 + +action=$1 +version=$2 +Install_solr() +{ + echo '正在安装脚本文件...' > $install_tmp + mkdir -p $serverPath/solr + SOLR_DIR=${serverPath}/source/solr + mkdir -p $SOLR_DIR + if [ ! -f ${SOLR_DIR}/solr-8.2.0.tgz ];then + wget -O ${SOLR_DIR}/solr-8.2.0.tgz http://mirror.bit.edu.cn/apache/lucene/solr/8.2.0/solr-8.2.0.tgz + fi + + if [ ! -d $serverPath/solr/bin ];then + cd ${SOLR_DIR} && tar -zxvf solr-8.2.0.tgz + cp -rf ${SOLR_DIR}/solr-8.2.0/ $serverPath/solr + fi + + echo "$version" > $serverPath/solr/version.pl + echo '安装完成' > $install_tmp + +} + +Uninstall_solr() +{ + rm -rf $serverPath/solr + echo "卸载完成" > $install_tmp +} + + +if [ "${1}" == 'install' ];then + Install_solr $version +else + Uninstall_solr $version +fi diff --git a/plugins/solr/js/solr.js b/plugins/solr/js/solr.js new file mode 100755 index 000000000..f17bd9ef7 --- /dev/null +++ b/plugins/solr/js/solr.js @@ -0,0 +1,86 @@ +function str2Obj(str){ + var data = {}; + kv = str.split('&'); + for(i in kv){ + v = kv[i].split('='); + data[v[0]] = v[1]; + } + return data; +} + +function pPost(method,args,callback, title){ + + var _args = null; + if (typeof(args) == 'string'){ + _args = JSON.stringify(str2Obj(args)); + } else { + _args = JSON.stringify(args); + } + + var _title = '正在获取...'; + if (typeof(title) != 'undefined'){ + _title = title; + } + + var loadT = layer.msg(_title, { icon: 16, time: 0, shade: 0.3 }); + $.post('/plugins/run', {name:'solr', func:method, args:_args}, function(data) { + layer.close(loadT); + if (!data.status){ + layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + + +function collection_management(){ + pPost('collection_list', '', function(data){ + var rdata = $.parseJSON(data.data); + if (!rdata.status){ + layer.msg(rdata.msg,{icon:rdata.status?1:2,time:2000,shade: [0.3, '#000']}); + return; + } + + var list = rdata.data; + var con = ''; + con += '
'; + con += ''; + con += ''; + con += ''; + con += ''; + + con += ''; + + for (var i = 0; i < list.length; i++) { + con += ''+ + '' + + '\ + '; + } + + con += ''; + con += '
collection操作(添加)
' + list[i]['name']+'\ + 命令\ + | 删除
'; + + $(".soft-man-con").html(con); + }); +} + +function addCollection(){ + +} + + +function pRead(){ + var readme = '
    '; + readme += '
  • 使用默认solr端口,如有需要自行修改.
  • '; + readme += '
  • 如果开启防火墙,需要放行solr设置的端口,例如(8983)。
  • '; + readme += '
'; + + $('.soft-man-con').html(readme); +} \ No newline at end of file