Node.js 리눅스 배포 스크립트
리눅스에 Node.js 앱 배포를 자동화하는 스크립트
서버는 sudo npm i -g pm2 실행 후
[code language=”shell”]
# 맥에서
$ vim deploy.sh
#!/bin/bash
APP_NAME=’앱이름’
tar -czf $APP_NAME.tar.gz app.js package.json
scp -i ~/.ssh/rsa $APP\_NAME.tar.gz user@server\_address:~
rm $APP_NAME.tar.gz
ssh -i ~/.ssh/rsa user@server_address <<‘ENDSSH’
APP_NAME=’앱이름’
echo ‘stop’ $APP_NAME
pm2 stop $APP_NAME
echo ‘remove’ $APP_NAME
rm -rf $APP_NAME
mkdir $APP_NAME
tar -xf $APP\_NAME.tar.gz -C $APP\_NAME
rm $APP_NAME.tar.gz
cd $APP_NAME
npm install
pm2 start app.js –name $APP_NAME
ENDSSH
ESC, :wq, ENTER
$ chmod +x deploy.sh
$ ./deploy.sh
참고https://www.youtube.com/watch?v=AQClj-lLqRs