cron: Add script to update production web site checkout.
This commit is contained in:
parent
7e8d0538aa
commit
e1d4fdfaba
2 changed files with 53 additions and 0 deletions
1
cron/cron.d/website-update
Normal file
1
cron/cron.d/website-update
Normal file
|
@ -0,0 +1 @@
|
||||||
|
*/5 * * * * www $HOME/website/cron/scripts/website-update.sh
|
52
cron/scripts/website-update.sh
Executable file
52
cron/scripts/website-update.sh
Executable file
|
@ -0,0 +1,52 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
LOCKDIR="/tmp/website-update.$(id -u)"
|
||||||
|
SITEDIR=~/website
|
||||||
|
PRODUCTION_BRANCH=master
|
||||||
|
DB_FILE=~/Database/conservancy-website.sqlite3
|
||||||
|
DB_SCRIPT=~bkuhn/django-supporters-list.sql
|
||||||
|
|
||||||
|
git_rev_name() {
|
||||||
|
git rev-parse --abbrev-ref --symbolic-full-name "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! mkdir "$LOCKDIR"; then
|
||||||
|
test -d "$LOCKDIR"
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
trap 'rmdir "$LOCKDIR"' 0 INT TERM QUIT
|
||||||
|
|
||||||
|
exitcode=0
|
||||||
|
if [ "$DB_SCRIPT" -nt "$DB_FILE" ]; then
|
||||||
|
sqlite3 "$DB_FILE" <"$DB_SCRIPT" || exitcode=$?
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If the checkout is not on the production branch,
|
||||||
|
# assume maintenance is happening and stop.
|
||||||
|
cd "$SITEDIR"
|
||||||
|
if [ "$(git_rev_name HEAD)" != "$PRODUCTION_BRANCH" ]; then
|
||||||
|
exit "$exitcode"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Abort if the production branch isn't tracking a remote branch.
|
||||||
|
if ! git_upstream="$(git_rev_name '@{upstream}' 2>/dev/null)"; then
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
IFS=/ read git_remote git_refspec <<EOF
|
||||||
|
$git_upstream
|
||||||
|
EOF
|
||||||
|
git fetch --quiet --no-tags "$git_remote" "$git_refspec"
|
||||||
|
if [ "$(git rev-parse "$PRODUCTION_BRANCH")" = "$(git rev-parse "$git_upstream")" ]; then
|
||||||
|
exit "$exitcode"
|
||||||
|
fi
|
||||||
|
|
||||||
|
git merge --quiet --ff-only "$git_remote" "$git_refspec"
|
||||||
|
python2 -m compileall -q www || exitcode=$?
|
||||||
|
chgrp -R www-data www || exitcode=$?
|
||||||
|
chmod -R g+rX-w,o+X-w www || exitcode=$?
|
||||||
|
chmod -R o+r www/conservancy/static || exitcode=$?
|
||||||
|
exit "$exitcode"
|
Loading…
Reference in a new issue