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

[新增] 部署脚本生成

上级 68539540
......@@ -4,6 +4,8 @@ target/
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
......@@ -19,6 +21,7 @@ target/
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
......@@ -29,3 +32,7 @@ build/
### VS Code ###
.vscode/
### project Code ###
**/src/main/resources/bin/serverTest/**
......@@ -50,7 +50,8 @@ public class GeneratorScript {
for (DeployInfoDataDTO grayVersionDataDTO : grayVersionDataDTOList) {
buildInitEnv(grayVersionDataDTO);
buildConfig(grayVersionDataDTO);
buildBackendConfig(grayVersionDataDTO);
buildFrontConfig(grayVersionDataDTO);
}
} catch (Exception e) {
......@@ -92,14 +93,15 @@ public class GeneratorScript {
/**
* 生成bootstrap.properties 及其 sh
*/
private static void buildConfig(DeployInfoDataDTO grayVersionDataDTO) throws IOException {
private static void buildBackendConfig(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();
String springProfilesActive = grayVersionDataDTO.getSpringProfilesActive();
if (StringUtils.isBlank(serviceName)) {
return;
......@@ -110,7 +112,8 @@ public class GeneratorScript {
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);
if (!folder.exists()) {
folder.mkdirs();
......@@ -123,15 +126,61 @@ public class GeneratorScript {
model.put("serviceName", serviceName);
model.put("deployPath", deployPath);
model.put("deployJar", deployJar);
model.put("serviceNameAbb", serviceNameAbb);
model.put("springProfilesActive", springProfilesActive);
String result = FreeMarkerUtils.process("bootstrap.ftl", model);
FileUtils.write(bootstrapFileName, result);
String replace = serviceName.replace("loit-", "deploy-");
String deployShFileName = fileDir + "\\" + replace + "-" + port + ".sh";
String deployShFileName = fileDir + "\\deploy-" + serviceName + "-" + port + ".sh";
String deployShResult = FreeMarkerUtils.process("deploy-sh.ftl", model);
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 {
@ExcelField(title = "部署包名称", sort = 6)
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() {
return fixedIp;
}
......@@ -95,4 +106,20 @@ public class DeployInfoDataDTO implements Serializable {
public void setDeployJar(String 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.application.name=${serviceName}
spring.application.name=loit-${serviceName}
# 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.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
echo '---------------kill_start----------------'
echo "pramas:" $1
command=$(cat updowncommand.txt)
echo 'command:' $command
if [ -z "$1" ]; then
command='up'
echo 'command reset value:' $command
command='start'
echo 'command reset value:' $command
fi
echo '---------------kill.jar----------------'
KILL_PROCESS_NAME='${deployPath}/${deployJar}'
PROCESS_ID=`ps -ef | grep $KILL_PROCESS_NAME | grep -v 'grep' | awk '{print $2}'`
......@@ -19,21 +18,19 @@ echo 'ProcessId: ' $PROCESS_ID
for id in $PROCESS_ID
do
echo 'KILL_ID: ' $id
kill -s 9 $id
echo 'KILL_ID: ' $id
kill -s 9 $id
done
echo '---------------killed.jar----------------'
if [ "$command" != "down" ]; then
echo '---------------start.jar----------------'
echo '---------------killed_stop----------------'
if [ "$command" != "stop" ]; then
echo '---------------start----------------'
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 &
echo '---------------started.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=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----------------'
fi
for i in {1..30};do
sleep 1
tail -n5 ${deployPath}/logs/${serviceName}.log
sleep 1
tail -n5 ${deployPath}/logs/loit-${serviceName}.log
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论