-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-receive
85 lines (60 loc) · 2.44 KB
/
post-receive
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
echo "Initializing deployment of your site from repo...."
git checkout -f
echo "Initialization has completed beensuccessfully"
echo "-------> Deployment has started..."
# Checkout the real 'master' so we can view the repo files
SERVICE='foreman'
WORKING_DIR=`exec git config --get core.worktree`
REPO_PRE_DEPLOY_SCRIPT="$WORKING_DIR"/mungo_pre_deploy
REPO_POST_DEPLOY_SCRIPT="$WORKING_DIR"/mungo_post_deploy
REPO_PROCFILE="$WORKING_DIR"/Procfile
chmod -Rf 0755 $REPO_PROCFILE
chmod -Rf 0755 $REPO_POST_DEPLOY_SCRIPT
chmod -Rf 0755 $REPO_PRE_DEPLOY_SCRIPT
chmod -Rf 0777 $WORKING_DIR
cd $WORKING_DIR
function start_app() {
# If the repository has a file called 'Procfile' then run it by foreman
if [ -x "$REPO_PROCFILE" ]; then
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
FOREMAN_ID=`ps aux | grep foreman | grep -v grep | awk '{print $2}'`
echo "$SERVICE service already running, with process id $FOREMAN_ID..Trying to kill it.."
kill $FOREMAN_ID
nohup foreman start > /dev/null 2>&1 &
FOREMAN_ID=`ps aux | grep foreman | grep -v grep | awk '{print $2}'`
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE service restarted with process id $FOREMAN_ID"
else
echo "Unable to start $SERVICE"
fi
else
FOREMAN_ID=`ps aux | grep foreman | grep -v grep | awk '{print $2}'`
echo "$SERVICE is not running"
echo "$SERVICE trying to start foreman"
nohup foreman start > /dev/null 2>&1 &
FOREMAN_ID=`ps aux | grep foreman | grep -v grep | awk '{print $2}'`
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE service running with process id $FOREMAN_ID"
else
echo "Unable to start $SERVICE"
fi
fi
# If the repository has a file called 'mungo_deploy' then run it
if [ -x "$REPO_POST_DEPLOY_SCRIPT" ]; then
exec "$REPO_POST_DEPLOY_SCRIPT"
echo "Your mungo_post_deploy has been found and has been executed"
fi
fi
}
if [ -x "$REPO_PRE_DEPLOY_SCRIPT" ]; then
source "$REPO_PRE_DEPLOY_SCRIPT"
echo "Your mungo_pre_deploy has been found and has been executed"
start_app
else
start_app
fi
echo "-------> Deployment has completed"