From 4426368369604224c971646eb334b212c69473f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Wed, 7 Oct 2015 16:13:31 +0200 Subject: Implemented the refresh-and-deploy shell script. --- scripts/deploy/codeq_refresh_and_deploy.sh | 99 ++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 scripts/deploy/codeq_refresh_and_deploy.sh (limited to 'scripts/deploy') diff --git a/scripts/deploy/codeq_refresh_and_deploy.sh b/scripts/deploy/codeq_refresh_and_deploy.sh new file mode 100755 index 0000000..46995ce --- /dev/null +++ b/scripts/deploy/codeq_refresh_and_deploy.sh @@ -0,0 +1,99 @@ +#!/bin/dash -e + +. /etc/default/codeq +export CODEQ_PROBLEMS CODEQ_WEB_OUTPUT CODEQ_DB_HOST CODEQ_DB_DATABASE CODEQ_DB_USER CODEQ_DB_PASS + +# flags to restart daemons at the end of the script +# 0 means not to restart, anything else means to restart +RESTART_PROLOG=0 +RESTART_SERVER=0 +RESTART_WEB=0 +BUILD_WEB_RESOURCES=0 + +init=$(cat /proc/1/comm) + +cd $CODEQ_SERVER +git fetch -q origin $CODEQ_GIT_BRANCH +git checkout -q $CODEQ_GIT_BRANCH +FILES=$(mktemp) +if git diff --name-status origin/$CODEQ_GIT_BRANCH | cut -c3- | grep -v \\.gitignore >$FILES; then + # some modifications happened + git merge -q + + if grep -q ^prolog/runner/ $FILES; then + RESTART_PROLOG=1 + fi + + if grep -q -v '^\(web\|prolog/runner\|scripts\)/' $FILES; then + RESTART_SERVER=1 + fi + + if grep -q ^web/ $FILES; then + RESTART_WEB=1 + fi + + if grep -q ^scripts/build_web_resources.py $FILES; then + BUILD_WEB_RESOURCES=1 + fi + + if grep -q ^web/ $FILES | grep -v ^web/main.js; then + # node dependencies may have changed, run installation + cd web && /usr/bin/npm install + fi +fi + +cd $CODEQ_PROBLEMS +git fetch -q origin $CODEQ_GIT_BRANCH +git checkout -q $CODEQ_GIT_BRANCH +if git diff --name-status origin/$CODEQ_GIT_BRANCH | cut -c3- | grep -v \\.gitignore >$FILES; then + git merge -q + BUILD_WEB_RESOURCES=1 + # restart the server if any other files than language files were modified + if grep -q -v '\(^\|/\)..\.py' $FILES; then + RESTART_SERVER=1 + fi +fi + +cd $CODEQ_WEB +git fetch -q origin $CODEQ_GIT_BRANCH +git checkout -q $CODEQ_GIT_BRANCH +if git diff --name-status origin/$CODEQ_GIT_BRANCH | cut -c3- | grep -v \\.gitignore >$FILES; then + git merge -q + echo Redeploying web app + /usr/bin/rsync -aq --delete -f '- .git' -f '- .gitignore' -f '- config.xml' -f 'P data' /var/local/codeq-web/ /var/www/html +fi + +rm -f $FILES + +# as a precaution switch to the tmp folder +cd /tmp +if [ $BUILD_WEB_RESOURCES -ne 0 ]; then + echo Rebuilding web resources + /usr/bin/python3 $CODEQ_SERVER/scripts/build_web_resources.py +fi +if [ $RESTART_PROLOG -ne 0 ]; then + echo Restarting codeq-prolog + if [ "$init" == systemd ]; then + systemctl restart codeq-prolog + else + /etc/init.d/codeq-prolog restart + fi +fi +if [ $RESTART_SERVER -ne 0 ]; then + echo Restarting codeq-server + if [ "$init" == systemd ]; then + systemctl restart codeq-server + else + /etc/init.d/codeq-server restart + fi +fi +if [ $RESTART_WEB -ne 0 ]; then + echo Restarting codeq-web + if [ "$init" == systemd ]; then + systemctl restart codeq-web + else + /etc/init.d/codeq-web restart + fi +fi + +exit 0 -- cgit v1.2.1