This commit is contained in:
Mr Chen
2019-08-01 16:46:34 +08:00
parent d35c6bb02f
commit 034939a0c5
7 changed files with 447 additions and 0 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 978 B

+21
View File
@@ -0,0 +1,21 @@
<div class="bt-form">
<div class="bt-w-main">
<div class="bt-w-menu">
<p class="bgw" onclick="pluginService('solr');">服务</p>
<p onclick="pluginInitD('solr');">自启动</p>
<p onclick="collection_management();">管理</p>
<p onclick="pluginLogs('solr','','run_log');">日志</p>
<p onclick="pRead()">说明</p>
</div>
<div class="bt-w-con pd15">
<div class="soft-man-con"></div>
</div>
</div>
</div>
<script type="text/javascript">
resetPluginWinWidth(700);
$.getScript( "/plugins/file?name=solr&f=js/solr.js", function() {
pluginService('solr');
});
</script>
+200
View File
@@ -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'
+16
View File
@@ -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"
}
+78
View File
@@ -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
+46
View File
@@ -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
+86
View File
@@ -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 += '<div class="divtable" style="margin-top:5px;"><table class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0">';
con += '<thead><tr>';
con += '<th>collection</th>';
con += '<th>操作(<a class="btlink" onclick="addCollection()">添加</a>)</th>';
con += '</tr></thead>';
con += '<tbody>';
for (var i = 0; i < list.length; i++) {
con += '<tr>'+
'<td>' + list[i]['name']+'</td>' +
'<td>\
<a class="btlink" onclick="cmdReceive(\''+list[i]['name']+'\')">命令</a>\
| <a class="btlink" onclick="delReceive(\''+list[i]['name']+'\')">删除</a></td>\
</tr>';
}
con += '</tbody>';
con += '</table></div>';
$(".soft-man-con").html(con);
});
}
function addCollection(){
}
function pRead(){
var readme = '<ul class="help-info-text c7">';
readme += '<li>使用默认solr端口,如有需要自行修改.</li>';
readme += '<li>如果开启防火墙,需要放行solr设置的端口,例如(8983)。</li>';
readme += '</ul>';
$('.soft-man-con').html(readme);
}