提交 185f74e2 authored 作者: chenshiying's avatar chenshiying

[新增] 部署脚本生成

上级 68539540
...@@ -4,6 +4,8 @@ target/ ...@@ -4,6 +4,8 @@ target/
!**/src/main/** !**/src/main/**
!**/src/test/** !**/src/test/**
### STS ### ### STS ###
.apt_generated .apt_generated
.classpath .classpath
...@@ -19,6 +21,7 @@ target/ ...@@ -19,6 +21,7 @@ target/
*.iml *.iml
*.ipr *.ipr
### NetBeans ### ### NetBeans ###
/nbproject/private/ /nbproject/private/
/nbbuild/ /nbbuild/
...@@ -29,3 +32,7 @@ build/ ...@@ -29,3 +32,7 @@ build/
### VS Code ### ### VS Code ###
.vscode/ .vscode/
### project Code ###
**/src/main/resources/bin/serverTest/**
...@@ -50,7 +50,8 @@ public class GeneratorScript { ...@@ -50,7 +50,8 @@ public class GeneratorScript {
for (DeployInfoDataDTO grayVersionDataDTO : grayVersionDataDTOList) { for (DeployInfoDataDTO grayVersionDataDTO : grayVersionDataDTOList) {
buildInitEnv(grayVersionDataDTO); buildInitEnv(grayVersionDataDTO);
buildConfig(grayVersionDataDTO); buildBackendConfig(grayVersionDataDTO);
buildFrontConfig(grayVersionDataDTO);
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -92,14 +93,15 @@ public class GeneratorScript { ...@@ -92,14 +93,15 @@ public class GeneratorScript {
/** /**
* 生成bootstrap.properties 及其 sh * 生成bootstrap.properties 及其 sh
*/ */
private static void buildConfig(DeployInfoDataDTO grayVersionDataDTO) throws IOException { private static void buildBackendConfig(DeployInfoDataDTO grayVersionDataDTO) throws IOException {
String serviceName = grayVersionDataDTO.getServiceName(); String serviceName = grayVersionDataDTO.getServiceName();
String fixedIp = grayVersionDataDTO.getFixedIp(); String fixedIp = grayVersionDataDTO.getFixedIp();
String port = grayVersionDataDTO.getPort(); String port = grayVersionDataDTO.getPort();
String deployPath = grayVersionDataDTO.getDeployPath(); String deployPath = grayVersionDataDTO.getDeployPath();
String deployJar = grayVersionDataDTO.getDeployJar(); String deployJar = grayVersionDataDTO.getDeployJar();
String serviceNameAbb = grayVersionDataDTO.getServiceNameAbb();
String springProfilesActive = grayVersionDataDTO.getSpringProfilesActive();
if (StringUtils.isBlank(serviceName)) { if (StringUtils.isBlank(serviceName)) {
return; return;
...@@ -110,7 +112,8 @@ public class GeneratorScript { ...@@ -110,7 +112,8 @@ public class GeneratorScript {
return; return;
} }
String fileDir = root_path_full + "\\" + fixedIp + "\\" + serviceName + "-" + port; String folderName = deployPath.replace("/home/soft/", "");
String fileDir = root_path_full + "\\" + fixedIp + "\\" + folderName;
File folder = new File(fileDir); File folder = new File(fileDir);
if (!folder.exists()) { if (!folder.exists()) {
folder.mkdirs(); folder.mkdirs();
...@@ -123,15 +126,61 @@ public class GeneratorScript { ...@@ -123,15 +126,61 @@ public class GeneratorScript {
model.put("serviceName", serviceName); model.put("serviceName", serviceName);
model.put("deployPath", deployPath); model.put("deployPath", deployPath);
model.put("deployJar", deployJar); model.put("deployJar", deployJar);
model.put("serviceNameAbb", serviceNameAbb);
model.put("springProfilesActive", springProfilesActive);
String result = FreeMarkerUtils.process("bootstrap.ftl", model); String result = FreeMarkerUtils.process("bootstrap.ftl", model);
FileUtils.write(bootstrapFileName, result); FileUtils.write(bootstrapFileName, result);
String replace = serviceName.replace("loit-", "deploy-"); String deployShFileName = fileDir + "\\deploy-" + serviceName + "-" + port + ".sh";
String deployShFileName = fileDir + "\\" + replace + "-" + port + ".sh";
String deployShResult = FreeMarkerUtils.process("deploy-sh.ftl", model); String deployShResult = FreeMarkerUtils.process("deploy-sh.ftl", model);
FileUtils.write(deployShFileName, deployShResult); FileUtils.write(deployShFileName, deployShResult);
} }
/**
* 生成bootstrap.properties 及其 sh
*/
private static void buildFrontConfig(DeployInfoDataDTO grayVersionDataDTO) throws IOException {
String serviceName = grayVersionDataDTO.getServiceName();
String fixedIp = grayVersionDataDTO.getFixedIp();
String port = grayVersionDataDTO.getPort();
String deployPath = grayVersionDataDTO.getDeployPath();
String deployJar = grayVersionDataDTO.getDeployJar();
String serviceNameAbb = grayVersionDataDTO.getServiceNameAbb();
if (StringUtils.isBlank(serviceName)) {
return;
}
BackendFrontEnum backendFrontType = BackendFrontEnum.getEnumByCode(grayVersionDataDTO.getBackendFrontType());
if (BackendFrontEnum.BACKEND.equals(backendFrontType)) {
return;
}
String folderName = deployPath.replace("/home/soft/", "");
String fileDir = root_path_full + "\\" + fixedIp + "\\" + folderName;
File folder = new File(fileDir);
if (!folder.exists()) {
folder.mkdirs();
}
Map model = new HashMap();
model.put("port", port);
model.put("serviceName", serviceName);
model.put("deployPath", deployPath);
model.put("deployJar", deployJar);
model.put("serviceNameAbb", serviceNameAbb);
String deployShFileName = fileDir + "\\deploy-" + serviceName + "-" + port + ".sh";
String deployShResult = FreeMarkerUtils.process("deploy-web-sh.ftl", model);
if ("portal-web".equals(serviceName)) {
deployShResult = FreeMarkerUtils.process("deploy-portal-web-sh.ftl", model);
}
FileUtils.write(deployShFileName, deployShResult);
}
} }
...@@ -40,6 +40,17 @@ public class DeployInfoDataDTO implements Serializable { ...@@ -40,6 +40,17 @@ public class DeployInfoDataDTO implements Serializable {
@ExcelField(title = "部署包名称", sort = 6) @ExcelField(title = "部署包名称", sort = 6)
private String deployJar; private String deployJar;
@ApiModelProperty(value = "前端子系统缩写")
@ExcelField(title = "前端子系统缩写", sort = 6)
private String serviceNameAbb;
@ApiModelProperty(value = "spring.profiles.active")
@ExcelField(title = "spring.profiles.active", sort = 6)
private String springProfilesActive;
public String getFixedIp() { public String getFixedIp() {
return fixedIp; return fixedIp;
} }
...@@ -95,4 +106,20 @@ public class DeployInfoDataDTO implements Serializable { ...@@ -95,4 +106,20 @@ public class DeployInfoDataDTO implements Serializable {
public void setDeployJar(String deployJar) { public void setDeployJar(String deployJar) {
this.deployJar = deployJar; this.deployJar = deployJar;
} }
public String getServiceNameAbb() {
return serviceNameAbb;
}
public void setServiceNameAbb(String serviceNameAbb) {
this.serviceNameAbb = serviceNameAbb;
}
public String getSpringProfilesActive() {
return springProfilesActive;
}
public void setSpringProfilesActive(String springProfilesActive) {
this.springProfilesActive = springProfilesActive;
}
} }
spring.profiles.active=prod${port} spring.profiles.active=prod${port}
spring.application.name=${serviceName} spring.application.name=loit-${serviceName}
# Nacos \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0135\ufffd\u05b7 # Nacos \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0135\ufffd\u05b7
spring.cloud.nacos.config.server-addr=10.0.120.221:8848 spring.cloud.nacos.config.server-addr=10.0.120.221:8848
spring.cloud.nacos.config.namespace=05270cbf-5a81-4a23-a534-b59ba26f11d5 spring.cloud.nacos.config.namespace=05270cbf-5a81-4a23-a534-b59ba26f11d5
......
#!/bin/sh
command=$(cat updowncommand.txt)
echo 'command:'$command
if [ -z "$1" ]; then
command='start'
echo 'command reset value:' $command
fi
PROCESS_ID=$(netstat -nlp | grep 9128| awk '{print $7}' | awk -F '[ / ]' '{print $1}')
echo 'ProcessId: ' $PROCESS_ID
for id in $PROCESS_ID
do
echo 'KILL_ID: ' $id
kill -s 9 $id
done
if [ "$command" != "stop" ]; then
cd ${deployPath}
rm -rf dist/
rm -rf ${serviceNameAbb}/
mkdir -p ${serviceNameAbb}/dist
unzip dist*.zip
cp -r dist/* ${serviceNameAbb}/dist
cp -r dist/static ${serviceNameAbb}/
#nohup ./node_modules/http-server/bin/http-server -p ${port} >/dev/null 2>&1 &
exit
fi
#!/bin/sh #!/bin/sh
echo '---------------kill_start----------------'
echo "pramas:" $1 echo "pramas:" $1
command=$(cat updowncommand.txt) command=$(cat updowncommand.txt)
echo 'command:' $command echo 'command:' $command
if [ -z "$1" ]; then if [ -z "$1" ]; then
command='up' command='start'
echo 'command reset value:' $command echo 'command reset value:' $command
fi fi
echo '---------------kill.jar----------------'
KILL_PROCESS_NAME='${deployPath}/${deployJar}' KILL_PROCESS_NAME='${deployPath}/${deployJar}'
PROCESS_ID=`ps -ef | grep $KILL_PROCESS_NAME | grep -v 'grep' | awk '{print $2}'` PROCESS_ID=`ps -ef | grep $KILL_PROCESS_NAME | grep -v 'grep' | awk '{print $2}'`
...@@ -19,21 +18,19 @@ echo 'ProcessId: ' $PROCESS_ID ...@@ -19,21 +18,19 @@ echo 'ProcessId: ' $PROCESS_ID
for id in $PROCESS_ID for id in $PROCESS_ID
do do
echo 'KILL_ID: ' $id echo 'KILL_ID: ' $id
kill -s 9 $id kill -s 9 $id
done done
echo '---------------killed.jar----------------' echo '---------------killed_stop----------------'
if [ "$command" != "stop" ]; then
if [ "$command" != "down" ]; then echo '---------------start----------------'
echo '---------------start.jar----------------'
nohup /usr/local/java/jdk1.8/bin/java -javaagent:/usr/local/skywalking/agent/skywalking-agent.jar -Dskywalking.trace.ignore_path=/api/v1/rest/event/longpolling -Dskywalking.agent.service_name=${serviceName} -Dskywalking.collector.backend_service=10.0.120.212:11800,10.0.120.143:11800,10.0.120.44:11800 -Xms2g -Xmx2g -jar $KILL_PROCESS_NAME --spring.profiles.active=prod${port} >/dev/null 2>&1 & nohup /usr/local/java/jdk1.8/bin/java -javaagent:/usr/local/skywalking/agent/skywalking-agent.jar -Dskywalking.trace.ignore_path=/api/v1/rest/event/longpolling -Dskywalking.agent.service_name=loit-${serviceName} -Dskywalking.collector.backend_service=10.0.120.212:11800,10.0.120.143:11800,10.0.120.44:11800 -Xms2g -Xmx2g -jar $KILL_PROCESS_NAME --spring.profiles.active=${springProfilesActive} >/dev/null 2>&1 &
echo '---------------started.jar----------------'
echo '---------------started----------------'
fi
for i in {1..30};do for i in {1..30};do
sleep 1 sleep 1
tail -n5 ${deployPath}/logs/${serviceName}.log tail -n5 ${deployPath}/logs/loit-${serviceName}.log
done done
fi
#!/bin/sh
command=$(cat updowncommand.txt)
echo 'command:'$command
if [ -z "$1" ]; then
command='start'
echo 'command reset value:' $command
fi
PROCESS_ID=$(netstat -nlp | grep 9128| awk '{print $7}' | awk -F '[ / ]' '{print $1}')
echo 'ProcessId: ' $PROCESS_ID
for id in $PROCESS_ID
do
echo 'KILL_ID: ' $id
kill -s 9 $id
done
if [ "$command" != "stop" ]; then
cd ${deployPath}
rm -rf dist/
rm -rf ${serviceNameAbb}/
mkdir -p ${serviceNameAbb}/dist
unzip dist*.zip
cp -r dist/* ${serviceNameAbb}/dist
cp -r dist/static ${serviceNameAbb}/
#nohup ./node_modules/http-server/bin/http-server -p ${port} >/dev/null 2>&1 &
exit
fi
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论