mirror of https://github.com/midoks/mdserver-web
parent
9789ab6e37
commit
4fbd037af1
@ -0,0 +1,35 @@ |
||||
#!/bin/bash |
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin |
||||
export PATH |
||||
|
||||
# OpenResty服务名称 |
||||
service_name="openresty" |
||||
|
||||
# 检查OpenResty是否正在运行 |
||||
if systemctl is-active --quiet "$service_name"; then |
||||
# 检查是否存在僵尸进程 |
||||
zombie_processes=$(ps -ef | grep -i openresty | grep -v grep | awk '{print $2}' | xargs ps -o state= -p 2>/dev/null | grep -c Z) |
||||
if [ "$zombie_processes" -gt 0 ]; then |
||||
echo "kill nginx 僵尸进程" |
||||
ps -ef|grep nginx| grep -v grep| awk '{print $2}' | xargs kill -9 |
||||
echo "检测到OpenResty僵尸进程,正在重启服务..." |
||||
systemctl restart "$service_name" |
||||
echo "服务已重启" |
||||
else |
||||
echo "OpenResty运行正常" |
||||
fi |
||||
else |
||||
echo "kill nginx" |
||||
ps -ef|grep nginx| grep -v grep| awk '{print $2}' | xargs kill -9 |
||||
echo "OpenResty未运行,正在启动服务..." |
||||
systemctl start "$service_name" |
||||
echo "服务已启动" |
||||
fi |
||||
|
||||
NGINX_IDS=`ps -ef|grep nginx | grep -v grep| awk '{print $2}'` |
||||
if [ "$NGINX_IDS" == "" ];then |
||||
ps -ef|grep nginx| grep -v grep| awk '{print $2}' | xargs kill -9 |
||||
systemctl start "$service_name" |
||||
echo "OpenResty未运行,正在启动服务..." |
||||
fi |
||||
|
||||
@ -0,0 +1,109 @@ |
||||
user {$OS_USER} {$OS_USER_GROUP}; |
||||
worker_processes auto; |
||||
worker_cpu_affinity auto; |
||||
error_log {$SERVER_PATH}/openresty/nginx/logs/error.log crit; |
||||
pid {$SERVER_PATH}/openresty/nginx/logs/nginx.pid; |
||||
|
||||
worker_rlimit_nofile 65535; |
||||
pcre_jit on; |
||||
|
||||
events |
||||
{ |
||||
use {$EVENT_MODEL}; |
||||
worker_connections 51200; |
||||
multi_accept on; |
||||
|
||||
# file/video close the mutex lock when under high load |
||||
# accept_mutex off; |
||||
} |
||||
|
||||
http |
||||
{ |
||||
include mime.types; |
||||
|
||||
include {$SERVER_PATH}/web_conf/nginx/lua/lua.conf; |
||||
#include proxy.conf; |
||||
|
||||
default_type application/octet-stream; |
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
||||
'$status $body_bytes_sent "$http_referer" ' |
||||
'"$http_user_agent" "$http_x_forwarded_for" "$request_time"'; |
||||
|
||||
server_names_hash_bucket_size 32; |
||||
client_header_buffer_size 32k; |
||||
large_client_header_buffers 4 32k; |
||||
client_body_buffer_size 128k; |
||||
client_max_body_size 20m; |
||||
|
||||
# video big file opt |
||||
aio threads; |
||||
directio 4m; |
||||
output_buffers 16 512k; |
||||
sendfile on; |
||||
tcp_nopush on; |
||||
tcp_nodelay on; |
||||
|
||||
keepalive_timeout 60; |
||||
|
||||
fastcgi_connect_timeout 60; |
||||
fastcgi_send_timeout 60; |
||||
fastcgi_read_timeout 60; |
||||
fastcgi_buffer_size 64k; |
||||
fastcgi_buffers 4 64k; |
||||
fastcgi_busy_buffers_size 128k; |
||||
fastcgi_temp_file_write_size 256k; |
||||
fastcgi_intercept_errors on; |
||||
|
||||
zstd off; |
||||
zstd_comp_level 6; |
||||
zstd_min_length 256; |
||||
zstd_types text/plain text/css text/xml text/javascript text/cache-manifest text/x-component text/vtt application/javascript application/json application/ld+json application/xml application/xhtml+xml application/rss+xml application/atom+xml application/manifest+json application/x-web-app-manifest+json application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/wasm font/opentype image/svg+xml image/bmp; |
||||
|
||||
brotli off; |
||||
brotli_min_length 256; |
||||
brotli_buffers 32 8k; |
||||
brotli_comp_level 4; |
||||
brotli_window 16m; |
||||
brotli_static on; |
||||
brotli_types text/plain text/css text/xml text/javascript text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml application/atom+xml application/vnd.ms-fontobject application/x-font-ttf application/x-font-opentype application/x-font-truetype font/tpl font/opentype font/otf font/ttf image/svg+xml image/x-icon image/vnd.microsoft.icon application/wasm application/manifest+json; |
||||
|
||||
gzip on; |
||||
gzip_min_length 1k; |
||||
gzip_buffers 4 16k; |
||||
gzip_http_version 1.1; |
||||
gzip_comp_level 9; |
||||
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; |
||||
gzip_vary on; |
||||
gzip_proxied expired no-cache no-store private auth; |
||||
gzip_disable "MSIE [1-6]\."; |
||||
|
||||
|
||||
limit_conn_zone $binary_remote_addr zone=perip:10m; |
||||
limit_conn_zone $server_name zone=perserver:10m; |
||||
|
||||
# CACEH_BEGIN |
||||
proxy_buffering on; |
||||
proxy_buffer_size 1024k; |
||||
proxy_buffers 16 1024k; |
||||
proxy_busy_buffers_size 2048k; |
||||
proxy_temp_file_write_size 2048k; |
||||
proxy_cache_path {$SERVER_PATH}/openresty/nginx/proxy_cache_temp levels=1:2 keys_zone=mw_cache:512m inactive=5m max_size=2g use_temp_path=off; |
||||
#proxy timeout |
||||
proxy_connect_timeout 3s; |
||||
proxy_read_timeout 5s; |
||||
proxy_send_timeout 5s; |
||||
|
||||
fastcgi_cache_key "$scheme$request_method$host$request_uri"; |
||||
fastcgi_cache_path {$SERVER_PATH}/openresty/nginx/fastcgi_cache_temp levels=1:2 keys_zone=mw_cache_fcgi:100m inactive=60m max_size=5g; |
||||
fastcgi_cache_use_stale error timeout invalid_header http_500; |
||||
fastcgi_ignore_headers Cache-Control Expires Set-Cookie; |
||||
# CACEH_END |
||||
|
||||
server_tokens off; |
||||
access_log /dev/null; |
||||
more_set_headers "Server: mdserver-web"; |
||||
|
||||
include {$SERVER_PATH}/web_conf/nginx/vhost/*.conf; |
||||
} |
||||
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@ -0,0 +1,24 @@ |
||||
<div class="bt-form"> |
||||
<!-- <div class='plugin_version'></div> --> |
||||
<div class="bt-w-main"> |
||||
<div class="bt-w-menu"> |
||||
<p class="bgw" onclick="orPluginService('apache',$('.plugin_version').attr('version'));">服务</p> |
||||
<p onclick="pluginInitD('apache', $('.plugin_version').attr('version'));">自启动</p> |
||||
<p onclick="pluginConfig('apache');">配置修改</p> |
||||
<p onclick="getOpStatus();">负载状态</p> |
||||
<p onclick="setOpCfg();">性能调整</p> |
||||
<p onclick="pluginLogs('apache');">错误日志</p> |
||||
<p onclick="otherFunc();">维护功能</p> |
||||
</div> |
||||
<div class="bt-w-con pd15"> |
||||
<div class="soft-man-con"></div> |
||||
</div> |
||||
</div> |
||||
|
||||
</div> |
||||
|
||||
<script type="text/javascript"> |
||||
$.getScript( "/plugins/file?name=apache&f=js/apache.js", function(){ |
||||
orPluginService('apache'); |
||||
}); |
||||
</script> |
||||
@ -0,0 +1,644 @@ |
||||
# coding:utf-8 |
||||
|
||||
import sys |
||||
import io |
||||
import os |
||||
import time |
||||
import threading |
||||
import subprocess |
||||
import re |
||||
|
||||
|
||||
web_dir = os.getcwd() + "/web" |
||||
if os.path.exists(web_dir): |
||||
sys.path.append(web_dir) |
||||
os.chdir(web_dir) |
||||
|
||||
import core.mw as mw |
||||
|
||||
app_debug = False |
||||
if mw.isAppleSystem(): |
||||
app_debug = True |
||||
|
||||
|
||||
def getPluginName(): |
||||
return 'apache' |
||||
|
||||
|
||||
def getPluginDir(): |
||||
return mw.getPluginDir() + '/' + getPluginName() |
||||
|
||||
|
||||
def getServerDir(): |
||||
return mw.getServerDir() + '/' + getPluginName() |
||||
|
||||
|
||||
def getInitDFile(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return '/tmp/' + getPluginName() |
||||
|
||||
if current_os.startswith('freebsd'): |
||||
return '/etc/rc.d/' + getPluginName() |
||||
|
||||
return '/etc/init.d/' + getPluginName() |
||||
|
||||
|
||||
def getArgs(): |
||||
args = sys.argv[2:] |
||||
# print(args) |
||||
tmp = {} |
||||
args_len = len(args) |
||||
|
||||
if args_len == 1: |
||||
t = args[0].strip('{').strip('}') |
||||
t = t.split(':',2) |
||||
tmp[t[0]] = t[1] |
||||
elif args_len > 1: |
||||
for i in range(len(args)): |
||||
t = args[i].split(':',2) |
||||
tmp[t[0]] = t[1] |
||||
# print(tmp) |
||||
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 clearTemp(): |
||||
path_bin = getServerDir() + "/nginx" |
||||
mw.execShell('rm -rf ' + path_bin + '/client_body_temp') |
||||
mw.execShell('rm -rf ' + path_bin + '/fastcgi_temp') |
||||
mw.execShell('rm -rf ' + path_bin + '/proxy_temp') |
||||
mw.execShell('rm -rf ' + path_bin + '/scgi_temp') |
||||
mw.execShell('rm -rf ' + path_bin + '/uwsgi_temp') |
||||
|
||||
|
||||
def getConf(): |
||||
path = getServerDir() + "/nginx/conf/nginx.conf" |
||||
return path |
||||
|
||||
|
||||
def getConfTpl(): |
||||
path = getPluginDir() + '/conf/nginx.conf' |
||||
return path |
||||
|
||||
|
||||
def getOs(): |
||||
data = {} |
||||
data['os'] = mw.getOs() |
||||
ng_exe_bin = getServerDir() + "/nginx/sbin/nginx" |
||||
|
||||
# if mw.isAppleSystem(): |
||||
# data['auth'] = True |
||||
# return mw.getJson(data) |
||||
|
||||
if checkAuthEq(ng_exe_bin, 'root'): |
||||
data['auth'] = True |
||||
else: |
||||
data['auth'] = False |
||||
return mw.getJson(data) |
||||
|
||||
|
||||
def getInitDTpl(): |
||||
path = getPluginDir() + "/init.d/nginx.tpl" |
||||
return path |
||||
|
||||
|
||||
def getPidFile(): |
||||
file = getConf() |
||||
content = mw.readFile(file) |
||||
rep = r'pid\s*(.*);' |
||||
tmp = re.search(rep, content) |
||||
return tmp.groups()[0].strip() |
||||
|
||||
|
||||
def getFileOwner(filename): |
||||
import pwd |
||||
stat = os.lstat(filename) |
||||
uid = stat.st_uid |
||||
pw = pwd.getpwuid(uid) |
||||
return pw.pw_name |
||||
|
||||
|
||||
def checkAuthEq(file, owner='root'): |
||||
fowner = getFileOwner(file) |
||||
if (fowner == owner): |
||||
return True |
||||
return False |
||||
|
||||
|
||||
def confReplace(): |
||||
service_path = mw.getServerDir() |
||||
content = mw.readFile(getConfTpl()) |
||||
content = content.replace('{$SERVER_PATH}', service_path) |
||||
|
||||
user = 'www' |
||||
user_group = 'www' |
||||
|
||||
content = content.replace('{$OS_USER}', user) |
||||
content = content.replace('{$OS_USER_GROUP}', user_group) |
||||
|
||||
# ng_conf_md5 = '' |
||||
# ng_conf_md5_file = getServerDir() + '/nginx_conf.md5' |
||||
# if not os.path.exists(ng_conf_md5_file): |
||||
# ng_conf_md5 = mw.md5(content) |
||||
# mw.writeFile(ng_conf_md5_file, ng_conf_md5) |
||||
# else: |
||||
# ng_conf_md5 = mw.writeFile(ng_conf_md5_file).strip() |
||||
|
||||
# 主配置文件 |
||||
nconf = getServerDir() + '/nginx/conf/nginx.conf' |
||||
mw.writeFile(nconf, content) |
||||
|
||||
# lua配置 |
||||
lua_conf_dir = mw.getServerDir() + '/web_conf/nginx/lua' |
||||
if not os.path.exists(lua_conf_dir): |
||||
mw.execShell('mkdir -p ' + lua_conf_dir) |
||||
# 静态配置 |
||||
php_conf = mw.getServerDir() + '/web_conf/php/conf' |
||||
if not os.path.exists(php_conf): |
||||
mw.execShell('mkdir -p ' + php_conf) |
||||
static_conf = mw.getServerDir() + '/web_conf/php/conf/enable-php-00.conf' |
||||
if not os.path.exists(static_conf): |
||||
mw.writeFile(static_conf, 'set $PHP_ENV 0;') |
||||
|
||||
# vhost |
||||
vhost_dir = mw.getServerDir() + '/web_conf/nginx/vhost' |
||||
vhost_tpl_dir = getPluginDir() + '/conf/vhost' |
||||
if not os.path.exists(vhost_dir): |
||||
mw.execShell('mkdir -p ' + vhost_dir) |
||||
|
||||
vhost_list = ['0.websocket.conf', '0.nginx_status.conf'] |
||||
for f in vhost_list: |
||||
a_conf = vhost_dir + '/' + f |
||||
a_conf_tpl = vhost_tpl_dir + '/' + f |
||||
if not os.path.exists(a_conf): |
||||
mw.writeFile(a_conf, mw.readFile(a_conf_tpl)) |
||||
|
||||
|
||||
def initDreplace(): |
||||
|
||||
file_tpl = getInitDTpl() |
||||
service_path = mw.getServerDir() |
||||
|
||||
initD_path = getServerDir() + '/init.d' |
||||
|
||||
# OpenResty is not installed |
||||
if not os.path.exists(getServerDir()): |
||||
print("ok") |
||||
exit(0) |
||||
|
||||
# init.d |
||||
file_bin = initD_path + '/' + getPluginName() |
||||
if not os.path.exists(initD_path): |
||||
os.mkdir(initD_path) |
||||
|
||||
# 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 |
||||
confReplace() |
||||
|
||||
# give nginx root permission |
||||
# ng_exe_bin = getServerDir() + "/nginx/sbin/nginx" |
||||
# if not checkAuthEq(ng_exe_bin, 'root'): |
||||
# user = 'www' |
||||
# user_group = 'www' |
||||
# current_os = mw.getOs() |
||||
# if current_os == 'darwin': |
||||
# user = 'root' |
||||
# user_group = 'staff' |
||||
# args = getArgs() |
||||
# if not 'pwd' in args: |
||||
# print("权限不足,需要认证启动!") |
||||
# exit(0) |
||||
|
||||
sudoPwd = args['pwd'] |
||||
cmd_own = 'chown -R ' + user+':' + user_group + ' ' + ng_exe_bin |
||||
mw.execShell('echo %s|sudo -S %s' % (sudoPwd, cmd_own)) |
||||
cmd_mod = 'chmod 755 ' + ng_exe_bin |
||||
mw.execShell('echo %s|sudo -S %s' % (sudoPwd, cmd_mod)) |
||||
cmd_s = 'chmod u+s ' + ng_exe_bin |
||||
mw.execShell('echo %s|sudo -S %s' % (sudoPwd, cmd_s)) |
||||
|
||||
# systemd |
||||
# /usr/lib/systemd/system |
||||
systemDir = mw.systemdCfgDir() |
||||
systemService = systemDir + '/httpd.service' |
||||
if os.path.exists(systemDir) and not os.path.exists(systemService): |
||||
systemServiceTpl = getPluginDir() + '/init.d/httpd.service.tpl' |
||||
se_content = mw.readFile(systemServiceTpl) |
||||
se_content = se_content.replace('{$SERVER_PATH}', service_path) |
||||
mw.writeFile(systemService, se_content) |
||||
mw.execShell('systemctl daemon-reload') |
||||
|
||||
return file_bin |
||||
|
||||
|
||||
def status(): |
||||
pid_file = getPidFile() |
||||
if not os.path.exists(pid_file): |
||||
return 'stop' |
||||
return 'start' |
||||
|
||||
|
||||
def restyOp(method): |
||||
file = initDreplace() |
||||
|
||||
# 启动时,先检查一下配置文件 |
||||
check = getServerDir() + "/bin/httpd -t" |
||||
check_data = mw.execShell(check) |
||||
if not check_data[1].find('test is successful') > -1: |
||||
return check_data[1] |
||||
|
||||
current_os = mw.getOs() |
||||
if current_os == "darwin": |
||||
data = mw.execShell(file + ' ' + method) |
||||
if data[1] == '': |
||||
return 'ok' |
||||
return data[1] |
||||
|
||||
if current_os.startswith("freebsd"): |
||||
data = mw.execShell('service httpd ' + method) |
||||
if data[1] == '': |
||||
return 'ok' |
||||
return data[1] |
||||
|
||||
data = mw.execShell('systemctl ' + method + ' httpd') |
||||
if data[1] == '': |
||||
return 'ok' |
||||
return data[1] |
||||
|
||||
|
||||
def op_submit_systemctl_restart(): |
||||
current_os = mw.getOs() |
||||
if current_os.startswith("freebsd"): |
||||
mw.execShell('service httpd restart') |
||||
return True |
||||
|
||||
mw.execShell('systemctl restart httpd') |
||||
return True |
||||
|
||||
|
||||
def op_submit_init_restart(file): |
||||
mw.execShell(file + ' restart') |
||||
|
||||
|
||||
def restyOp_restart(): |
||||
file = initDreplace() |
||||
|
||||
# 启动时,先检查一下配置文件 |
||||
check = getServerDir() + "/bin/httpd -t" |
||||
check_data = mw.execShell(check) |
||||
if not check_data[1].find('test is successful') > -1: |
||||
return 'ERROR: 配置出错<br><a style="color:red;">' + check_data[1].replace("\n", '<br>') + '</a>' |
||||
|
||||
if not mw.isAppleSystem(): |
||||
threading.Timer(2, op_submit_systemctl_restart).start() |
||||
return 'ok' |
||||
|
||||
threading.Timer(2, op_submit_init_restart, args=(file,)).start() |
||||
return 'ok' |
||||
|
||||
|
||||
def start(): |
||||
return restyOp('start') |
||||
|
||||
|
||||
def stop(): |
||||
r = restyOp('stop') |
||||
pid_file = getPidFile() |
||||
if os.path.exists(pid_file): |
||||
os.remove(pid_file) |
||||
return r |
||||
|
||||
|
||||
def restart(): |
||||
return restyOp_restart() |
||||
|
||||
|
||||
def reload(): |
||||
confReplace() |
||||
return restyOp('reload') |
||||
|
||||
|
||||
def initdStatus(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return "Apple Computer does not support" |
||||
|
||||
if current_os.startswith('freebsd'): |
||||
initd_bin = getInitDFile() |
||||
if os.path.exists(initd_bin): |
||||
return 'ok' |
||||
|
||||
shell_cmd = 'systemctl status httpd | grep loaded | grep "enabled;"' |
||||
data = mw.execShell(shell_cmd) |
||||
if data[0] == '': |
||||
return 'fail' |
||||
return 'ok' |
||||
|
||||
|
||||
def initdInstall(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return "Apple Computer does not support" |
||||
|
||||
# freebsd initd install |
||||
if current_os.startswith('freebsd'): |
||||
import shutil |
||||
source_bin = initDreplace() |
||||
initd_bin = getInitDFile() |
||||
shutil.copyfile(source_bin, initd_bin) |
||||
mw.execShell('chmod +x ' + initd_bin) |
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="YES"') |
||||
return 'ok' |
||||
|
||||
mw.execShell('systemctl enable httpd') |
||||
return 'ok' |
||||
|
||||
|
||||
def initdUinstall(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return "Apple Computer does not support" |
||||
|
||||
if current_os.startswith('freebsd'): |
||||
initd_bin = getInitDFile() |
||||
os.remove(initd_bin) |
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="NO"') |
||||
return 'ok' |
||||
|
||||
mw.execShell('systemctl disable httpd') |
||||
return 'ok' |
||||
|
||||
def getNgxStatusPort(): |
||||
ngx_status_file = mw.getServerDir() + '/web_conf/nginx/vhost/0.nginx_status.conf' |
||||
content = mw.readFile(ngx_status_file) |
||||
rep = r'listen\s*(.*);' |
||||
tmp = re.search(rep, content) |
||||
port = tmp.groups()[0].strip() |
||||
return port |
||||
|
||||
|
||||
def runInfo(): |
||||
op_status = status() |
||||
if op_status == 'stop': |
||||
return mw.returnJson(False, "未启动!") |
||||
|
||||
port = getNgxStatusPort() |
||||
# 取Openresty负载状态 |
||||
try: |
||||
url = 'http://127.0.0.1:%s/nginx_status' % port |
||||
result = mw.httpGet(url, timeout=3) |
||||
tmp = result.split() |
||||
data = {} |
||||
data['active'] = tmp[2] |
||||
data['accepts'] = tmp[9] |
||||
data['handled'] = tmp[7] |
||||
data['requests'] = tmp[8] |
||||
data['Reading'] = tmp[11] |
||||
data['Writing'] = tmp[13] |
||||
data['Waiting'] = tmp[15] |
||||
return mw.getJson(data) |
||||
except Exception as e: |
||||
try: |
||||
url = 'http://' + mw.getHostAddr() + ':%s/nginx_status' % port |
||||
result = mw.httpGet(url) |
||||
tmp = result.split() |
||||
data = {} |
||||
data['active'] = tmp[2] |
||||
data['accepts'] = tmp[9] |
||||
data['handled'] = tmp[7] |
||||
data['requests'] = tmp[8] |
||||
data['Reading'] = tmp[11] |
||||
data['Writing'] = tmp[13] |
||||
data['Waiting'] = tmp[15] |
||||
return mw.getJson(data) |
||||
except Exception as e: |
||||
return mw.returnJson(False, "oprenresty异常!") |
||||
|
||||
except Exception as e: |
||||
return mw.returnJson(False, "oprenresty not started!") |
||||
|
||||
|
||||
def errorLogPath(): |
||||
return getServerDir() + '/nginx/logs/error.log' |
||||
|
||||
|
||||
def getCfg(): |
||||
cfg = getConf() |
||||
content = mw.readFile(cfg) |
||||
|
||||
unitrep = "[kmgKMG]" |
||||
cfg_args = [ |
||||
{"name": "worker_processes", "ps": "处理进程,auto表示自动,数字表示进程数", 'type': 2}, |
||||
{"name": "worker_connections", "ps": "最大并发链接数", 'type': 2}, |
||||
{"name": "keepalive_timeout", "ps": "连接超时时间", 'type': 2}, |
||||
{"name": "zstd", "ps": "是否开启zstd压缩传输", 'type': 1}, |
||||
{"name": "brotli", "ps": "是否开启brotli压缩传输", 'type': 1}, |
||||
{"name": "gzip", "ps": "是否开启gzip压缩传输", 'type': 1}, |
||||
{"name": "gzip_min_length", "ps": "最小压缩文件", 'type': 2}, |
||||
{"name": "gzip_comp_level", "ps": "压缩率", 'type': 2}, |
||||
{"name": "client_max_body_size", "ps": "最大上传文件", 'type': 2}, |
||||
{"name": "server_names_hash_bucket_size", |
||||
"ps": "服务器名字的hash表大小", 'type': 2}, |
||||
{"name": "client_header_buffer_size", "ps": "客户端请求头buffer大小", 'type': 2}, |
||||
] |
||||
|
||||
# {"name": "client_body_buffer_size", "ps": "请求主体缓冲区"} |
||||
rdata = [] |
||||
for i in cfg_args: |
||||
rep = r"(%s)\s+(\w+)" % i["name"] |
||||
k = re.search(rep, content) |
||||
if not k: |
||||
return mw.returnJson(False, "获取 key {} 失败".format(k)) |
||||
k = k.group(1) |
||||
v = re.search(rep, content) |
||||
if not v: |
||||
return mw.returnJson(False, "获取 value {} 失败".format(v)) |
||||
v = v.group(2) |
||||
|
||||
if re.search(unitrep, v): |
||||
u = str.upper(v[-1]) |
||||
v = v[:-1] |
||||
if len(u) == 1: |
||||
psstr = u + "B," + i["ps"] |
||||
else: |
||||
psstr = u + "," + i["ps"] |
||||
else: |
||||
u = "" |
||||
|
||||
kv = {"name": k, "value": v, "unit": u, |
||||
"ps": i["ps"], "type": i["type"]} |
||||
rdata.append(kv) |
||||
|
||||
return mw.returnJson(True, "ok", rdata) |
||||
|
||||
def replaceChar(value, index, new_char): |
||||
return value[:index] + new_char + value[index+1:] |
||||
|
||||
def makeWorkerCpuAffinity(val): |
||||
if val == "auto": |
||||
return "auto" |
||||
|
||||
if mw.isNumber(val): |
||||
core_num = int(val) |
||||
default_core_str = "0"*core_num |
||||
core_num_arr = [] |
||||
for x in range(core_num): |
||||
t = replaceChar(default_core_str, x , "1") |
||||
core_num_arr.append(t) |
||||
return " ".join(core_num_arr) |
||||
|
||||
return 'auto' |
||||
|
||||
def setCfg(): |
||||
|
||||
args = getArgs() |
||||
data = checkArgs(args, [ |
||||
'worker_processes', 'worker_connections', 'keepalive_timeout','zstd','brotli', |
||||
'gzip', 'gzip_min_length', 'gzip_comp_level', 'client_max_body_size', |
||||
'server_names_hash_bucket_size', 'client_header_buffer_size' |
||||
]) |
||||
if not data[0]: |
||||
return data[1] |
||||
|
||||
cfg = getConf() |
||||
mw.backFile(cfg) |
||||
content = mw.readFile(cfg) |
||||
|
||||
unitrep = "[kmgKMG]" |
||||
cfg_args = [ |
||||
{"name": "worker_processes", "ps": "处理进程,auto表示自动,数字表示进程数", 'type': 2}, |
||||
{"name": "worker_connections", "ps": "最大并发链接数", 'type': 2}, |
||||
{"name": "keepalive_timeout", "ps": "连接超时时间", 'type': 2}, |
||||
{"name": "zstd", "ps": "是否开启zstd压缩传输", 'type': 1}, |
||||
{"name": "brotli", "ps": "是否开启brotli压缩传输", 'type': 1}, |
||||
{"name": "gzip", "ps": "是否开启压缩传输", 'type': 1}, |
||||
{"name": "gzip_min_length", "ps": "最小压缩文件", 'type': 2}, |
||||
{"name": "gzip_comp_level", "ps": "压缩率", 'type': 2}, |
||||
{"name": "client_max_body_size", "ps": "最大上传文件", 'type': 2}, |
||||
{"name": "server_names_hash_bucket_size", |
||||
"ps": "服务器名字的hash表大小", 'type': 2}, |
||||
{"name": "client_header_buffer_size", "ps": "客户端请求头buffer大小", 'type': 2}, |
||||
] |
||||
|
||||
# print(args) |
||||
for k, v in args.items(): |
||||
# print(k, v) |
||||
rep = r"%s\s+[^kKmMgG\;\n]+" % k |
||||
if k == "worker_processes" or k == "gzip": |
||||
if not re.search(r"auto|on|off|\d+", v): |
||||
return mw.returnJson(False, '参数值错误') |
||||
elif k == "zstd" or k == "brotli": |
||||
if not re.search(r"auto|on|off|\d+", v): |
||||
return mw.returnJson(False, '参数值错误') |
||||
else: |
||||
if not re.search(r"\d+", v): |
||||
return mw.returnJson(False, '参数值错误,请输入数字整数') |
||||
|
||||
if k == "worker_processes" : |
||||
k_wca = "worker_cpu_affinity" |
||||
rep_wca = r"%s\s+[^\;\n]+" % k_wca |
||||
v_wca = makeWorkerCpuAffinity(v) |
||||
newconf = "%s %s" % (k_wca, v_wca) |
||||
content = re.sub(rep_wca, newconf, content) |
||||
|
||||
|
||||
if re.search(rep, content): |
||||
newconf = "%s %s" % (k, v) |
||||
content = re.sub(rep, newconf, content) |
||||
elif re.search(rep, content): |
||||
newconf = "%s %s" % (k, v) |
||||
content = re.sub(rep, newconf, content) |
||||
|
||||
mw.writeFile(cfg, content) |
||||
isError = mw.checkWebConfig() |
||||
if (isError != True): |
||||
mw.restoreFile(cfg) |
||||
return mw.returnJson(False, 'ERROR: 配置出错<br><a style="color:red;">' + isError.replace("\n", '<br>') + '</a>') |
||||
|
||||
mw.restartWeb() |
||||
return mw.returnJson(True, '设置成功') |
||||
|
||||
|
||||
def cronAddCheck(): |
||||
try: |
||||
import tool_task |
||||
tool_task.createBgTask() |
||||
return mw.returnJson(True, '添加检查任务成功') |
||||
except Exception as e: |
||||
return mw.returnJson(False, '添加检查任务失败:'+str(e)) |
||||
|
||||
def cronDelCheck(): |
||||
try: |
||||
import tool_task |
||||
tool_task.removeBgTask() |
||||
return mw.returnJson(True, '删除检查任务成功') |
||||
except Exception as e: |
||||
return mw.returnJson(False, '删除检查任务失败:'+str(e)) |
||||
|
||||
def cronCheck(): |
||||
return 'ok' |
||||
|
||||
|
||||
def installPreInspection(): |
||||
return 'ok' |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
|
||||
version = '1.27.1' |
||||
version_pl = getServerDir() + "/version.pl" |
||||
if os.path.exists(version_pl): |
||||
version = mw.readFile(version_pl) |
||||
|
||||
|
||||
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 == 'install_pre_inspection': |
||||
print(installPreInspection()) |
||||
elif func == 'conf': |
||||
print(getConf()) |
||||
elif func == 'get_os': |
||||
print(getOs()) |
||||
elif func == 'run_info': |
||||
print(runInfo()) |
||||
elif func == 'error_log': |
||||
print(errorLogPath()) |
||||
elif func == 'get_cfg': |
||||
print(getCfg()) |
||||
elif func == 'set_cfg': |
||||
print(setCfg()) |
||||
elif func == 'check': |
||||
print(cronCheck()) |
||||
elif func == 'cron_add_check': |
||||
print(cronAddCheck()) |
||||
elif func == 'cron_del_check': |
||||
print(cronDelCheck()) |
||||
else: |
||||
print('error') |
||||
@ -0,0 +1,18 @@ |
||||
{ |
||||
"sort": 0, |
||||
"title":"apache", |
||||
"tip":"soft", |
||||
"name":"apache", |
||||
"type":"其他插件", |
||||
"ps":"世界排名第一,快速、可靠并且可通过简单的API扩充", |
||||
"shell":"install.sh", |
||||
"install_pre_inspection":true, |
||||
"checks":"server/apache", |
||||
"path":"server/apache", |
||||
"author":"apache", |
||||
"home":"https://downloads.apache.org/httpd/", |
||||
"date":"2026-04-11", |
||||
"pid": "1", |
||||
"versions": ["2.4"], |
||||
"updates": ["2.4:66"] |
||||
} |
||||
@ -0,0 +1,14 @@ |
||||
[Unit] |
||||
Description=OpenResty is a dynamic web platform based on NGINX and LuaJIT. |
||||
After=network.target |
||||
|
||||
[Service] |
||||
Type=forking |
||||
ExecStart={$SERVER_PATH}/apache/bin/httpd -c {$SERVER_PATH}/apache/nginx/conf/nginx.conf |
||||
ExecStop={$SERVER_PATH}/apache/bin/httpd -s stop |
||||
ExecReload={$SERVER_PATH}/apache/bin/httpd -s reload |
||||
KillMode=process |
||||
Restart=on-failure |
||||
|
||||
[Install] |
||||
WantedBy=multi-user.target |
||||
@ -0,0 +1,118 @@ |
||||
#! /bin/sh |
||||
# chkconfig: 2345 55 25 |
||||
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and |
||||
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your |
||||
# distro. For CentOS/Redhat run: 'chkconfig --add openresty' |
||||
|
||||
### BEGIN INIT INFO |
||||
# Provides: nginx |
||||
# Required-Start: $all |
||||
# Required-Stop: $all |
||||
# Default-Start: 2 3 4 5 |
||||
# Default-Stop: 0 1 6 |
||||
# Short-Description: starts the nginx web server |
||||
# Description: starts nginx using start-stop-daemon |
||||
### END INIT INFO |
||||
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/homebrew/bin |
||||
NAME=nginx |
||||
NGINX_BIN={$SERVER_PATH}/openresty/bin/openresty |
||||
CONFIGFILE={$SERVER_PATH}/openresty/nginx/conf/$NAME.conf |
||||
PIDFILE={$SERVER_PATH}/openresty/nginx/logs/$NAME.pid |
||||
|
||||
case "$1" in |
||||
start) |
||||
echo -n "Starting $NAME... " |
||||
if [ -f $PIDFILE ];then |
||||
mPID=`cat $PIDFILE` |
||||
isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"` |
||||
if [ "$isStart" != '' ];then |
||||
echo "$NAME (pid `pidof $NAME`) already running." |
||||
exit 1 |
||||
fi |
||||
fi |
||||
|
||||
$NGINX_BIN -c $CONFIGFILE |
||||
|
||||
if [ "$?" != 0 ] ; then |
||||
echo " failed" |
||||
exit 1 |
||||
else |
||||
echo " done" |
||||
fi |
||||
;; |
||||
|
||||
stop) |
||||
echo -n "Stoping $NAME... " |
||||
if [ -f $PIDFILE ];then |
||||
mPID=`cat $PIDFILE` |
||||
isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"` |
||||
if [ "$isStart" = '' ];then |
||||
echo "$NAME is not running." |
||||
exit 1 |
||||
fi |
||||
else |
||||
echo "$NAME is not running." |
||||
exit 1 |
||||
fi |
||||
$NGINX_BIN -s stop |
||||
|
||||
if [ "$?" != 0 ] ; then |
||||
echo " failed. Use force-quit" |
||||
exit 1 |
||||
else |
||||
echo " done" |
||||
fi |
||||
;; |
||||
|
||||
status) |
||||
if [ -f $PIDFILE ];then |
||||
mPID=`cat $PIDFILE` |
||||
isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"` |
||||
if [ "$isStart" != '' ];then |
||||
echo "$NAME (pid `pidof $NAME`) already running." |
||||
exit 1 |
||||
else |
||||
echo "$NAME is stopped" |
||||
exit 0 |
||||
fi |
||||
else |
||||
echo "$NAME is stopped" |
||||
exit 0 |
||||
fi |
||||
;; |
||||
restart) |
||||
$0 stop |
||||
sleep 1 |
||||
$0 start |
||||
;; |
||||
|
||||
reload) |
||||
echo -n "Reload service $NAME... " |
||||
if [ -f $PIDFILE ];then |
||||
mPID=`cat $PIDFILE` |
||||
isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"` |
||||
if [ "$isStart" != '' ];then |
||||
$NGINX_BIN -s reload |
||||
echo " done" |
||||
else |
||||
echo "$NAME is not running, can't reload." |
||||
exit 1 |
||||
fi |
||||
else |
||||
echo "$NAME is not running, can't reload." |
||||
exit 1 |
||||
fi |
||||
;; |
||||
|
||||
configtest) |
||||
echo -n "Test $NAME configure files... " |
||||
$NGINX_BIN -t |
||||
;; |
||||
|
||||
*) |
||||
echo "Usage: $0 {start|stop|restart|reload|status|configtest}" |
||||
exit 1 |
||||
;; |
||||
esac |
||||
@ -0,0 +1,84 @@ |
||||
#!/bin/bash |
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin |
||||
export PATH |
||||
|
||||
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/apache && bash install.sh install 2.4 |
||||
# cd /www/server/mdserver-web/plugins/apache && bash install.sh install 2.4 |
||||
# cd /www/server/mdserver-web/plugins/apache && bash install.sh upgrade 2.4 |
||||
|
||||
# curl -I -H "Accept-Encoding: br" http://localhost |
||||
# curl -I -H "Accept-Encoding: zstd" http://localhost |
||||
# curl --http3 -v https://www.xxx.com |
||||
|
||||
# apt install ncat -y |
||||
# nc -u -v www.xx.com 443 |
||||
|
||||
# cd /www/server/mdserver-web && python3 plugins/openresty/index.py run_info |
||||
|
||||
curPath=`pwd` |
||||
rootPath=$(dirname "$curPath") |
||||
rootPath=$(dirname "$rootPath") |
||||
serverPath=$(dirname "$rootPath") |
||||
|
||||
sysName=`uname` |
||||
action=$1 |
||||
type=$2 |
||||
|
||||
VERSION=$2 |
||||
openrestyDir=${serverPath}/source/apache |
||||
|
||||
if id www &> /dev/null ;then |
||||
echo "www uid is `id -u www`" |
||||
echo "www shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `" |
||||
else |
||||
groupadd www |
||||
useradd -g www -s /bin/bash www |
||||
fi |
||||
|
||||
if [ "${action}" == "upgrade" ];then |
||||
sh -x $curPath/versions/$2/install.sh $1 |
||||
|
||||
echo "${VERSION}" > $serverPath/apache/version.pl |
||||
|
||||
mkdir -p $serverPath/web_conf/php/conf |
||||
echo 'set $PHP_ENV 0;' > $serverPath/web_conf/php/conf/enable-php-00.conf |
||||
|
||||
#初始化 |
||||
cd ${rootPath} && python3 ${rootPath}/plugins/apache/index.py start |
||||
cd ${rootPath} && python3 ${rootPath}/plugins/apache/index.py initd_install |
||||
exit 0 |
||||
fi |
||||
|
||||
|
||||
if [ "${2}" == "" ];then |
||||
echo '缺少安装脚本版本...' |
||||
exit 0 |
||||
fi |
||||
|
||||
if [ "${action}" == "uninstall" ];then |
||||
if [ -f /usr/lib/systemd/system/apache.service ] || [ -f /lib/systemd/system/apache.service ];then |
||||
systemctl stop apache |
||||
rm -rf /usr/systemd/system/apache.service |
||||
rm -rf /lib/systemd/system/apache.service |
||||
systemctl daemon-reload |
||||
fi |
||||
|
||||
if [ -f $serverPath/apache/init.d/apache ];then |
||||
$serverPath/apache/init.d/apache stop |
||||
fi |
||||
|
||||
rm -rf $serverPath/apache |
||||
fi |
||||
|
||||
sh -x $curPath/versions/$2/install.sh $1 |
||||
|
||||
if [ "${action}" == "install" ] && [ -d $serverPath/apache ];then |
||||
echo "${VERSION}" > $serverPath/apache/version.pl |
||||
|
||||
mkdir -p $serverPath/web_conf/php/conf |
||||
echo 'set $PHP_ENV 0;' > $serverPath/web_conf/php/conf/enable-php-00.conf |
||||
|
||||
#初始化 |
||||
cd ${rootPath} && python3 ${rootPath}/plugins/apache/index.py start |
||||
cd ${rootPath} && python3 ${rootPath}/plugins/apache/index.py initd_install |
||||
fi |
||||
@ -0,0 +1,238 @@ |
||||
function orPost(method, args, callback){ |
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); |
||||
$.post('/plugins/run', {name:'openresty', func:method, args:JSON.stringify(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 orPluginService(_name, version){ |
||||
var data = {name:_name, func:'status'} |
||||
if ( typeof(version) != 'undefined' ){ |
||||
data['version'] = version; |
||||
} else { |
||||
version = ''; |
||||
} |
||||
|
||||
orPost('status', data, function(data){ |
||||
if (data.data == 'start'){ |
||||
orPluginSetService(_name, true, version); |
||||
} else { |
||||
orPluginSetService(_name, false, version); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
function orPluginSetService(_name ,status, version){ |
||||
var serviceCon ='<p class="status">当前状态:<span>'+(status ? '开启' : '关闭' )+ |
||||
'</span><span style="color: '+ |
||||
(status?'#20a53a;':'red;')+ |
||||
' margin-left: 3px;" class="glyphicon ' + (status?'glyphicon glyphicon-play':'glyphicon-pause')+'"></span></p><div class="sfm-opt">\ |
||||
<button class="btn btn-default btn-sm" onclick="orPluginOpService(\''+_name+'\',\''+(status?'stop':'start')+'\',\''+version+'\')">'+(status?'停止':'启动')+'</button>\ |
||||
<button class="btn btn-default btn-sm" onclick="orPluginOpService(\''+_name+'\',\'restart\',\''+version+'\',\'yes\')">重启</button>\ |
||||
<button class="btn btn-default btn-sm" onclick="orPluginOpService(\''+_name+'\',\'reload\',\''+version+'\')">重载配置</button>\ |
||||
</div>'; |
||||
$(".soft-man-con").html(serviceCon); |
||||
} |
||||
|
||||
|
||||
function orPluginOpService(a, b, v,request_callback) { |
||||
|
||||
var c = "name=" + a + "&func=" + b; |
||||
if(v != ''){ |
||||
c = c + '&version='+v; |
||||
} |
||||
|
||||
var d = ""; |
||||
|
||||
switch(b) { |
||||
case "stop":d = '停止';break; |
||||
case "start":d = '启动';break; |
||||
case "restart":d = '重启';break; |
||||
case "reload":d = '重载';break; |
||||
} |
||||
layer.confirm( msgTpl('您真的要{1}{2}{3}服务吗?', [d,a,v]), {icon:3,closeBtn: 2}, function() { |
||||
orPost('get_os',{},function(data){ |
||||
var rdata = $.parseJSON(data.data); |
||||
if (!rdata['auth']){ |
||||
layer.prompt({title: '检查到权限不足,需要输入密码!', formType: 1},function(pwd, index){ |
||||
|
||||
layer.close(index); |
||||
var data = {'pwd':pwd}; |
||||
c += '&args='+JSON.stringify(data); |
||||
orPluginOpServiceOp(a,b,c,d,a,v,request_callback); |
||||
}); |
||||
} else { |
||||
orPluginOpServiceOp(a,b,c,d,a,v,request_callback); |
||||
|
||||
} |
||||
}); |
||||
}) |
||||
} |
||||
|
||||
function orPluginOpServiceOp(a,b,c,d,a,v,request_callback){ |
||||
|
||||
var request_path = "/plugins/run"; |
||||
if (request_callback == 'yes'){ |
||||
request_path = "/plugins/callback"; |
||||
} |
||||
|
||||
var e = layer.msg(msgTpl('正在{1}{2}{3}服务,请稍候...',[d,a,v]), {icon: 16,time: 0}); |
||||
$.post(request_path, c, function(g) { |
||||
layer.close(e); |
||||
|
||||
var f = g.data == 'ok' ? msgTpl('{1}{2}服务已{3}',[a,v,d]) : msgTpl('{1}{2}服务{3}失败!',[a,v,d]); |
||||
layer.msg(f, {icon: g.data == 'ok' ? 1 : 2}); |
||||
|
||||
if( b != "reload" && g.data == 'ok' ) { |
||||
if ( b == 'start' ) { |
||||
orPluginSetService(a, true, v); |
||||
} else if ( b == 'stop' ){ |
||||
orPluginSetService(a, false, v); |
||||
} |
||||
} |
||||
|
||||
if( g.status && g.data != 'ok' ) { |
||||
layer.msg(g.data, {icon: 2,time: 10000,shade: 0.3}); |
||||
} |
||||
|
||||
},'json').error(function() { |
||||
layer.close(e); |
||||
layer.msg('操作异常!', {icon: 2}); |
||||
}); |
||||
} |
||||
|
||||
|
||||
//查看Nginx负载状态
|
||||
function getOpStatus() { |
||||
var loadT = layer.msg('正在处理,请稍后...', { icon: 16, time: 0, shade: 0.3 }); |
||||
$.post('/plugins/run', {name:'openresty', func:'run_info'}, function(data) { |
||||
layer.close(loadT);
|
||||
try { |
||||
var rdata = $.parseJSON(data.data); |
||||
if ('status' in rdata && !rdata.status){ |
||||
showMsg(rdata.msg, function(){}, null,3000); |
||||
return; |
||||
} |
||||
|
||||
var con = "<div><table class='table table-hover table-bordered'>\ |
||||
<tr><th>活动连接(Active connections)</th><td>" + rdata.active + "</td></tr>\ |
||||
<tr><th>总连接次数(accepts)</th><td>" + rdata.accepts + "</td></tr>\ |
||||
<tr><th>总握手次数(handled)</th><td>" + rdata.handled + "</td></tr>\ |
||||
<tr><th>总请求数(requests)</th><td>" + rdata.requests + "</td></tr>\ |
||||
<tr><th>请求数(Reading)</th><td>" + rdata.Reading + "</td></tr>\ |
||||
<tr><th>响应数(Writing)</th><td>" + rdata.Writing + "</td></tr>\ |
||||
<tr><th>驻留进程(Waiting)</th><td>" + rdata.Waiting + "</td></tr>\ |
||||
</table></div>"; |
||||
$(".soft-man-con").html(con); |
||||
}catch(err){ |
||||
showMsg(data.data, function(){}, null,3000); |
||||
} |
||||
},'json'); |
||||
} |
||||
|
||||
|
||||
function setOpCfg(){ |
||||
orPost('get_cfg', {}, function(data){ |
||||
var rdata = $.parseJSON(data.data); |
||||
var rdata = rdata.data; |
||||
// console.log(rdata);
|
||||
|
||||
var mlist = ''; |
||||
for (var i = 0; i < rdata.length; i++) { |
||||
var w = '70' |
||||
var ibody = '<input style="width: ' + w + 'px;" class="bt-input-text mr5" name="' + rdata[i].name + '" value="' + rdata[i].value + '" type="text" >'; |
||||
switch (rdata[i].type) { |
||||
case 0: |
||||
var selected_1 = (rdata[i].value == 1) ? 'selected' : ''; |
||||
var selected_0 = (rdata[i].value == 0) ? 'selected' : ''; |
||||
ibody = '<select class="bt-input-text mr5" name="' + rdata[i].name + '" style="width: ' + w + 'px;">\ |
||||
<option value="1" ' + selected_1 + '>开启</option>\ |
||||
<option value="0" ' + selected_0 + '>关闭</option>\ |
||||
</select>'; |
||||
break; |
||||
case 1: |
||||
var selected_1 = (rdata[i].value == 'on') ? 'selected' : ''; |
||||
var selected_0 = (rdata[i].value == 'off') ? 'selected' : ''; |
||||
ibody = '<select class="bt-input-text mr5" name="' + rdata[i].name + '" style="width: ' + w + 'px;">\ |
||||
<option value="on" ' + selected_1 + '>开启</option>\ |
||||
<option value="off" ' + selected_0 + '>关闭</option>\ |
||||
</select>'; |
||||
break; |
||||
} |
||||
mlist += '<p style="margin-top:15px;"><span>' + rdata[i].name + '</span>' + ibody + "<b class='unit c9'>"+rdata[i].unit+"</b>" +', <font class="c9">' + rdata[i].ps + '</font></p>'; |
||||
} |
||||
var con = '<style>.conf_p p{margin-bottom: 2px}</style><div class="conf_p" style="margin-bottom:0">\ |
||||
' + mlist + '\ |
||||
<div style="margin-top:10px; padding-right:15px" class="text-right">\ |
||||
<button class="btn btn-success btn-sm mr5" onclick="setOpCfg()">刷新</button>\ |
||||
<button class="btn btn-success btn-sm" onclick="submitConf()">保存</button>\ |
||||
</div>\ |
||||
</div>' |
||||
$(".soft-man-con").html(con); |
||||
}); |
||||
} |
||||
|
||||
function submitConf() { |
||||
var data = { |
||||
worker_processes: $("input[name='worker_processes']").val(), |
||||
worker_connections: $("input[name='worker_connections']").val(), |
||||
keepalive_timeout: $("input[name='keepalive_timeout']").val(), |
||||
zstd: $("select[name='zstd']").val() || 'on', |
||||
brotli: $("select[name='brotli']").val() || 'on', |
||||
gzip: $("select[name='gzip']").val() || 'on', |
||||
gzip_min_length: $("input[name='gzip_min_length']").val(), |
||||
gzip_comp_level: $("input[name='gzip_comp_level']").val(), |
||||
client_max_body_size: $("input[name='client_max_body_size']").val(), |
||||
server_names_hash_bucket_size: $("input[name='server_names_hash_bucket_size']").val(), |
||||
client_header_buffer_size: $("input[name='client_header_buffer_size']").val(), |
||||
}; |
||||
|
||||
// console.log(data);
|
||||
orPost('set_cfg', data, function(rdata){ |
||||
var rdata = $.parseJSON(rdata.data); |
||||
// console.log(rdata);
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); |
||||
}); |
||||
} |
||||
|
||||
function otherFunc(){ |
||||
var con = '<p class="conf_p" style="text-align:center;">\ |
||||
<button class="btn btn-default btn-sm" onclick="cronAddCheck()">添加检查任务</button> \ |
||||
<button class="btn btn-default btn-sm" onclick="cronDelCheck()">删除检查任务</button>\ |
||||
</p>'; |
||||
$(".soft-man-con").html(con); |
||||
} |
||||
|
||||
function cronAddCheck(){ |
||||
orPost('cron_add_check', {}, function(data){ |
||||
var rdata = $.parseJSON(data.data); |
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); |
||||
}); |
||||
} |
||||
|
||||
function cronDelCheck(){ |
||||
orPost('cron_del_check', {}, function(data){ |
||||
var rdata = $.parseJSON(data.data); |
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); |
||||
}); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,124 @@ |
||||
# coding:utf-8 |
||||
|
||||
import sys |
||||
import io |
||||
import os |
||||
import time |
||||
import json |
||||
|
||||
web_dir = os.getcwd() + "/web" |
||||
if os.path.exists(web_dir): |
||||
sys.path.append(web_dir) |
||||
os.chdir(web_dir) |
||||
|
||||
import core.mw as mw |
||||
from utils.crontab import crontab as MwCrontab |
||||
|
||||
|
||||
app_debug = False |
||||
if mw.isAppleSystem(): |
||||
app_debug = True |
||||
|
||||
|
||||
def getPluginName(): |
||||
return 'apache' |
||||
|
||||
|
||||
def getPluginDir(): |
||||
return mw.getPluginDir() + '/' + getPluginName() |
||||
|
||||
|
||||
def getServerDir(): |
||||
return mw.getServerDir() + '/' + getPluginName() |
||||
|
||||
|
||||
def getTaskConf(): |
||||
conf = getServerDir() + "/task_config.json" |
||||
return conf |
||||
|
||||
|
||||
def getConfigData(): |
||||
conf = getTaskConf() |
||||
if os.path.exists(conf): |
||||
return json.loads(mw.readFile(getTaskConf())) |
||||
return { |
||||
"task_id": -1, |
||||
"period": "minute-n", |
||||
"where1": "3", |
||||
"hour": "0", |
||||
"minute": "0", |
||||
} |
||||
|
||||
|
||||
def createBgTask(): |
||||
removeBgTask() |
||||
createBgTaskByName(getPluginName()) |
||||
|
||||
|
||||
def createBgTaskByName(name): |
||||
args = getConfigData() |
||||
_name = "[apache]检查任务" |
||||
res = mw.M("crontab").field("id, name").where("name=?", (_name,)).find() |
||||
if res: |
||||
return True |
||||
|
||||
if "task_id" in args and args["task_id"] > 0: |
||||
res = mw.M("crontab").field("id, name").where( |
||||
"id=?", (args["task_id"],)).find() |
||||
if res and res["id"] == args["task_id"]: |
||||
print("计划任务已经存在!") |
||||
return True |
||||
|
||||
mw_dir = mw.getPanelDir() |
||||
cmd = ''' |
||||
mw_dir=%s |
||||
rname=%s |
||||
plugin_path=%s |
||||
script_path=%s |
||||
''' % (mw_dir, name, getServerDir(), getPluginDir()) |
||||
cmd += 'echo "bash $script_path/check.sh"' + "\n" |
||||
cmd += 'cd $mw_dir && bash $script_path/check.sh' + "\n" |
||||
|
||||
params = { |
||||
'name': _name, |
||||
'type': args['period'], |
||||
'week': "", |
||||
'where1': args['where1'], |
||||
'hour': args['hour'], |
||||
'minute': args['minute'], |
||||
'save': "", |
||||
'backup_to': "", |
||||
'stype': "toShell", |
||||
'sname': '', |
||||
'sbody': cmd, |
||||
'url_address': '', |
||||
} |
||||
|
||||
task_id = MwCrontab.instance().add(params) |
||||
if task_id > 0: |
||||
args["task_id"] = task_id |
||||
args["name"] = name |
||||
mw.writeFile(getTaskConf(), json.dumps(args)) |
||||
|
||||
|
||||
def removeBgTask(): |
||||
cfg = getConfigData() |
||||
if "task_id" in cfg and cfg["task_id"] > 0: |
||||
res = mw.M("crontab").field("id, name").where( |
||||
"id=?", (cfg["task_id"],)).find() |
||||
if res and res["id"] == cfg["task_id"]: |
||||
data = MwCrontab.instance().delete(cfg["task_id"]) |
||||
if data["status"]: |
||||
cfg["task_id"] = -1 |
||||
mw.writeFile(getTaskConf(), json.dumps(cfg)) |
||||
return True |
||||
return False |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
if len(sys.argv) > 1: |
||||
action = sys.argv[1] |
||||
if action == "remove": |
||||
removeBgTask() |
||||
elif action == "add": |
||||
createBgTask() |
||||
@ -0,0 +1,154 @@ |
||||
#!/bin/bash |
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin |
||||
export PATH |
||||
|
||||
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/apache && bash install.sh install 2.4 |
||||
# cd /www/server/mdserver-web/plugins/apache && bash install.sh install 2.4 |
||||
|
||||
curPath=`pwd` |
||||
rootPath=$(dirname "$curPath") |
||||
rootPath=$(dirname "$rootPath") |
||||
serverPath=$(dirname "$rootPath") |
||||
|
||||
sysName=`uname` |
||||
action=$1 |
||||
type=$2 |
||||
|
||||
VERSION=2.4.66 |
||||
apacheDir=${serverPath}/source/apache |
||||
|
||||
Install_App() |
||||
{ |
||||
if [ "${action}" == "install" ];then |
||||
if [ -d $serverPath/apache ];then |
||||
exit 0 |
||||
fi |
||||
fi |
||||
|
||||
# ----- cpu start ------ |
||||
if [ -z "${cpuCore}" ]; then |
||||
cpuCore="1" |
||||
fi |
||||
|
||||
if [ -f /proc/cpuinfo ];then |
||||
cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l` |
||||
fi |
||||
|
||||
MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}') |
||||
if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then |
||||
if [ "${cpuCore}" -gt "${MEM_INFO}" ];then |
||||
cpuCore="${MEM_INFO}" |
||||
fi |
||||
else |
||||
cpuCore="1" |
||||
fi |
||||
|
||||
if [ "$cpuCore" -gt "2" ];then |
||||
cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` |
||||
else |
||||
cpuCore="1" |
||||
fi |
||||
# ----- cpu end ------ |
||||
|
||||
mkdir -p ${apacheDir} |
||||
echo 'install script ...' |
||||
OPTIONS='' |
||||
|
||||
# 安装 APR 和 APR-util |
||||
APR_VERSION=1.7.6 |
||||
APR_UTIL_VERSION=1.6.3 |
||||
|
||||
if [ ! -f ${apacheDir}/apr-${APR_VERSION}.tar.bz2 ];then |
||||
wget --no-check-certificate -O ${apacheDir}/apr-${APR_VERSION}.tar.bz2 https://downloads.apache.org/apr/apr-${APR_VERSION}.tar.bz2 -T 3 |
||||
fi |
||||
|
||||
if [ ! -f ${apacheDir}/apr-util-${APR_UTIL_VERSION}.tar.bz2 ];then |
||||
wget --no-check-certificate -O ${apacheDir}/apr-util-${APR_UTIL_VERSION}.tar.bz2 https://downloads.apache.org/apr/apr-util-${APR_UTIL_VERSION}.tar.bz2 -T 3 |
||||
fi |
||||
|
||||
# 安装 APR |
||||
if [ ! -d ${serverPath}/apache/apr ];then |
||||
cd ${apacheDir} && tar -jxf apr-${APR_VERSION}.tar.bz2 |
||||
cd ${apacheDir}/apr-${APR_VERSION} && ./configure --prefix=${serverPath}/apache/apr |
||||
if [ "$?" == "0" ];then |
||||
make -j${cpuCore} && make install |
||||
if [ ! -f ${serverPath}/apache/apr/bin/apr-config ];then |
||||
echo "APR installation failed: apr-config not found" |
||||
exit 1 |
||||
fi |
||||
else |
||||
echo "APR configure failed" |
||||
exit 1 |
||||
fi |
||||
fi |
||||
|
||||
# 安装 APR-util |
||||
if [ ! -d ${serverPath}/apache/apr-util ];then |
||||
cd ${apacheDir} && tar -jxf apr-util-${APR_UTIL_VERSION}.tar.bz2 |
||||
echo "${apacheDir} && tar -jxf apr-util-${APR_UTIL_VERSION}.tar.bz2" |
||||
echo "cd ${apacheDir}/apr-util-${APR_UTIL_VERSION} && ./configure --prefix=${serverPath}/apache/apr-util --with-apr=${serverPath}/apache/apr" |
||||
cd ${apacheDir}/apr-util-${APR_UTIL_VERSION} && ./configure --prefix=${serverPath}/apache/apr-util --with-apr=${serverPath}/apache/apr |
||||
if [ "$?" == "0" ];then |
||||
make -j${cpuCore} && make install |
||||
if [ ! -f ${serverPath}/apache/apr-util/bin/apu-config ];then |
||||
echo "APR-util installation failed: apu-config not found" |
||||
find ${serverPath}/apache/apr-util -name "apu-config" |
||||
exit 1 |
||||
fi |
||||
else |
||||
echo "APR-util configure failed" |
||||
exit 1 |
||||
fi |
||||
fi |
||||
|
||||
if [ ! -f ${apacheDir}/httpd-${VERSION}.tar.bz2 ];then |
||||
wget --no-check-certificate -O ${apacheDir}/httpd-${VERSION}.tar.bz2 https://downloads.apache.org/httpd/httpd-${VERSION}.tar.bz2 -T 3 |
||||
fi |
||||
|
||||
if [ ! -d ${apacheDir}/httpd-${VERSION} ];then |
||||
cd ${apacheDir} && tar -jxf ${apacheDir}/httpd-${VERSION}.tar.bz2 |
||||
fi |
||||
|
||||
|
||||
# 检查 APR 和 APR-util 可执行文件 |
||||
APR_CONFIG=$(find ${serverPath}/apache/apr -name "apr-config" | head -1) |
||||
APU_CONFIG=$(find ${serverPath}/apache/apr-util -name "apu-config" | head -1) |
||||
|
||||
if [ -z "$APR_CONFIG" ];then |
||||
echo "APR config not found" |
||||
exit 1 |
||||
fi |
||||
|
||||
if [ -z "$APU_CONFIG" ];then |
||||
echo "APR-util config not found" |
||||
exit 1 |
||||
fi |
||||
|
||||
echo "Using APR config: $APR_CONFIG" |
||||
echo "Using APR-util config: $APU_CONFIG" |
||||
|
||||
OPTIONS="${OPTIONS}--with-apr=$APR_CONFIG" |
||||
OPTIONS="${OPTIONS} --with-apr-util=$APU_CONFIG" |
||||
|
||||
cd ${apacheDir}/httpd-${VERSION} && ./configure \ |
||||
--prefix=$serverPath/apache \ |
||||
$OPTIONS |
||||
|
||||
make -j${cpuCore} && make install && make clean |
||||
|
||||
echo 'installation of apache completed' |
||||
} |
||||
|
||||
Uninstall_App() |
||||
{ |
||||
echo 'uninstalling apache completed' |
||||
} |
||||
|
||||
action=$1 |
||||
if [ "${1}" == "install" ];then |
||||
Install_App |
||||
elif [ "${1}" == "upgrade" ];then |
||||
Install_App |
||||
else |
||||
Uninstall_App |
||||
fi |
||||
Loading…
Reference in new issue