提交 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
```
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 {
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";
File file = new File(filePath);
if (!file.exists()) {
FileUtils.write(filePath, "#!/bin/bash ");
//TODO
FileUtils.appendNewLine(filePath, "rm -rf /home/soft/*");
}
String deployPath = grayVersionDataDTO.getDeployPath();
......@@ -87,6 +97,12 @@ public class GeneratorScript {
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 {
String deployPath = grayVersionDataDTO.getDeployPath();
String deployJar = grayVersionDataDTO.getDeployJar();
String serviceNameAbb = grayVersionDataDTO.getServiceNameAbb();
String nginxConfigName = grayVersionDataDTO.getNginxConfigName();
if (StringUtils.isBlank(serviceName)) {
......@@ -174,6 +191,7 @@ public class GeneratorScript {
model.put("deployPath", deployPath);
model.put("deployJar", deployJar);
model.put("serviceNameAbb", serviceNameAbb);
model.put("nginxConfigName", nginxConfigName);
String deployShFileName = fileDir + "\\deploy-" + serviceName + "-" + port + ".sh";
String deployShResult = FreeMarkerUtils.process("deploy-web-sh.ftl", model);
......@@ -182,5 +200,12 @@ public class GeneratorScript {
}
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 {
private String port;
@ApiModelProperty(value = "部署包名称")
@ExcelField(title = "部署包名称", sort = 6)
@ExcelField(title = "部署包名称", sort = 7)
private String deployJar;
@ApiModelProperty(value = "前端子系统缩写")
@ExcelField(title = "前端子系统缩写", sort = 6)
@ExcelField(title = "前端子系统缩写", sort = 8)
private String serviceNameAbb;
@ApiModelProperty(value = "spring.profiles.active")
@ExcelField(title = "spring.profiles.active", sort = 6)
@ExcelField(title = "spring.profiles.active", sort = 9)
private String springProfilesActive;
@ApiModelProperty(value = "nginxConfigName")
@ExcelField(title = "nginxConfigName", sort = 10)
private String nginxConfigName;
public String getFixedIp() {
return fixedIp;
}
......@@ -122,4 +127,12 @@ public class DeployInfoDataDTO implements Serializable {
public void setSpringProfilesActive(String springProfilesActive) {
this.springProfilesActive = springProfilesActive;
}
public String getNginxConfigName() {
return nginxConfigName;
}
public void setNginxConfigName(String nginxConfigName) {
this.nginxConfigName = nginxConfigName;
}
}
......@@ -3,9 +3,7 @@
[ ! -f /root/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -f /root/.ssh/id_rsa &>/dev/null
while read line;do
user_name=`echo $line | cut -d " " -f1` # 提取文件中的用户名
pass_word=`echo $line | cut -d " " -f2` # 提取文件中的密码
ip=`echo $line | cut -d " " -f3` # 提取文件中的ip
ip=`echo $line | cut -d " " -f1` # 提取文件中的用户名
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}
# Nacos \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0135\ufffd\u05b7
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
params1=$1
command=$(cat updowncommand.txt)
echo 'command:'$command
if [ -z "$1" ]; then
command='start'
if [ -z "$params1" ]; 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 [ "$params1" = "stop" ]; then
command="stop"
echo 'command params 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
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/
rm -rf ${serviceNameAbb}/
fi
mkdir -p ${serviceNameAbb}/dist
pid_file=$nginxPath"logs/nginx.pid"
unzip dist*.zip
cp -r dist/* ${serviceNameAbb}/dist
cp -r dist/static ${serviceNameAbb}/
if [ ! -e "$pid_file" ]; then
/usr/local/nginx/sbin/nginx
fi
#nohup ./node_modules/http-server/bin/http-server -p ${port} >/dev/null 2>&1 &
exit
if [ -e "$pid_file" ]; then
/usr/local/nginx/sbin/nginx -s reload
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
params1=$1
command=$(cat updowncommand.txt)
echo 'command:'$command
if [ -z "$1" ]; then
command='start'
if [ -z "$params1" ]; 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 [ "$params1" = "stop" ]; then
command="stop"
echo 'command params 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
cd ${deployPath}
if [ -e "$stopConf" ]; then
echo 'copy to start file'
mv $stopConf $startPath
fi
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
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
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论