-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode-deploy
50 lines (37 loc) · 1.37 KB
/
node-deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
# Generic simple deployment script for checking out Node app project files
# from a bare Git rep. The Node app to work with is defined by the APP_NAME
# environment variable set in the post-receive hook. This script runs as root.
echo "Deploying $APP_NAME ..."
# Export environment variables for deployment operation.
# These will be picked up in the sub process invoked by
# git checkout later on.
export GIT_DIR=/home/git/repositories/"$APP_NAME".git
APP_DIR=/var/node/"$APP_NAME"
export GIT_WORK_TREE="$APP_DIR"/app
echo "Using Git repo $GIT_DIR"
echo "Using Node app folder $GIT_WORK_TREE"
# Check that by concatenating strings with the value
# of APP_NAME we've created a valid repo location.
if [ ! -d "$GIT_DIR" ]; then
echo "Error, Git repo not found"
exit 1
fi
# Node apps will live in /var/node/app-name/app so create
# if it doesn't exist.
if [ ! -d "$GIT_WORK_TREE" ]; then
echo "Warning, Node app folder not found ... creating"
mkdir -p "$GIT_WORK_TREE"
fi
# Sync the app location with the latest files in the
# repo via git checkout. Also change ownership of all the
# app files to the node user (we're currently root).
echo "Moving app files to $GIT_WORK_TREE" ...
unset GIT_INDEX_FILE
git checkout -f
chown -R node:node "$APP_DIR"
echo "Restarting via Monit ..."
sleep 1
monit restart "$APP_NAME"
echo "Deployment complete!"
exit 0