0.0.1-SNAPSHOT
wangbing 5 years ago
parent 5e3ba5e368
commit 616922e041

@ -101,22 +101,31 @@ public class AjaxController {
private BaseResponse nginxStart(String jsonString, Token token) {
BaseResponse baseResponse = new BaseResponse();
String exec = ProcessUtil.execBat(nginxCtrl.getStartCmd());
System.out.println(exec);
if (nginxCtrl.isRunning()) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, "程序已经运行");
return baseResponse;
}
ProcessUtil.execBat(nginxCtrl.getStartCmd());
return baseResponse;
}
private BaseResponse nginxStop(String jsonString, Token token) {
BaseResponse baseResponse = new BaseResponse();
String exec = ProcessUtil.execBat(nginxCtrl.getStopCmd());
System.out.println(exec);
if (!nginxCtrl.isRunning()) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, "程序尚未运行");
return baseResponse;
}
ProcessUtil.execBat(nginxCtrl.getStopCmd());
return baseResponse;
}
private BaseResponse nginxReload(String jsonString, Token token) {
BaseResponse baseResponse = new BaseResponse();
String exec = ProcessUtil.execBat(nginxCtrl.getReloadCmd());
System.out.println(exec);
if (!nginxCtrl.isRunning()) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, "程序尚未运行");
return baseResponse;
}
ProcessUtil.execBat(nginxCtrl.getReloadCmd());
return baseResponse;
}

@ -2,6 +2,8 @@ package com.example.action.screen;
import com.example.frame.base.Screen;
import com.example.frame.utils.ProcessUtil;
import com.example.module.admin.ent.NginxCtrl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import javax.servlet.http.HttpServletRequest;
@ -9,10 +11,11 @@ import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
public class Mapping extends Screen {
@Autowired
private NginxCtrl nginxCtrl;
@Override
public void exec(Model model, HttpServletRequest request, HttpServletResponse response) {
boolean nginx = ProcessUtil.findProcess("nginx");
model.addAttribute("run", nginx ? "true" : "false");
model.addAttribute("run", nginxCtrl.isRunning() ? "true" : "false");
}
}

@ -27,6 +27,8 @@ public class NginxConfig {
@Autowired
private Environment environment;
@Autowired
private ObjectClient objectClient;
@Bean
public NginxCtrl initNginx() {
@ -69,6 +71,7 @@ public class NginxConfig {
nginxCtrl.setStopCmd(stop.getAbsolutePath());
nginxCtrl.setReloadCmd(reload.getAbsolutePath());
nginxCtrl.setVersionCmd(nginxHome.getAbsolutePath() + " -v ");
return nginxCtrl;
}
}

@ -3,6 +3,7 @@ package com.example.config;
import com.example.frame.utils.FileUtil;
import com.example.frame.utils.ZipUtil;
import com.example.module.admin.ent.Mapping;
import com.example.module.admin.ent.Port;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.system.ApplicationHome;
@ -20,6 +21,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Configuration
@ -41,7 +43,15 @@ public class SqliteConfig {
ArrayList<Class> objects = new ArrayList<>();
objects.add(Mapping.class);
return new ObjectClient(new File(dbpath, "data.db"), objects);
objects.add(Port.class);
ObjectClient objectClient = new ObjectClient(new File(dbpath, "data.db"), objects);
List<Port> select = objectClient.select(Port.class, 1, 1);
if (select.size() == 0 && objectClient.insert(Port.class, new Port("8888")) != 1) {
throw new RuntimeException("Nginx default port 8888 init failed.");
}
return objectClient;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {

@ -5,6 +5,7 @@ import com.example.frame.base.Message;
import com.example.frame.base.MessageType;
import com.example.frame.utils.LogUtil;
import com.example.frame.utils.ProcessUtil;
import com.example.module.admin.ent.NginxCtrl;
import com.example.module.admin.ent.State;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@ -27,13 +28,15 @@ public class TaskConfig implements SchedulingConfigurer {
@Autowired
private GlobalController globalController;
@Autowired
private NginxCtrl nginxCtrl;
@Scheduled(cron = "0/3 * * * * ? ")
public void task() {
Message message = new Message();
message.setType(MessageType.NGINX_STATE);
State state = new State();
state.setRun(ProcessUtil.findProcess("nginx"));
state.setRun(nginxCtrl.isRunning());
message.setObject(state);
globalController.pushAll(message);
}

@ -19,11 +19,12 @@ public class ProcessUtil {
*
* @param exe exe
*/
public static String execExe(String exe) {
if (!exe.endsWith(".bat")) {
throw new RuntimeException(exe + "is not a file of .exe");
public static void execExe(String exe) {
try {
Runtime.getRuntime().exec(exe);
} catch (IOException e) {
e.printStackTrace();
}
return exec(exe);
}
/**
@ -31,11 +32,15 @@ public class ProcessUtil {
*
* @param bat
*/
public static String execBat(String bat) {
public static void execBat(String bat) {
if (!bat.endsWith(".bat")) {
throw new RuntimeException(bat + "is not a file of .bat");
}
return exec("call "+bat);
try {
Runtime.getRuntime().exec(bat);
} catch (IOException e) {
e.printStackTrace();
}
}
/**

@ -53,4 +53,8 @@ public class NginxCtrl {
public void setVersionCmd(String versionCmd) {
this.versionCmd = versionCmd;
}
public boolean isRunning(){
return ProcessUtil.findProcess("nginx.exe");
}
}

@ -0,0 +1,33 @@
package com.example.module.admin.ent;
import xyz.wbsite.wsqlite.anonation.TableField;
import java.util.Date;
/**
* MAPPING -
*
* @author author
* @version 0.0.1
* @since 2019-09-28
*/
public class Port {
/**
* VALUE -
*/
@TableField
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Port(String value) {
this.value = value;
}
}

@ -0,0 +1,60 @@
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /tzzdxxsb/ {
proxy_pass http://127.0.0.1:8081/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 128k;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
index index.html index.htm index.jsp index.do;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

@ -15,7 +15,7 @@
</el-card>
<el-card class="box-card control">
<a> Nginx 控制中心</a>
<a>Nginx 控制中心</a>
<a @click="nginxStart">
<el-image v-if="run" :src="'${Uri.getUrl('/static/img/start_.png')}'" style="width: 50px; height: 50px"
fit="fill"></el-image>
@ -37,12 +37,23 @@
</a>
</el-card>
<el-card class="box-card">
<el-card class="box-card" v-for="item in services">
<el-row>
<el-col :span="12">
<el-input size="small" v-model="item.port" placeholder="请输入端口" style="width: 250px;text-align: center" suffix-icon="el-icon-edit">
<template slot="prepend">端口</template>
<el-button type="warning" slot="append" icon="el-icon-refresh">应用</el-button>
</el-input>
</el-col>
<el-col :span="12">
<span style="float: right;">
<el-button type="success" size="small" icon="el-icon-plus" @click="onAction(['create',''])">新增
</el-button>
<el-button type="warning" size="small" icon="el-icon-download">导出</el-button>
<el-button size="small" icon="el-icon-refresh" @click="onFind"></el-button>
</span>
<el-dialog :title="form.title" :visible.sync="form.dialog">
<el-form :model="form" :rules="formRules" ref="form" label-width="90px"
@ -60,12 +71,6 @@
</span>
</el-dialog>
</el-col>
<el-col :span="12">
<el-button-group style="float: right;">
<el-button size="small" icon="el-icon-refresh" @click="onFind"></el-button>
</el-button-group>
</el-col>
</el-row>
<el-table
@ -130,12 +135,17 @@
<style>
#app {
padding: 10px;
width: 800px;
}
.box-card {
margin: 10px;
}
.control a:first-child {
padding-right: 10px;
}
.control a {
display: inline-block;
line-height: 50px;
@ -180,6 +190,9 @@
{min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur'}
],
},
services: [
{port: "8080"}
],
select: [],
result: [],
run: ${run?default('false')}

Loading…
Cancel
Save

Powered by TurnKey Linux.