-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy2.sh
88 lines (75 loc) · 1.8 KB
/
deploy2.sh
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
#!/bin/bash
# this script is executed on the webserver
# there's a bunch of sleep commands to guard things that don't necessarily
# complete in realtime; should evaluate if they're actually necessary
# and if they are how small we can make them
##########
# set up correct version of python/pip
##########
echo "Initializing deployment"
export VIRTUAL_ENV_DISABLE_PROMPT=1
source /home/werewolf/virtualenv/paste/3.11/bin/activate
SOURCEPATH=/home/werewolf/repositories/paste
DESTPATH=/home/werewolf/paste
BAKPATH=/home/werewolf/paste.bak
##########
# make a backup
##########
echo "Creating backup"
rm -rf $BAKPATH
mv $DESTPATH $BAKPATH
##########
# ensure dependencies are up to date
##########
echo "Ensuring updated dependencies"
cd $SOURCEPATH
pip install --upgrade -r requirements.txt
##########
# copy files
##########
echo "Copying files"
mkdir $DESTPATH
mkdir $DESTPATH/tmp
cp -r . $DESTPATH
cp $BAKPATH/config.py $DESTPATH/config.py
##########
# cleanup unnecessary files
##########
rm -rf $DESTPATH/.git
rm -rf $DESTPATH/.github
rm -f $DESTPATH/.gitignore
rm -f $DESTPATH/.cpanel.yml
rm -f $DESTPATH/deploy*
##########
# restart app
##########
echo "Restarting webapp"
touch $DESTPATH/tmp/restart.txt
sleep 5
##########
# test if app runs successfully
##########
SUCCESS=0
curl -f https://ww.chat > /dev/null
if [ $? -ne 0 ]; then
SUCCESS=1
fi
sleep 5
if [ -s $DESTPATH/stderr.log ]; then
SUCCESS=1
fi
##########
# restore backup if app didn't run successfully
##########
if [ $SUCCESS -eq 1 ]; then
echo "Webapp failed, restoring backup. Below is what was found in the log:"
cat $DESTPATH/stderr.log
rm -rf $DESTPATH
mv $BAKPATH $DESTPATH
touch $DESTPATH/tmp/restart.txt
sleep 5
curl -f https://ww.chat > /dev/null
echo "Backup restored"
fi
echo "Deployment complete"
exit $SUCCESS