提交 5cef0135 authored 作者: chenshiying's avatar chenshiying

[新增] 部署脚本更新

上级 185f74e2
...@@ -81,11 +81,22 @@ pssh -h /home/soft/deploy/server/host_ip_skywalking.txt -i bash /usr/local/src/m ...@@ -81,11 +81,22 @@ pssh -h /home/soft/deploy/server/host_ip_skywalking.txt -i bash /usr/local/src/m
``` ```
8、发送部署包 8、部署文件更新
发送最新部署文件
```shell
sh push_script.sh
```
执行初始化 /home/soft 脚本
```shell
pssh -h /home/soft/deploy/server/host_ip_push_script.txt -i bash /home/soft/initEnv.sh
```
执行拷贝 nginx 配置文件
```shell
pssh -h /home/soft/deploy/server/host_ip_push_script.txt -i bash /home/soft/copyNginxConfig.sh
```
...@@ -73,10 +73,20 @@ public class GeneratorScript { ...@@ -73,10 +73,20 @@ public class GeneratorScript {
folder.mkdirs(); folder.mkdirs();
} }
String nginxConfigDir = root_path_full + "\\" + grayVersionDataDTO.getFixedIp() + "\\nginxConfig";
File nginxConfigFolder = new File(nginxConfigDir);
if (!nginxConfigFolder.exists()) {
nginxConfigFolder.mkdirs();
}
String filePath = fileDir + "\\initEnv.sh"; String filePath = fileDir + "\\initEnv.sh";
File file = new File(filePath); File file = new File(filePath);
if (!file.exists()) { if (!file.exists()) {
FileUtils.write(filePath, "#!/bin/bash "); FileUtils.write(filePath, "#!/bin/bash ");
//TODO
FileUtils.appendNewLine(filePath, "rm -rf /home/soft/*");
} }
String deployPath = grayVersionDataDTO.getDeployPath(); String deployPath = grayVersionDataDTO.getDeployPath();
...@@ -87,6 +97,12 @@ public class GeneratorScript { ...@@ -87,6 +97,12 @@ public class GeneratorScript {
FileUtils.appendNewLine(filePath, "mkdir -p " + deployPath + "/logs"); FileUtils.appendNewLine(filePath, "mkdir -p " + deployPath + "/logs");
} }
} }
String nginxConfigShFileName = fileDir + "\\copyNginxConfig.sh";
String nginxConfigShResult = FreeMarkerUtils.process("copyNginxConfig.ftl", null);
FileUtils.write(nginxConfigShFileName, nginxConfigShResult);
} }
...@@ -150,6 +166,7 @@ public class GeneratorScript { ...@@ -150,6 +166,7 @@ public class GeneratorScript {
String deployPath = grayVersionDataDTO.getDeployPath(); String deployPath = grayVersionDataDTO.getDeployPath();
String deployJar = grayVersionDataDTO.getDeployJar(); String deployJar = grayVersionDataDTO.getDeployJar();
String serviceNameAbb = grayVersionDataDTO.getServiceNameAbb(); String serviceNameAbb = grayVersionDataDTO.getServiceNameAbb();
String nginxConfigName = grayVersionDataDTO.getNginxConfigName();
if (StringUtils.isBlank(serviceName)) { if (StringUtils.isBlank(serviceName)) {
...@@ -174,6 +191,7 @@ public class GeneratorScript { ...@@ -174,6 +191,7 @@ public class GeneratorScript {
model.put("deployPath", deployPath); model.put("deployPath", deployPath);
model.put("deployJar", deployJar); model.put("deployJar", deployJar);
model.put("serviceNameAbb", serviceNameAbb); model.put("serviceNameAbb", serviceNameAbb);
model.put("nginxConfigName", nginxConfigName);
String deployShFileName = fileDir + "\\deploy-" + serviceName + "-" + port + ".sh"; String deployShFileName = fileDir + "\\deploy-" + serviceName + "-" + port + ".sh";
String deployShResult = FreeMarkerUtils.process("deploy-web-sh.ftl", model); String deployShResult = FreeMarkerUtils.process("deploy-web-sh.ftl", model);
...@@ -182,5 +200,12 @@ public class GeneratorScript { ...@@ -182,5 +200,12 @@ public class GeneratorScript {
} }
FileUtils.write(deployShFileName, deployShResult); FileUtils.write(deployShFileName, deployShResult);
if (StringUtils.isNotBlank(nginxConfigName)) {
String nginxName = root_path_full + "\\" + fixedIp + "\\nginxConfig" + "\\" + nginxConfigName;
String nginxConfigResult = FreeMarkerUtils.process("nginx_config.ftl", model);
FileUtils.write(nginxName, nginxConfigResult);
}
} }
} }
...@@ -37,20 +37,25 @@ public class DeployInfoDataDTO implements Serializable { ...@@ -37,20 +37,25 @@ public class DeployInfoDataDTO implements Serializable {
private String port; private String port;
@ApiModelProperty(value = "部署包名称") @ApiModelProperty(value = "部署包名称")
@ExcelField(title = "部署包名称", sort = 6) @ExcelField(title = "部署包名称", sort = 7)
private String deployJar; private String deployJar;
@ApiModelProperty(value = "前端子系统缩写") @ApiModelProperty(value = "前端子系统缩写")
@ExcelField(title = "前端子系统缩写", sort = 6) @ExcelField(title = "前端子系统缩写", sort = 8)
private String serviceNameAbb; private String serviceNameAbb;
@ApiModelProperty(value = "spring.profiles.active") @ApiModelProperty(value = "spring.profiles.active")
@ExcelField(title = "spring.profiles.active", sort = 6) @ExcelField(title = "spring.profiles.active", sort = 9)
private String springProfilesActive; private String springProfilesActive;
@ApiModelProperty(value = "nginxConfigName")
@ExcelField(title = "nginxConfigName", sort = 10)
private String nginxConfigName;
public String getFixedIp() { public String getFixedIp() {
return fixedIp; return fixedIp;
} }
...@@ -122,4 +127,12 @@ public class DeployInfoDataDTO implements Serializable { ...@@ -122,4 +127,12 @@ public class DeployInfoDataDTO implements Serializable {
public void setSpringProfilesActive(String springProfilesActive) { public void setSpringProfilesActive(String springProfilesActive) {
this.springProfilesActive = springProfilesActive; this.springProfilesActive = springProfilesActive;
} }
public String getNginxConfigName() {
return nginxConfigName;
}
public void setNginxConfigName(String nginxConfigName) {
this.nginxConfigName = nginxConfigName;
}
} }
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
[ ! -f /root/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -f /root/.ssh/id_rsa &>/dev/null [ ! -f /root/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -f /root/.ssh/id_rsa &>/dev/null
while read line;do while read line;do
user_name=`echo $line | cut -d " " -f1` # 提取文件中的用户名 ip=`echo $line | cut -d " " -f1` # 提取文件中的用户名
pass_word=`echo $line | cut -d " " -f2` # 提取文件中的密码
ip=`echo $line | cut -d " " -f3` # 提取文件中的ip
scp -r /home/soft/deploy/server/$ip/* root@$ip:/home/soft scp -r /home/soft/deploy/server/$ip/* root@$ip:/home/soft
......
#!/bin/bash
\cp -rf /home/soft/nginxConfig/ /usr/local/nginx/conf/conf.d.start/
server{
listen 9527;
server_name localhost;
gzip on;
gzip_buffers 32 4K;
gzip_comp_level 6;
gzip_min_length 100;
gzip_types application/javascript text/css text/xml;
gzip_vary on;
location /{
root /home/soft/loit-portal-web-9527/;
try_files $uri $uri/ /index.html;
index index.html;
}
}
spring.profiles.active=prod${port} spring.profiles.active=${springProfilesActive}
spring.application.name=loit-${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
......
#!/bin/bash
\cp -rf /home/soft/nginxConfig/ /usr/local/nginx/conf/conf.d.start/
#!/bin/sh #!/bin/sh
params1=$1
command=$(cat updowncommand.txt) command=$(cat updowncommand.txt)
echo 'command:'$command echo 'command:'$command
if [ -z "$1" ]; then if [ -z "$params1" ]; then
command='start' command="start"
echo 'command reset value:' $command echo 'command reset value:' $command
fi fi
PROCESS_ID=$(netstat -nlp | grep 9128| awk '{print $7}' | awk -F '[ / ]' '{print $1}') if [ "$params1" = "stop" ]; then
command="stop"
echo 'ProcessId: ' $PROCESS_ID echo 'command params value:' $command
fi
for id in $PROCESS_ID nginxConf="/${nginxConfigName}"
nginxPath="/usr/local/nginx/"
do startPath=$nginxPath'conf/conf.d.start'
echo 'KILL_ID: ' $id startConf=$startPath$nginxConf
kill -s 9 $id stopPath=$nginxPath'conf/conf.d.stop'
done stopConf=$stopPath$nginxConf
echo 'startConf:'$startConf
if [ "$command" = "stop" ]; then
echo 'test'
if [ -e "$startConf" ]; then
echo 'copy to stop file'
mv $startConf $stopPath
fi
fi
if [ "$command" != "stop" ]; then if [ "$command" != "stop" ]; then
if [ -e "$stopConf" ]; then
echo 'copy to start file'
mv $stopConf $startPath
fi
cd ${deployPath} cd ${deployPath}
rm -rf dist
rm -rf static
rm -rf vue-permission/static
unzip dist*.zip
cp -r dist/static static
cp -r dist/static vue-permission/static
rm -rf dist/ fi
rm -rf ${serviceNameAbb}/
mkdir -p ${serviceNameAbb}/dist pid_file=$nginxPath"logs/nginx.pid"
unzip dist*.zip if [ ! -e "$pid_file" ]; then
cp -r dist/* ${serviceNameAbb}/dist /usr/local/nginx/sbin/nginx
cp -r dist/static ${serviceNameAbb}/ fi
#nohup ./node_modules/http-server/bin/http-server -p ${port} >/dev/null 2>&1 & if [ -e "$pid_file" ]; then
exit /usr/local/nginx/sbin/nginx -s reload
fi fi
#!/bin/sh
command=$(cat updowncommand.txt)
echo 'command:'$command
if [ -z "$1" ]; then
command='start'
echo 'command reset value:' $command
fi
nginxConf="/${nginxConfigName}"
nginxPath="/usr/local/nginx/"
startPath=$nginxPath'conf/conf.d.start'
startConf=$startPath$nginxConf
stopPath=$nginxPath'conf/conf.d.stop'
stopConf=$stopPath$nginxConf
echo 'startConf:'$startConf
if [ "$command" = "stop" ]; then
echo 'test'
if [ -e "$startConf" ]; then
echo 'copy to stop file'
mv $startConf $stopPath
fi
fi
if [ "$command" != "stop" ]; then
if [ -e "$stopConf" ]; then
echo 'copy to start file'
mv $stopConf $startPath
fi
fi
if [ "$command" = "deploy" ]; 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}/
fi
pid_file=$nginxPath"logs/nginx.pid"
if [ ! -e ${r"${pid_file}"} ]; then
/usr/local/nginx/sbin/nginx
fi
if [ -e ${r"${pid_file}"} ]; then
/usr/local/nginx/sbin/nginx -s reload
fi
#!/bin/sh #!/bin/sh
params1=$1
command=$(cat updowncommand.txt) command=$(cat updowncommand.txt)
echo 'command:'$command echo 'command:'$command
if [ -z "$1" ]; then if [ -z "$params1" ]; then
command='start' command="start"
echo 'command reset value:' $command echo 'command reset value:' $command
fi fi
PROCESS_ID=$(netstat -nlp | grep 9128| awk '{print $7}' | awk -F '[ / ]' '{print $1}') if [ "$params1" = "stop" ]; then
command="stop"
echo 'ProcessId: ' $PROCESS_ID echo 'command params value:' $command
fi
for id in $PROCESS_ID nginxConf="/${nginxConfigName}"
nginxPath="/usr/local/nginx/"
do startPath=$nginxPath'conf/conf.d.start'
echo 'KILL_ID: ' $id startConf=$startPath$nginxConf
kill -s 9 $id stopPath=$nginxPath'conf/conf.d.stop'
done stopConf=$stopPath$nginxConf
echo 'startConf:'$startConf
if [ "$command" = "stop" ]; then
echo 'test'
if [ -e "$startConf" ]; then
echo 'copy to stop file'
mv $startConf $stopPath
fi
fi
if [ "$command" != "stop" ]; then if [ "$command" != "stop" ]; then
cd ${deployPath} if [ -e "$stopConf" ]; then
echo 'copy to start file'
mv $stopConf $startPath
fi
cd ${deployPath}
rm -rf dist/ rm -rf dist/
rm -rf ${serviceNameAbb}/ rm -rf ${serviceNameAbb}/
mkdir -p ${serviceNameAbb}/dist mkdir -p ${serviceNameAbb}/dist
unzip dist*.zip unzip dist*.zip
cp -r dist/* ${serviceNameAbb}/dist cp -r dist/* ${serviceNameAbb}/dist
cp -r dist/static ${serviceNameAbb}/ cp -r dist/static ${serviceNameAbb}/
#nohup ./node_modules/http-server/bin/http-server -p ${port} >/dev/null 2>&1 & fi
exit
pid_file=$nginxPath"logs/nginx.pid"
if [ ! -e "$pid_file" ]; then
/usr/local/nginx/sbin/nginx
fi
if [ -e "$pid_file" ]; then
/usr/local/nginx/sbin/nginx -s reload
fi fi
server{
listen ${port};
server_name localhost;
gzip on;
gzip_buffers 32 4K;
gzip_comp_level 6;
gzip_min_length 100;
gzip_types application/javascript text/css text/xml;
gzip_vary on;
location /{
root ${deployPath}/;
try_files $uri $uri/ /index.html;
index index.html;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论