0.0.1-SNAPSHOT
wangbing 5 years ago
parent 1719a94030
commit 597b13390b

@ -148,6 +148,9 @@ public class AjaxController {
baseResponse.addError(ErrorType.BUSINESS_ERROR, "程序尚未运行"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "程序尚未运行");
return baseResponse; return baseResponse;
} }
// 刷新配置文件
flushConfig();
// 重新加载配置文件
ProcessUtil.execBat(nginxCtrl.getReloadCmd()); ProcessUtil.execBat(nginxCtrl.getReloadCmd());
return baseResponse; return baseResponse;
} }
@ -210,10 +213,15 @@ public class AjaxController {
} }
private void flushConfig() { private void flushConfig() {
Writer wr = null;
try { try {
File config = nginxCtrl.getConfig();
HashMap<String, Object> context = new HashMap<>(); HashMap<String, Object> context = new HashMap<>();
PortLoadResponse portLoadResponse = (PortLoadResponse) loadPort("", LocalData.getSysToken());
context.put("services",portLoadResponse.getResult());
Template template = freeMarkerConfigurer.getConfiguration().getTemplate("nginx.conf"); Template template = freeMarkerConfigurer.getConfiguration().getTemplate("nginx.conf");
Writer wr = new OutputStreamWriter(new FileOutputStream(outfile), "UTF-8"); wr = new OutputStreamWriter(new FileOutputStream(config), "UTF-8");
//写入 //写入
template.process(context, wr); template.process(context, wr);
//关闭流 //关闭流
@ -222,6 +230,12 @@ public class AjaxController {
e.printStackTrace(); e.printStackTrace();
} catch (TemplateException e) { } catch (TemplateException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try {
wr.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
} }

@ -71,7 +71,7 @@ public class NginxConfig {
nginxCtrl.setStopCmd(stop.getAbsolutePath()); nginxCtrl.setStopCmd(stop.getAbsolutePath());
nginxCtrl.setReloadCmd(reload.getAbsolutePath()); nginxCtrl.setReloadCmd(reload.getAbsolutePath());
nginxCtrl.setVersionCmd(nginxHome.getAbsolutePath() + " -v "); nginxCtrl.setVersionCmd(nginxHome.getAbsolutePath() + " -v ");
nginxCtrl.setConfig(new File(new File(nginxHome, "conf"), "nginx.conf"));
return nginxCtrl; return nginxCtrl;
} }
} }

@ -25,24 +25,15 @@ public class Mapping {
*/ */
@TableField @TableField
private Long serviceId; private Long serviceId;
/**
* NAME -
*/
@TableField @TableField
private String name; private String name;
/**
* VALUE -
*/
@TableField @TableField
private String value; private String context;
/** @TableField
* BZ - private String location;
*/
@TableField @TableField
private String bz; private String bz;
@TableField @TableField
// @JsonFormat(timezone = "GMT+8", pattern = "yyyyMMddHHmmss")
private Date createTime; private Date createTime;
@TableField @TableField
private boolean isDeleted; private boolean isDeleted;
@ -63,12 +54,20 @@ public class Mapping {
this.name = name; this.name = name;
} }
public String getValue() { public String getContext() {
return value; return context;
}
public void setContext(String context) {
this.context = context;
}
public String getLocation() {
return location;
} }
public void setValue(String value) { public void setLocation(String location) {
this.value = value; this.location = location;
} }
public String getBz() { public String getBz() {

@ -3,22 +3,25 @@ package com.example.module.admin.ent;
import com.example.frame.utils.ProcessUtil; import com.example.frame.utils.ProcessUtil;
import java.io.File;
public class NginxCtrl { public class NginxCtrl {
private String startCmd = "start nginx"; private String startCmd = "start nginx";
private String stopCmd = "nginx.exe -s quit"; private String stopCmd = "nginx.exe -s quit";
private String reloadCmd = "nginx.exe -s reload"; private String reloadCmd = "nginx.exe -s reload";
private String versionCmd = "nginx -v"; private String versionCmd = "nginx -v";
private File config = null;
public void doStart(){ public void doStart() {
ProcessUtil.exec(startCmd); ProcessUtil.exec(startCmd);
} }
public void doStop(){ public void doStop() {
ProcessUtil.exec(stopCmd); ProcessUtil.exec(stopCmd);
} }
public void doReload(){ public void doReload() {
ProcessUtil.exec(reloadCmd); ProcessUtil.exec(reloadCmd);
} }
@ -54,7 +57,15 @@ public class NginxCtrl {
this.versionCmd = versionCmd; this.versionCmd = versionCmd;
} }
public boolean isRunning(){ public File getConfig() {
return config;
}
public void setConfig(File config) {
this.config = config;
}
public boolean isRunning() {
return ProcessUtil.findProcess("nginx.exe"); return ProcessUtil.findProcess("nginx.exe");
} }
} }

@ -7,6 +7,7 @@ import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.Length;
import xyz.wbsite.wsqlite.anonation.TableField;
/** /**
* MappingCreateRequest - * MappingCreateRequest -
@ -32,7 +33,10 @@ public class MappingCreateRequest extends BaseRequest {
@NotNull(message = "映射值不能为空") @NotNull(message = "映射值不能为空")
@Pattern(regexp = "[^/]*", message = "映射值不能存在/") @Pattern(regexp = "[^/]*", message = "映射值不能存在/")
@Pattern(regexp = "\\w*", message = "映射值需为英文") @Pattern(regexp = "\\w*", message = "映射值需为英文")
private String value; private String context;
@TableField
private String location;
/** /**
* BZ - * BZ -
@ -55,12 +59,20 @@ public class MappingCreateRequest extends BaseRequest {
this.name = name; this.name = name;
} }
public String getValue() { public String getContext() {
return value; return context;
}
public void setContext(String context) {
this.context = context;
}
public String getLocation() {
return location;
} }
public void setValue(String value) { public void setLocation(String location) {
this.value = value; this.location = location;
} }
public String getBz() { public String getBz() {

@ -20,6 +20,8 @@ http {
sendfile on; sendfile on;
keepalive_timeout 65; keepalive_timeout 65;
<#list services as item>
server { server {
listen 8888; listen 8888;
server_name localhost; server_name localhost;
@ -28,13 +30,9 @@ http {
#access_log logs/host.access.log main; #access_log logs/host.access.log main;
location / { <#list services.mappingList as mapping>
root html; location /#{mapping.context} {
index index.html index.htm; proxy_pass http://#{location};
}
location /tzzdxxsb/ {
proxy_pass http://127.0.0.1:8081/;
proxy_redirect off; proxy_redirect off;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
@ -51,10 +49,12 @@ http {
index index.html index.htm index.jsp index.do; index index.html index.htm index.jsp index.do;
} }
</#list>
error_page 500 502 503 504 /50x.html; error_page 500 502 503 504 /50x.html;
location = /50x.html { location = /50x.html {
root html; root html;
} }
} }
</#list>
} }

@ -68,11 +68,16 @@
<el-form-item label="名称" prop="name"> <el-form-item label="名称" prop="name">
<el-input v-model="form.name" clearable size="small" placeholder="简要描述"></el-input> <el-input v-model="form.name" clearable size="small" placeholder="简要描述"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="路径" prop="value"> <el-form-item label="路径" prop="context">
<el-input v-model="form.value" clearable size="small" placeholder="字母数字组合"> <el-input v-model="form.value" clearable size="small" placeholder="字母数字组合">
<template slot="prepend">:{{form.port}}/</template> <template slot="prepend">:{{form.port}}/</template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item label="地址" prop="location">
<el-input v-model="form.value" clearable size="small" placeholder="字母数字组合">
<template slot="prepend">http://</template>
</el-input>
</el-form-item>
<el-form-item label="备注" prop="bz"> <el-form-item label="备注" prop="bz">
<el-input type="textarea" v-model="form.bz" clearable size="small" <el-input type="textarea" v-model="form.bz" clearable size="small"
placeholder="备注信息"></el-input> placeholder="备注信息"></el-input>
@ -97,7 +102,12 @@
<el-table-column <el-table-column
width="150px" width="150px"
label="路径" label="路径"
prop="value"> prop="context">
</el-table-column>
<el-table-column
width="150px"
label="地址"
prop="location">
</el-table-column> </el-table-column>
<el-table-column <el-table-column
width="150px" width="150px"

@ -31,7 +31,8 @@ public class MappingTest {
public void createMapping() { public void createMapping() {
MappingCreateRequest createRequest = new MappingCreateRequest(); MappingCreateRequest createRequest = new MappingCreateRequest();
createRequest.setName("测试"); createRequest.setName("测试");
createRequest.setValue("test"); createRequest.setContext("test");
createRequest.setLocation("test");
MappingCreateResponse mappingCreateResponse = mappingManager.create(createRequest, token); MappingCreateResponse mappingCreateResponse = mappingManager.create(createRequest, token);
assertTrue(!mappingCreateResponse.hasError()); assertTrue(!mappingCreateResponse.hasError());

Loading…
Cancel
Save

Powered by TurnKey Linux.