Last active
February 23, 2023 12:40
-
-
Save vipulwairagade/26a18b22720091a31834bc0e871a52ba to your computer and use it in GitHub Desktop.
post-receive hook for node.js app on vps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
PROJECT_REPO="/home/ubuntu/<project-folder-name>/<project-name>/deploy.git" | |
WORKING_DIR="/home/ubuntu/<project-folder-name>/<project-name>/workingdir" | |
while read oldrev newrev ref | |
do | |
echo "Ref $ref received. Deploying $newrev ..." | |
git --work-tree=${WORKING_DIR} --git-dir=${PROJECT_REPO} checkout -f $newrev | |
done | |
# | |
# NodeJS hook additions | |
# | |
NODE_APP_NAME="<project-name>" | |
cd ${WORKING_DIR}; npm ci --ignore-scripts; npm run migrate:up; | |
if [[ "$(pm2 id "${NODE_APP_NAME}")" = "[]" ]]; then | |
pm2 start npm --name "${NODE_APP_NAME}" -- start | |
else | |
pm2 restart "${NODE_APP_NAME}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment