pull/109/head
midoks 4 years ago
parent 7a4de6e227
commit 42b25be204
  1. 6
      class/core/mw.py
  2. 12
      plugins/mongodb/config/mongodb.conf
  3. BIN
      plugins/mongodb/ico.png
  4. 44
      plugins/mongodb/index.html
  5. 225
      plugins/mongodb/index.py
  6. 18
      plugins/mongodb/info.json
  7. 70
      plugins/mongodb/init.d/mongodb.tpl
  8. 73
      plugins/mongodb/install.sh

@ -482,7 +482,7 @@ def getLastLine(inputfile, lineNum):
def getNumLines(path, num, p=1):
pyVersion = sys.version_info[0]
try:
import cgi
import html
if not os.path.exists(path):
return ""
start_line = (p - 1) * num
@ -503,8 +503,8 @@ def getNumLines(path, num, p=1):
if n >= start_line:
line = buf[newline_pos + 1:]
try:
data.insert(0, cgi.escape(line))
except:
data.insert(0, html.escape(line))
except Exception as e:
pass
buf = buf[:newline_pos]
n += 1

@ -0,0 +1,12 @@
dbpath = {$SERVER_PATH}/mongodb/data
logpath = {$SERVER_PATH}/mongodb/logs/mongodb.log
logappend = true
bind_ip = 127.0.0.1
port = 27017
fork = true
auth = false
# 5.0.2 - Master/slave replication is no longer supported
#master = true
pidfilepath = {$SERVER_PATH}/mongodb/mongodb.pid

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

@ -0,0 +1,44 @@
<div class="bt-form">
<div class="bt-w-main">
<div class="bt-w-menu">
<p class="bgw" onclick="pluginService('mongodb');">服务</p>
<p onclick="pluginInitD('mongodb');">自启动</p>
<p onclick="pluginConfig('mongodb');">配置修改</p>
<p onclick="redisStatus();">负载状态</p>
<p onclick="pluginLogs('mongodb','','run_log');">日志</p>
</div>
<div class="bt-w-con pd15">
<div class="soft-man-con"></div>
</div>
</div>
</div>
<script type="text/javascript">
pluginService('mongodb');
//redis负载状态 start
function redisStatus() {
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
$.post('/plugins/run', {name:'mongodb', func:'run_info'}, function(data) {
layer.close(loadT);
if (!data.status){
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
return;
}
var rdata = $.parseJSON(data.data);
hit = (parseInt(rdata.keyspace_hits) / (parseInt(rdata.keyspace_hits) + parseInt(rdata.keyspace_misses)) * 100).toFixed(2);
var Con = '<div class="divtable">\
<table class="table table-hover table-bordered" style="width: 490px;">\
<thead><th>字段</th><th>当前值</th><th>说明</th></thead>\
<tbody>\
<tr><th>version</th><td>' + rdata.version + '</td><td>版本</td></tr>\
<tr><th>uptime</th><td>' + rdata.uptime + '</td><td>已运行秒</td></tr>\
<tr><th>connections</th><td>' + rdata.connections + '</td><td>当前链接数</td></tr>\
<tr><th>collections</th><td>' + rdata.collections + '</td><td>文档数</td></tr>\
<tbody>\
</table></div>'
$(".soft-man-con").html(Con);
},'json');
}
//mongodb end
</script>

@ -0,0 +1,225 @@
# coding:utf-8
import sys
import io
import os
import time
sys.path.append(os.getcwd() + "/class/core")
import mw
app_debug = False
if mw.isAppleSystem():
app_debug = True
def getPluginName():
return 'mongodb'
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 getConf():
if mw.isAppleSystem():
path = getServerDir() + "/mongodb.conf"
return path
return "/etc/mongod.conf"
def getConfTpl():
path = getPluginDir() + "/config/mongodb.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 status():
data = mw.execShell(
"ps -ef|grep mongod |grep -v grep | grep -v python | grep -v mdserver-web | 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)
file_bin = initD_path + '/' + getPluginName()
# initd replace
content = mw.readFile(file_tpl)
content = content.replace('{$SERVER_PATH}', service_path)
mw.writeFile(file_bin, content)
mw.execShell('chmod +x ' + file_bin)
# config replace
conf_content = mw.readFile(getConfTpl())
conf_content = conf_content.replace('{$SERVER_PATH}', service_path)
mw.writeFile(getServerDir() + '/mongodb.conf', conf_content)
return file_bin
def start():
if mw.isAppleSystem():
file = initDreplace()
data = mw.execShell(file + ' start')
if data[1] == '':
return 'ok'
return 'fail'
data = mw.execShell('systemctl start mongod')
if data[1] == '':
return 'ok'
return 'fail'
def stop():
if mw.isAppleSystem():
file = initDreplace()
data = mw.execShell(file + ' stop')
if data[1] == '':
return 'ok'
return 'fail'
data = mw.execShell('systemctl stop mongod')
if data[1] == '':
return 'ok'
return 'fail'
def reload():
if mw.isAppleSystem():
file = initDreplace()
data = mw.execShell(file + ' reload')
if data[1] == '':
return 'ok'
return 'fail'
data = mw.execShell('systemctl reload mongod')
if data[1] == '':
return 'ok'
return 'fail'
def runInfo():
import pymongo
client = pymongo.MongoClient(host='127.0.0.1', port=27017)
db = client.admin
serverStatus = db.command('serverStatus')
# print(serverStatus)
# for key, value in serverStatus.items():
# print(key, value)
result = {}
result["version"] = serverStatus['version']
result["uptime"] = serverStatus['uptime']
result["connections"] = serverStatus['connections']['current']
result["collections"] = serverStatus['catalogStats']['collections']
return mw.getJson(result)
def initdStatus():
if not app_debug:
if mw.isAppleSystem():
return "Apple Computer does not support"
initd_bin = getInitDFile()
if os.path.exists(initd_bin):
return 'ok'
return 'fail'
def initdInstall():
import shutil
if not app_debug:
if mw.isAppleSystem():
return "Apple Computer does not support"
source_bin = initDreplace()
initd_bin = getInitDFile()
shutil.copyfile(source_bin, initd_bin)
mw.execShell('chmod +x ' + initd_bin)
mw.execShell('chkconfig --add ' + getPluginName())
return 'ok'
def initdUinstall():
if not app_debug:
if mw.isAppleSystem():
return "Apple Computer does not support"
mw.execShell('chkconfig --del ' + getPluginName())
initd_bin = getInitDFile()
os.remove(initd_bin)
return 'ok'
def runLog():
if mw.isAppleSystem():
return getServerDir() + '/logs/mongodb.log'
return "/var/log/mongodb/mongod.log"
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_info':
print(runInfo())
elif func == 'conf':
print(getConf())
elif func == 'run_log':
print(runLog())
else:
print('error')

@ -0,0 +1,18 @@
{
"sort": 7,
"ps": "一个高性能的NOSQL数据库",
"name": "mongodb",
"title": "Mongodb",
"shell": "install.sh",
"versions":["5.0.4"],
"updates":["5.0.4"],
"tip": "soft",
"checks": "server/mongodb",
"path": "server/mongodb",
"display": 1,
"author": "mongodb",
"date": "2021-11-23",
"home": "https://www.mongodb.com/",
"type": 0,
"pid": "2"
}

@ -0,0 +1,70 @@
#!/bin/sh
# chkconfig: 2345 55 25
# description: Mongodb Service
### BEGIN INIT INFO
# Provides: Mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts Mongodb
# Description: starts the MDW-Web
### END INIT INFO
# Simple Mongodb init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
CONF="{$SERVER_PATH}/mongodb/mongodb.conf"
EXEC={$SERVER_PATH}/mongodb/bin/mongod
PIDFILE={$SERVER_PATH}/mongodb/mongodb.pid
mkdir -p {$SERVER_PATH}/mongodb/data
mkdir -p {$SERVER_PATH}/mongodb/logs
app_start(){
if [ -f $PIDFILE ];then
kill -9 `cat $PIDFILE`
fi
echo "Starting mongodb server..."
echo $EXEC -f $CONF
$EXEC -f $CONF >> {$SERVER_PATH}/mongodb/logs.pl 2>&1 &
}
app_stop(){
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
rm -rf $PIDFILE
fi
}
case "$1" in
start)
app_start
;;
stop)
app_stop
;;
restart|reload)
app_stop
sleep 0.3
app_start
;;
*)
echo "Please use start or stop as first argument"
;;
esac

@ -0,0 +1,73 @@
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 5.0.4
# cd /www/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 5.0.4
curPath=`pwd`
rootPath=$(dirname "$curPath")
rootPath=$(dirname "$rootPath")
serverPath=$(dirname "$rootPath")
install_tmp=${rootPath}/tmp/mw_install.pl
VERSION=$2
sysName=`uname`
Install_app_mac()
{
if [ ! -f $serverPath/source/mongodb-macos-x86_64-${VERSION}.tgz ];then
wget -O $serverPath/source/mongodb-macos-x86_64-${VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${VERSION}.tgz
fi
cd $serverPath/source && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
mkdir -p $serverPath/mongodb
cd mongodb-macos-x86_64-${VERSION} && mv ./* $serverPath/mongodb
}
# https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/RPMS/mongodb-org-server-5.0.4-1.el7.x86_64.rpm
Install_app_linux(){
if [ ! -f $serverPath/source/mongodb-org-server-${VERSION}-1.el7.x86_64.rpm ];then
wget -O $serverPath/source/mongodb-org-server-${VERSION}-1.el7.x86_64.rpm https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/RPMS/mongodb-org-server-${VERSION}-1.el7.x86_64.rpm
fi
rpm -ivh $serverPath/source/mongodb-org-server-${VERSION}-1.el7.x86_64.rpm
}
Install_app()
{
pip3 install pymongo
echo "sys:$sysName"
echo '正在安装脚本文件...' > $install_tmp
mkdir -p $serverPath/source
# echo $sysName
if [ "Darwin" == "$sysName" ];then
Install_app_mac
else
Install_app_linux
fi
# cd $serverPath/source && tar -zxvf mongodb-${VERSION}.tar.gz
echo "${VERSION}" > $serverPath/mongodb/version.pl
echo '安装完成' > $install_tmp
}
Uninstall_app()
{
rm -rf $serverPath/mongodb
echo "Uninstall_mongodb" > $install_tmp
}
action=$1
if [ "${1}" == 'install' ];then
Install_app
else
Uninstall_app
fi
Loading…
Cancel
Save