lila/bin/prod/deploy

125 lines
3.1 KiB
Bash
Executable File

#!/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 = "koala" ]; then
REMOTE="koala"
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"
echo "##################################################"
echo "# #"
echo "# * Deploy and restart * #"
echo "# #"
echo "##################################################"
read -p "Press enter to continue"
if [ "$2" = "asset" ]; then
bin/prod/compile-client
fi
if [ $mode = "main" ]; then
lilalog "Notify users of pre deploy"
$CLI deploy pre
fi
SBT_OPTS=""
export JAVA_OPTS="-Xms1024M -Xmx1024M -XX:ReservedCodeCacheSize=64m -XX:+UseConcMarkSweepGC"
sbt 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 '*.h' \
--exclude '*.cpp' \
--exclude '.git/' \
--exclude bin/.translate_version
--exclude bin/node_modules"
if [ $mode != "main" ] && [ $mode != "stage" ] && [ $mode != "koala" ]; 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"
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"
if [ $mode = "main" ]; then
lilalog "Notify users of post deploy"
$CLI deploy post
fi
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
if [ $mode = "koala" ]; 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