Skip to content

Instantly share code, notes, and snippets.

@pbredenberg
Last active January 30, 2020 17:25
Show Gist options
  • Save pbredenberg/238aa9b4f7da66e19d27339f1cd4ae98 to your computer and use it in GitHub Desktop.
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.
#!/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