环境脚本记录

1
2
3
4
5
6
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add
apt update
apt install -y nodejs
apt install -y yarn

supervisor配置

1
2
3
4
5
[program:{yarn_app}]
directory = /{yarn_run_path}/{yarn_app}
command = yarn start
autorestart = true
startretries = 60

自动部署脚本记录

{build_host} 编译脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18

cd /{yarn_build_path}/{yarn_app}/
git checkout .
git pull
yarn -i
yarn build -y
cd /{yarn_build_path}/

tar -czf {yarn_app}.tar.gz {yarn_app}

scp {yarn_app}.tar.gz  root@{run_host_1}:/{yarn_build_path}/{yarn_app}/
ssh root@{run_host_1} "bash /{yarn_build_path}/{yarn_app}/update.sh"

scp {yarn_app}.tar.gz  root@{run_host_2}:/{yarn_build_path}/{yarn_app}/
ssh root@{run_host_2} "bash /{yarn_build_path}/{yarn_app}/update.sh"

rm -f {yarn_app}.tar.gz

{run_host_x} 重启脚本 /{yarn_run_path}/{yarn_app}/update.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

cd /{yarn_run_path}/{yarn_app}/
tar -xzf {yarn_app}.tar.gz
supervisorctl stop {yarn_app}
kill -9 `lsof -ti:{run_port}`
rm -rf bak_*
mv last bak_`(date +%Y_%m_%d_%H_%M_%S)`
mv {yarn_app} last
supervisorctl start {yarn_app}
rm -f {yarn_app}.tar.gz

Jenkins shell

1
2
ssh -i /{key_file_path} {ssh_user}@{build_host} "sudo su -c /{yarn_build_path}/build_{yarn_app}.sh - {build_user}"