|
@@ -1,21 +1,18 @@
|
|
|
package org.jeecg.modules.adweb.site.service;
|
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
-import jakarta.servlet.http.HttpServletRequest;
|
|
|
-import jakarta.servlet.http.HttpSession;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.constant.SymbolConstant;
|
|
|
import org.jeecg.common.constant.WebsocketConst;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
-import org.jeecg.modules.adweb.common.dto.ServerDTO;
|
|
|
import org.jeecg.modules.adweb.common.service.FeishuService;
|
|
|
import org.jeecg.modules.adweb.common.service.ShellService;
|
|
|
import org.jeecg.modules.adweb.common.service.WebSocketService;
|
|
|
import org.jeecg.modules.adweb.common.util.ShellSSH2Util;
|
|
|
import org.jeecg.modules.adweb.server.entity.AdwebServer;
|
|
|
import org.jeecg.modules.adweb.server.service.IAdwebServerService;
|
|
|
-import org.jeecg.modules.adweb.site.constant.WordPressConstants;
|
|
|
import org.jeecg.modules.adweb.site.entity.AdwebSite;
|
|
|
import org.jeecg.modules.adweb.system.entity.SysException;
|
|
|
import org.jeecg.modules.adweb.system.service.ISysExceptionService;
|
|
@@ -24,6 +21,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.security.InvalidKeyException;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.Date;
|
|
@@ -64,6 +62,9 @@ public class SelfWebSiteService {
|
|
|
@Value("${AdwebSiteConnect.password}")
|
|
|
private String password;
|
|
|
|
|
|
+ @Value(value = "${jeecg.path.upload}")
|
|
|
+ private String uploadpath;
|
|
|
+
|
|
|
@Resource
|
|
|
private FeishuService openFeishuMsgService;
|
|
|
|
|
@@ -132,11 +133,11 @@ public class SelfWebSiteService {
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(errorMsg)) {
|
|
|
- createSiteFailed(adwebSite, errorMsg);
|
|
|
+ createSiteFailed(adwebSite, errorMsg, 4);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("在wp服务器上生成站点文件失败");
|
|
|
- createSiteFailed(adwebSite, e.getMessage());
|
|
|
+ createSiteFailed(adwebSite, e.getMessage(), 4);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -214,14 +215,14 @@ public class SelfWebSiteService {
|
|
|
* @param adwebSite 代表临时站点的对象,包含站点的相关信息
|
|
|
* @param errorMsg 描述创建失败的错误信息
|
|
|
*/
|
|
|
- private void createSiteFailed(AdwebSite adwebSite, String errorMsg) {
|
|
|
- adwebSite.setStatus(4); // 临时站点创建失败
|
|
|
+ private void createSiteFailed(AdwebSite adwebSite, String errorMsg, int status) {
|
|
|
+ adwebSite.setStatus(status); // 临时站点创建失败 或者正式站点创建失败
|
|
|
siteService.updateById(adwebSite);
|
|
|
|
|
|
SysException sysException = new SysException();
|
|
|
|
|
|
- sysException.setType(1);
|
|
|
- sysException.setFunctionModule("拉取临时站点错误");
|
|
|
+ sysException.setType(1); // 业务错误
|
|
|
+ sysException.setFunctionModule("拉取站点错误");
|
|
|
sysException.setExceptionDetail(String.format("站点code:%s, 站点名称:%s,临时连接:%s", adwebSite.getCode(), adwebSite.getName(), adwebSite.getDomain()));
|
|
|
sysException.setExceptionDescription(errorMsg);
|
|
|
|
|
@@ -232,18 +233,17 @@ public class SelfWebSiteService {
|
|
|
/**
|
|
|
* 发布站点到生产环境
|
|
|
*
|
|
|
- * @param request HTTP请求对象,用于获取会话信息
|
|
|
+ * @param user 当前登录用户
|
|
|
* @param serverId 服务器ID,未在方法体内使用
|
|
|
* @param domain 域名,用于站点发布
|
|
|
* @param siteCode 站点代码,标识特定的站点
|
|
|
*/
|
|
|
@Async
|
|
|
- public void releaseSite(HttpServletRequest request, String serverId, String domain, String siteCode) {
|
|
|
+ public void releaseSite(LoginUser user, String serverId, String domain, String siteCode) {
|
|
|
log.info("===== releaseSite domain:{},siteCode:{} ====", domain, siteCode);
|
|
|
StringBuilder statusSuccess = new StringBuilder();
|
|
|
StringBuilder statusFail = new StringBuilder();
|
|
|
AdwebSite adwebSite = siteService.getSiteByCode(siteCode);
|
|
|
- HttpSession session = request.getSession();
|
|
|
AdwebServer adwebServer = serverService.getById(serverId);
|
|
|
|
|
|
if (adwebServer == null) {
|
|
@@ -251,7 +251,7 @@ public class SelfWebSiteService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- String usWest118ServerShellPath = "/home/ci-user/shell";
|
|
|
+ String serverShellPath = "/opt/adweb3/shell";
|
|
|
|
|
|
//原始域名
|
|
|
String originDomain = domain;
|
|
@@ -260,123 +260,94 @@ public class SelfWebSiteService {
|
|
|
domain = domain.replace("www.", "");
|
|
|
}
|
|
|
String dbName = domain.replaceAll("[^a-zA-Z0-9]", "") + "_" + adwebSite.getCode();
|
|
|
- log.info("===== releaseSite domain:{},siteCode:{},originDomain:{},domain:{},dbName:{} ====", domain, siteCode, originDomain, domain, dbName);
|
|
|
|
|
|
- String cmd = "";
|
|
|
- if (WordPressConstants.DEV_CI1.equals(adwebSite.getDevServerIp())) {
|
|
|
- cmd = "sudo sh " + usWest118ServerShellPath + "/adweb-publish_http.sh " + adwebSite.getCode() + " " + domain + " " + dbName;
|
|
|
- }
|
|
|
- if (WordPressConstants.DEV_CI2.equals(adwebSite.getDevServerIp())) {
|
|
|
- cmd = "sudo sh " + usWest118ServerShellPath + "/adweb-publish-devci2_http.sh " + adwebSite.getCode() + " " + domain + " " + dbName;
|
|
|
- }
|
|
|
- log.info("===== releaseSite originDomain:{},domain:{},siteCode:{},cmd:{} ====", originDomain, domain, siteCode, cmd);
|
|
|
+ log.info("===== releaseSite domain:{}, siteCode:{},originDomain:{},domain:{},dbName:{} ====", domain, siteCode, originDomain, domain, dbName);
|
|
|
|
|
|
- if (StringUtils.isEmpty(cmd)) {
|
|
|
- String errorMsg = "网站上线脚本命令获取失败!";
|
|
|
- String title = "网站域名:" + originDomain + " 站点发布失败";
|
|
|
- String message = "**站点ID:** " + siteCode + "\n";
|
|
|
- message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
- message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
- message += "**错误原因:** " + errorMsg + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
- Result.error("该站点的发布上线命令执行失败,请重试!");
|
|
|
- return;
|
|
|
- }
|
|
|
+ String cmd = "sudo sh " + serverShellPath + "/publish_wp_site.sh " + adwebSite.getCode() + " " + domain + " " + dbName;
|
|
|
+
|
|
|
+ log.info("===== releaseSite originDomain:{},domain:{},siteCode:{},cmd:{} ====", originDomain, domain, siteCode, cmd);
|
|
|
|
|
|
-// return false;
|
|
|
try {
|
|
|
-// modifyMaterialImgToUs(adwebSite.getCode());
|
|
|
-// shellService.exceShellByUsWest118(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
-// @Override
|
|
|
-// public void stdout(String line) {
|
|
|
-// log.info("标准 :" + line);
|
|
|
-// msgSetInSessionProd(request, line);
|
|
|
-// if ("ERROR:FILE_NAME IS EXISTS".equals(line)) {
|
|
|
-// // TODO ----
|
|
|
-// }
|
|
|
-// if ("[Creationcompleted]".equals(line)) {
|
|
|
-// log.info("======网站上线成功======");
|
|
|
-// statusSuccess.append("ok");
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void stderr(String line) {
|
|
|
-// log.info("错误 :" + line);
|
|
|
-// statusFail.append(line);
|
|
|
-// }
|
|
|
-// });
|
|
|
-// //发布完成后,调用脚本,停止测试站点的访问
|
|
|
-// try {
|
|
|
-// String delCmd = "/home/ci-user/shell/deldns " + adwebSite.getCode();
|
|
|
-// log.info("/***************开始停止测试站点*****************/");
|
|
|
-// shellService.createShareSiteByPwd(delCmd, host, port, username, password, new ShellSSH2Util.StdoutListener() {
|
|
|
-// @Override
|
|
|
-// public void stdout(String line) {
|
|
|
-// log.info("停止测试站,标准 :" + line);
|
|
|
-// //信息存入session
|
|
|
-// if ("ERROR:FILE_NAME IS EXISTS".equals(line)) {
|
|
|
-// // TODO ----
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void stderr(String line) {
|
|
|
-// log.info(line);
|
|
|
-// }
|
|
|
-// });
|
|
|
-// log.info("/***************停止测试站点结束,成功*****************/");
|
|
|
-// } catch (Exception e) {
|
|
|
-// log.info("停止测试站异常", e);
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
- //正式域名
|
|
|
+ if (StringUtils.isBlank(adwebServer.getServerPem())) {
|
|
|
+ String[] userIds = {user.getId()};
|
|
|
+ // 给该站点所属的用户发送消息
|
|
|
+ log.info("生产服务器:{},未配置连接秘钥", adwebServer.getServerName());
|
|
|
+ webSocketService.sendMessage(userIds, "站点发布失败通知", "该站点发布失败,请联系管理员配置服务器连接秘钥", WebsocketConst.CMD_MANAGE_SITE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ adwebSite.setStatus(5); //正式站点正在创建
|
|
|
+ siteService.updateById(adwebSite);
|
|
|
+ sendAdWebV3FeiShuMsg("tets", "teste");
|
|
|
+
|
|
|
+ String pemPath = adwebServer.getServerPem().replace("..", "").replace("../", "");
|
|
|
+ if (pemPath.endsWith(SymbolConstant.COMMA)) {
|
|
|
+ pemPath = pemPath.substring(0, pemPath.length() - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ String filePath = uploadpath + File.separator + pemPath;
|
|
|
+ adwebServer.setServerPem(filePath); // 设置秘钥绝对路径
|
|
|
+
|
|
|
+ shellService.exceShell(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
+ @Override
|
|
|
+ public void stdout(String line) {
|
|
|
+ log.info("标准 :" + line);
|
|
|
+
|
|
|
+ if ("ERROR:FILE_NAME IS EXISTS".equals(line)) {
|
|
|
+ // TODO ----
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ("[Creationcompleted]".equals(line)) {
|
|
|
+ log.info("======网站上线成功======");
|
|
|
+ statusSuccess.append("ok");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- log.info("===== releaseSite originDomain:{},domain:{},siteId:{},statusSuccess:{} ====", originDomain, domain, siteCode, statusSuccess);
|
|
|
- log.info("===== releaseSite originDomain:{},domain:{},siteId:{},statusFail:{} ====", originDomain, domain, siteCode, statusFail);
|
|
|
+ @Override
|
|
|
+ public void stderr(String line) {
|
|
|
+ log.info("错误 :" + line);
|
|
|
+ statusFail.append(line);
|
|
|
+ }
|
|
|
+ }, adwebServer);
|
|
|
+
|
|
|
+
|
|
|
+ //正式域名
|
|
|
+ log.info("===== releaseSite originDomain:{},domain:{},siteCode:{},statusSuccess:{} ====", originDomain, domain, siteCode, statusSuccess);
|
|
|
+ log.info("===== releaseSite originDomain:{},domain:{},siteCode:{},statusFail:{} ====", originDomain, domain, siteCode, statusFail);
|
|
|
if (StringUtils.isNotEmpty(statusFail.toString())) {
|
|
|
String title = "网站域名:" + originDomain + " 站点发布失败";
|
|
|
- String message = "**站点ID:** " + siteCode + "\n";
|
|
|
+ String message = "**站点CODE:** " + siteCode + "\n";
|
|
|
message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
message += "**错误信息:** " + statusFail.toString() + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
+ sendAdWebV3FeiShuMsg(title, message);
|
|
|
|
|
|
// 站点发布失败
|
|
|
- adwebSite.setStatus(6);
|
|
|
- siteService.updateById(adwebSite);
|
|
|
- Result.error("网站发布上线失败!");
|
|
|
+ createSiteFailed(adwebSite, statusFail.toString(), 6);
|
|
|
+
|
|
|
} else {
|
|
|
String title = "网站域名:" + originDomain + " 站点发布成功";
|
|
|
- String message = "**站点ID:** " + siteCode + "\n";
|
|
|
+ String message = "**站点CODE:** " + siteCode + "\n";
|
|
|
message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
+ sendAdWebV3FeiShuMsg(title, message);
|
|
|
|
|
|
// 创建站点完成-操作
|
|
|
adwebSite.setDomain(originDomain);
|
|
|
adwebSite.setIsDomain(1);
|
|
|
-
|
|
|
//添加发布时间
|
|
|
adwebSite.setIssueTime(new Date());
|
|
|
//发布成功后修改状态为发布成功状态 :1
|
|
|
adwebSite.setStatus(1);
|
|
|
- adwebSite.setProdServerIp(WordPressConstants.PROD_WP_SERVER_IP);
|
|
|
+ adwebSite.setProdServerIp(adwebServer.getServerIp());
|
|
|
siteService.updateById(adwebSite);
|
|
|
- // 将数据库中关键词的域名修改一致
|
|
|
- // UpdateWrapper<SeoKeywords> updateWrapper = new UpdateWrapper<>();
|
|
|
- // updateWrapper.eq("user_flag", adwebSite.getCode());
|
|
|
- // updateWrapper.set("domain", domain);
|
|
|
- // seoKeywordsService.update(updateWrapper);
|
|
|
- session.setAttribute("shellLineModular", "");
|
|
|
- Result.OK("网站发布上线成功!");
|
|
|
+
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- log.error("站点发布失败,退出执行;" + e.getMessage(), e);
|
|
|
- // 站点发布失败
|
|
|
- adwebSite.setStatus(6);
|
|
|
- siteService.updateById(adwebSite);
|
|
|
- Result.error("网站发布上线失败!");
|
|
|
+ log.error("站点发布失败,退出执行;{}", e.getMessage(), e);
|
|
|
+ createSiteFailed(adwebSite, e.getMessage(), 6);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -412,7 +383,7 @@ public class SelfWebSiteService {
|
|
|
// String message = "**站点ID:** " + siteId + "\n";
|
|
|
// message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
// message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
-// sendAdWebV2FeiShuMsg(title, message);
|
|
|
+// sendAdWebV3FeiShuMsg(title, message);
|
|
|
//
|
|
|
// delSuccess.append(line);
|
|
|
// }
|
|
@@ -424,7 +395,7 @@ public class SelfWebSiteService {
|
|
|
// message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
// message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
// message += "**错误信息:** " + line + "\n";
|
|
|
-// sendAdWebV2FeiShuMsg(title, message);
|
|
|
+// sendAdWebV3FeiShuMsg(title, message);
|
|
|
//
|
|
|
// delFail.append(line);
|
|
|
// }
|
|
@@ -438,7 +409,7 @@ public class SelfWebSiteService {
|
|
|
// message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
// message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
// message += "**错误信息:** " + line + "\n";
|
|
|
-// sendAdWebV2FeiShuMsg(title, message);
|
|
|
+// sendAdWebV3FeiShuMsg(title, message);
|
|
|
//
|
|
|
// delFail.append(line);
|
|
|
// }
|
|
@@ -471,7 +442,7 @@ public class SelfWebSiteService {
|
|
|
AdwebSite adwebSite = siteService.getById(siteId);
|
|
|
|
|
|
// 获取站点所在生产服务器信息
|
|
|
- ServerDTO serverInfo = new ServerDTO();
|
|
|
+ AdwebServer serverInfo = new AdwebServer();
|
|
|
boolean flag = false;
|
|
|
switch (status) {
|
|
|
case 1:
|
|
@@ -552,9 +523,9 @@ public class SelfWebSiteService {
|
|
|
* @param adwebSite
|
|
|
* @return
|
|
|
*/
|
|
|
- private boolean startSite(LoginUser sysUser, AdwebSite adwebSite, ServerDTO serverInfo) {
|
|
|
+ private boolean startSite(LoginUser sysUser, AdwebSite adwebSite, AdwebServer serverInfo) {
|
|
|
//站点启动
|
|
|
- String cmd = "./shell/start_site " + serverInfo.getIp() + " " + adwebSite.getCode() + " ";
|
|
|
+ String cmd = "./shell/start_site " + serverInfo.getServerIp() + " " + adwebSite.getCode() + " ";
|
|
|
shellService.exceShell(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
@Override
|
|
|
public void stdout(String line) {
|
|
@@ -580,8 +551,8 @@ public class SelfWebSiteService {
|
|
|
* @param adwebSite
|
|
|
* @return
|
|
|
*/
|
|
|
- private boolean stopSite(LoginUser sysUser, AdwebSite adwebSite, ServerDTO serverInfo) {
|
|
|
- String cmd = "./shell/stop_site " + serverInfo.getIp() + " " + adwebSite.getCode() + " ";
|
|
|
+ private boolean stopSite(LoginUser sysUser, AdwebSite adwebSite, AdwebServer serverInfo) {
|
|
|
+ String cmd = "./shell/stop_site " + serverInfo.getServerIp() + " " + adwebSite.getCode() + " ";
|
|
|
shellService.exceShell(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
@Override
|
|
|
public void stdout(String line) {
|
|
@@ -622,9 +593,9 @@ public class SelfWebSiteService {
|
|
|
* @param msgTitle
|
|
|
* @param message
|
|
|
*/
|
|
|
- public void sendAdWebV2FeiShuMsg(String msgTitle, String message) {
|
|
|
+ public void sendAdWebV3FeiShuMsg(String msgTitle, String message) {
|
|
|
try {
|
|
|
- openFeishuMsgService.sendAdWebV2FeiShuMsg(msgTitle, message);
|
|
|
+ openFeishuMsgService.sendAdWebV3FeiShuMsg(msgTitle, message);
|
|
|
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|