-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgit_hook_post-receive
89 lines (69 loc) · 2.43 KB
/
git_hook_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
86
87
88
89
#!/bin/bash
# This file is a copy of production file .git/hooks/post-receive
# Used to deploy on `git push production`
set -e
export PORT=80
export AMBER_ENV=production
if [ "$GIT_DIR" = "." ]; then
# The script has been called as a hook; chdir to the working copy
cd ..
unset GIT_DIR
fi
# try to obtain the usual system PATH
if [ -f /etc/profile ]; then
PATH=$(source /etc/profile; echo $PATH)
export PATH
fi
# get the current branch
head="$(git symbolic-ref HEAD)"
# read the STDIN to detect if this push changed the current branch
while read oldrev newrev refname
do
[ "$refname" = "$head" ] && break
done
# abort if there's no update, or in case the branch is deleted
if [ -z "${newrev//0}" ]; then
exit
fi
# check out the latest code into the working copy
umask 002
git reset --hard
logfile=log/deploy.log
if [ -z "${oldrev//0}" ]; then
# this is the first push; this branch was just created
mkdir -p log tmp bin
chmod 0775 log tmp bin
touch $logfile
chmod 0664 $logfile
# init submodules
git submodule update --recursive --init 2>&1 | tee -a $logfile
else
# log timestamp
echo ==== $(date) ==== >> $logfile
################################################################################
#### BEGIN: Amberframework specific Code #####
################################################################################
shards install
if [ -f bin/amber ]; then
echo "amber already installed"
else
crystal build lib/amber/src/amber/cli.cr -o bin/amber --stats
fi
echo "Migrating..."
./bin/amber db create migrate || true
echo "Building application in release mode"
crystal build src/amberframework.cr -o bin/amberframework --release --stats
systemctl status amberframework
sudo systemctl restart amberframework
systemctl status amberframework
## Code below is NOT required, now we're using an amberframework.sevice at /etc/systemd/system
#old_pid=`cat tmp/amberframework.pid`
#echo "Killing old process..."
#kill -9 $old_pid || true # Move after start line if PORT_REUSE is on.
#echo "Starting application..."
#nohup ./bin/amberframework >> log/production.log 2>&1 &
#echo $! > tmp/amberframework.pid
################################################################################
#### END: Amberframework specific Code #####
################################################################################
fi