|
@ -4,6 +4,7 @@ import cn.hutool.db.Session; |
|
|
import com.insigma.config.AppCfg; |
|
|
import com.insigma.config.AppCfg; |
|
|
import com.insigma.entry.IndexObj; |
|
|
import com.insigma.entry.IndexObj; |
|
|
import com.insigma.entry.TabColObj; |
|
|
import com.insigma.entry.TabColObj; |
|
|
|
|
|
import com.insigma.func.ThrowingConsumer; |
|
|
import com.insigma.service.Computer; |
|
|
import com.insigma.service.Computer; |
|
|
import com.insigma.service.*; |
|
|
import com.insigma.service.*; |
|
|
import com.insigma.utils.*; |
|
|
import com.insigma.utils.*; |
|
@ -37,7 +38,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean runBak() throws Exception { |
|
|
public boolean runBak() { |
|
|
boolean retBool; |
|
|
boolean retBool; |
|
|
log.info("创建备份文件目录..."); |
|
|
log.info("创建备份文件目录..."); |
|
|
String format = DateTimeFormatter.BASIC_ISO_DATE.format(LocalDate.now()); |
|
|
String format = DateTimeFormatter.BASIC_ISO_DATE.format(LocalDate.now()); |
|
@ -50,7 +51,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
copyFileByA57(format); |
|
|
copyFileByA57(format); |
|
|
|
|
|
|
|
|
log.info("停止 数据库 服务..."); |
|
|
log.info("停止 数据库 服务..."); |
|
|
ws.stopService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
log.info("备份压缩数据库文件..."); |
|
|
log.info("备份压缩数据库文件..."); |
|
|
ZipUtil.zip7Z( |
|
|
ZipUtil.zip7Z( |
|
@ -63,7 +66,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
AppCfg.HZB + File.separatorChar + format + ".gz"); |
|
|
AppCfg.HZB + File.separatorChar + format + ".gz"); |
|
|
|
|
|
|
|
|
log.info("启动 数据库 服务..."); |
|
|
log.info("启动 数据库 服务..."); |
|
|
ws.startService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
retBool = true; |
|
|
retBool = true; |
|
|
} else { |
|
|
} else { |
|
|
retBool = false; |
|
|
retBool = false; |
|
@ -93,7 +98,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean runRestore(String path) throws Exception { |
|
|
public boolean runRestore(String path) { |
|
|
boolean retBool; |
|
|
boolean retBool; |
|
|
boolean b = cn.hutool.core.io.FileUtil.isFile(path); |
|
|
boolean b = cn.hutool.core.io.FileUtil.isFile(path); |
|
|
if(b){ |
|
|
if(b){ |
|
@ -106,7 +111,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
|
|
|
|
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
ws.stopService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
log.info("删除原数据文件..."); |
|
|
log.info("删除原数据文件..."); |
|
|
cn.hutool.core.io.FileUtil.del(dbPath); |
|
|
cn.hutool.core.io.FileUtil.del(dbPath); |
|
@ -119,7 +126,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
|
|
|
|
|
|
log.info("移动照片文件..."); |
|
|
log.info("移动照片文件..."); |
|
|
cn.hutool.core.io.FileUtil.copy(namePath + picPath, AppCfg.HZB + picPath, true); |
|
|
cn.hutool.core.io.FileUtil.copy(namePath + picPath, AppCfg.HZB + picPath, true); |
|
|
ws.startService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
retBool = true; |
|
|
retBool = true; |
|
|
}else{ |
|
|
}else{ |
|
|
log.error("判断文件:{}...不存在,请检查!", path); |
|
|
log.error("判断文件:{}...不存在,请检查!", path); |
|
@ -127,6 +136,18 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
} |
|
|
} |
|
|
return retBool; |
|
|
return retBool; |
|
|
} |
|
|
} |
|
|
|
|
|
private boolean canNotRun(WinServiceTool.WindowsService ws, |
|
|
|
|
|
ThrowingConsumer<WinServiceTool.WindowsService, Exception> consumer) { |
|
|
|
|
|
boolean canRun; |
|
|
|
|
|
try { |
|
|
|
|
|
consumer.accept(ws); |
|
|
|
|
|
canRun = true; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("执行发生异常:{}", e.getMessage()); |
|
|
|
|
|
canRun = false; |
|
|
|
|
|
} |
|
|
|
|
|
return !canRun; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean rebuildIndex(List<IndexObj> index) { |
|
|
public boolean rebuildIndex(List<IndexObj> index) { |
|
@ -166,7 +187,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
* @throws Exception |
|
|
* @throws Exception |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public boolean setDbSize(int ...size) throws Exception { |
|
|
public boolean setDbSize(int ...size) { |
|
|
if(size == null || size.length!=1){ |
|
|
if(size == null || size.length!=1){ |
|
|
log.error("请检测参数是否正确..."); |
|
|
log.error("请检测参数是否正确..."); |
|
|
return false; |
|
|
return false; |
|
@ -174,7 +195,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
log.info("停止 数据库 服务..."); |
|
|
log.info("停止 数据库 服务..."); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
ws.stopService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.info("设置 数据库 内存参数..."); |
|
|
log.info("设置 数据库 内存参数..."); |
|
@ -183,7 +206,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
String.format("innodb_buffer_pool_size=%dM", size[0])); |
|
|
String.format("innodb_buffer_pool_size=%dM", size[0])); |
|
|
|
|
|
|
|
|
log.info("启动 数据库 服务..."); |
|
|
log.info("启动 数据库 服务..."); |
|
|
ws.startService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -245,11 +270,13 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean cleanMwCache() throws Exception { |
|
|
public boolean cleanMwCache() { |
|
|
log.info("停止 中间件 服务..."); |
|
|
log.info("停止 中间件 服务..."); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
ws.stopService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.info("退出 浏览器..."); |
|
|
log.info("退出 浏览器..."); |
|
@ -269,7 +296,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
FileUtil.delAllFile(AppCfg.HZB + "/tomcat8/logs"); |
|
|
FileUtil.delAllFile(AppCfg.HZB + "/tomcat8/logs"); |
|
|
|
|
|
|
|
|
log.info("启动 中间件 服务..."); |
|
|
log.info("启动 中间件 服务..."); |
|
|
ws.startService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -280,7 +309,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
* @throws Exception |
|
|
* @throws Exception |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public boolean setMwSize(int ...size) throws Exception { |
|
|
public boolean setMwSize(int ...size) { |
|
|
if(size == null || size.length!=4){ |
|
|
if(size == null || size.length!=4){ |
|
|
log.error("请检测参数是否正确..."); |
|
|
log.error("请检测参数是否正确..."); |
|
|
return false; |
|
|
return false; |
|
@ -288,7 +317,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
log.info("停止 中间件 服务..."); |
|
|
log.info("停止 中间件 服务..."); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
ws.stopService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(WinCommandUtil.RegisterUtil.registerJava(AppCfg.HZB, size[0], size[1], size[2], size[3])){ |
|
|
if(WinCommandUtil.RegisterUtil.registerJava(AppCfg.HZB, size[0], size[1], size[2], size[3])){ |
|
@ -296,7 +327,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.info("启动 中间件 服务..."); |
|
|
log.info("启动 中间件 服务..."); |
|
|
ws.startService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -340,52 +373,58 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean startDbService() throws Exception { |
|
|
public boolean startDbService() { |
|
|
|
|
|
boolean bool; |
|
|
log.info("启动 数据库 服务..."); |
|
|
log.info("启动 数据库 服务..."); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.STOPPED){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.STOPPED){ |
|
|
ws.startService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
return true; |
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
ws.restartService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::restartService)) { |
|
|
return true; |
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean stopDbService() throws Exception { |
|
|
public boolean stopDbService() { |
|
|
|
|
|
boolean bool; |
|
|
log.info("停止 数据库 服务..."); |
|
|
log.info("停止 数据库 服务..."); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
ws.stopService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { |
|
|
return true; |
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean startMwService() throws Exception { |
|
|
public boolean startMwService() { |
|
|
|
|
|
boolean bool; |
|
|
log.info("启动 中间件 服务..."); |
|
|
log.info("启动 中间件 服务..."); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.STOPPED){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.STOPPED){ |
|
|
ws.startService(); |
|
|
return !canNotRun(ws, WinServiceTool.WindowsService::startService); |
|
|
return true; |
|
|
|
|
|
} |
|
|
} |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
ws.restartService(); |
|
|
return !canNotRun(ws, WinServiceTool.WindowsService::restartService); |
|
|
return true; |
|
|
|
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean stopMwService() throws Exception { |
|
|
public boolean stopMwService() { |
|
|
log.info("停止 中间件 服务..."); |
|
|
log.info("停止 中间件 服务..."); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
ws.stopService(); |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|