Generic deployment script using git & node.js (forever) on a *NIX machine

I created a very basic, but working shell script that deploys a node.js web application on your *NIX server. It assumes you have an init.d script set up to start and stop your application.

Note: while this script will sudo into another user of your choosing (to do the git stuff and building) it expects to be run as root in order to access init.d to start/stop the server.

You’ll have to edit the BASE_DIR, SERVER_ROOT, and DO variables at the top. The BASE_DIR is your .git and package.json reside. The SERVER_ROOT is where your application is hosted; we’re going to assume that this URL will give back an angular app (at the bottom) as part of the smoke test. You’ll also need to change APP_INIT_SCRIPT to your application’s init script name. This script will:

  1. Stop the server
  2. Smoke check to ensure it’s really down
  3. Enter base dir and reset it (git reset --hard)
  4. Ensure that no files exist that need to still be changed (git status should return ‘nothing to commit’)
  5. git pull the latest code
  6. Gulp clean & build (via gulp prod)
  7. Start the server
  8. Do a smoke test to ensure it is running (expects ng-app in the response)

Without further ado, here’s the code:


Leave a Reply

Your email address will not be published.