#! /bin/bash

if [ ! -d "{{appPath}}" ]; then
  echo error: application path {{appPath}} does not exist;
  exit 1;
fi;

# check that the nginx sites-enabled directory exists
if [ ! -d "{{sitesEnabledPath}}" ]; then
  echo error: nginx sites-enabled path {{sitesEnabledPath}} does not exist;
  exit 1;
fi;

# stop any existing app instance
sudo stop {{appName}} > /dev/null;

# remove config files and app directory
sudo rm -f "{{nginxConfig}}";
sudo rm -f "{{upstartConfig}}";
sudo rm -rf "{{appPath}}";

# reload nginx config
sudo nginx -s reload > /dev/null;
