-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
deploy
executable file
·99 lines (84 loc) · 2.29 KB
/
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
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
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
. bin/lilarc
mode=$1
if [ -z $mode ]; then
echo "Empty deploy target"
exit 1
elif [ $mode = "main" ]; then
REMOTE="benko"
REMOTE_DIR="/home/lichess-deploy"
CLI="bin/cli-prod"
elif [ $mode = "stage" ]; then
REMOTE="khiaw"
REMOTE_DIR="/home/lichess-stage"
CLI="bin/cli-stage"
elif [ $mode = "local" ]; then
REMOTE="localhost"
REMOTE_DIR="/tmp/lila5"
CLI="bin/cli"
else
echo "Unknown deploy target $mode"
exit 1
fi
lilalog "Deploy to $mode server $REMOTE:$REMOTE_DIR"
if [ "$2" == "asset" ]; then
bin/prod/compile-client
fi
lilalog "Notify users of pre deploy"
$CLI deploy pre
bin/dev ";stage;exit"
if [ $? != 0 ]; then
lilalog "Deploy canceled"
exit 1
fi
if [ $mode == "main" ]; then
lilalog "Backup production lichess dir"
BACKUP_DIR=/home/backup/lichess-$(date +%Y-%m-%d_%H-%M)
ssh $REMOTE "echo $BACKUP_DIR && cp -r $REMOTE_DIR $BACKUP_DIR && rm $BACKUP_DIR/RUNNING_PID && chown -R lichess:lichess $BACKUP_DIR"
fi
RSYNC_OPTIONS=" \
--archive \
--no-o --no-g \
--force \
--delete \
--progress \
--compress \
--checksum \
--verbose \
--exclude conf/application.conf \
--exclude RUNNING_PID \
--exclude '*.psd' \
--exclude '.git/' \
--exclude bin/.translate_version"
if [ $mode != "main" ] && [ $mode != "stage" ]; then
RSYNC_OPTIONS="$RSYNC_OPTIONS \
--exclude public";
fi
lilalog "Rsync scripts, binaries and assets"
stage="target/universal/stage"
include="bin $stage/bin $stage/lib public submodules"
rsync_command="rsync $RSYNC_OPTIONS $include $REMOTE:$REMOTE_DIR"
echo "$rsync_command"
$rsync_command
echo "rsync complete"
if [ $mode == "main" ]; then
lilalog "Deploy logger configuration"
rsync -av conf/prod-logger.xml $REMOTE:/etc/lichess.logger.xml
fi
read -n 1 -p "Press [Enter] to complete deployment to $mode server $REMOTE:$REMOTE_DIR"
lilalog "Notify users of post deploy"
$CLI deploy post
if [ $mode == "main" ]; then
lilalog "Restart lichess"
RUN_DIR="/home/lichess"
ssh $REMOTE "chown -R lichess:lichess $REMOTE_DIR && rm $RUN_DIR && ln -s $REMOTE_DIR $RUN_DIR && service lichess restart"
fi
if [ $mode == "stage" ]; then
lilalog "Restart lichess-stage"
ssh $REMOTE "chown -R lichess:lichess $REMOTE_DIR && service lichess-stage restart"
fi
lilalog "Deploy complete"
if [ $mode != "local" ]; then
sleep 2
curl_prod
fi