Last active
January 30, 2020 17:25
-
-
Save pbredenberg/238aa9b4f7da66e19d27339f1cd4ae98 to your computer and use it in GitHub Desktop.
Script to restart/re-deploy a pm2-managed node.js application remotely over ssh via non-interactive shell.
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 | |
# Put this in your deployment user's home directory. Make sure nvm is installed for that user. | |
# Execute this file from the directory where the pm2 app package.json resides. | |
# Example: ssh user@server "cd /path/to/app/root && /home/user/deploy_pm2_app.sh pm2_app_name" | |
NVM_DIR=/home/username/.nvm | |
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm | |
## Run whatever you need to do to prepare for restart: | |
## git fetch && git rebase | |
## npm ci | |
if [ -z "$1" ]; then | |
echo "Please supply a pm2 app name."; | |
else | |
pm2 restart $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment