changeset 1586:d0d59d12db94 dockerise

Add some cron scripts, update
author Chris Cannam
date Wed, 16 Aug 2017 16:58:22 +0100
parents 37d4559a9fce
children d8949733849d
files extra/soundsoftware/scripted-deploy/config/cron.daily/00-backup-db extra/soundsoftware/scripted-deploy/config/cron.daily/10-extract-docs extra/soundsoftware/scripted-deploy/config/cron.daily/15-get-statistics extra/soundsoftware/scripted-deploy/config/cron.daily/20-check-end-of-external-repo-log extra/soundsoftware/scripted-deploy/config/cron.hourly/00-drupal-cron extra/soundsoftware/scripted-deploy/config/cron.hourly/10-redmine-fetch-changesets extra/soundsoftware/scripted-deploy/config/cron.hourly/20-convert-external-repos extra/soundsoftware/scripted-deploy/config/cron.hourly/30-expire-explore-cache extra/soundsoftware/scripted-deploy/config/cron.hourly/40-export-git extra/soundsoftware/scripted-deploy/config/cron.minutely/00-redmine-repositories extra/soundsoftware/scripted-deploy/config/cron.monthly/00-backup-files extra/soundsoftware/scripted-deploy/config/logrotate.conf extra/soundsoftware/scripted-deploy/docker/start.sh extra/soundsoftware/scripted-deploy/vagrant/start.sh extra/soundsoftware/scripted-deploy/vagrant/vagrant-provision.sh public/themes/soundsoftware/stylesheets/fonts/.keep
diffstat 15 files changed, 139 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.daily/00-backup-db	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,6 @@
+#!/bin/sh
+outfile="/var/files/backups/postgres-dumpall-`date +%Y%m%d%H%M`"
+oldmask=`umask`
+umask 0277
+su postgres -c /usr/bin/pg_dumpall > "$outfile" && bzip2 "$outfile"
+umask "$oldmask"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.daily/10-extract-docs	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,3 @@
+#!/bin/bash
+cd /tmp
+/var/www/code/docgen/extract-docs.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.daily/15-get-statistics	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,2 @@
+#!/bin/bash
+sudo -u code sh -c "cd /var/www/code ; ./script/rails runner -e production extra/soundsoftware/get-statistics.rb >> log/statistics.log"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.daily/20-check-end-of-external-repo-log	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,2 @@
+#!/bin/bash
+tail -2 /var/log/external-repos.log
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.hourly/00-drupal-cron	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,3 @@
+#!/bin/bash
+/usr/bin/wget -O - -q -t 1 http://www.soundsoftware.ac.uk/cron.php
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.hourly/10-redmine-fetch-changesets	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,3 @@
+#!/bin/bash
+sudo -u code sh -c "cd /var/www/code ; ./script/rails runner \"Repository.fetch_changesets\" -e production 2>&1 | grep -v 'Not trusting' | grep -v 'svn:' | grep -v 'working copy' | grep -v 'deprecated' | grep -v 'version_requirements'"
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.hourly/20-convert-external-repos	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,2 @@
+#!/bin/bash
+sudo -H -u www-data /var/www/code/reposman/run-external.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.hourly/30-expire-explore-cache	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,2 @@
+#!/bin/sh
+rm -f /var/www/code/tmp/cache/*/*/views*explore*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.hourly/40-export-git	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,3 @@
+#!/bin/bash
+logfile="/var/www/code/log/export-git.log"
+sudo -u code sh -c "cd /tmp ; /var/www/code/extra/soundsoftware/export-git.sh production /var/hg /var/files/git-mirror >> $logfile 2>&1"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.minutely/00-redmine-repositories	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,3 @@
+#!/bin/bash
+sudo -u www-data /var/www/code/reposman/run-reposman.sh
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/cron.monthly/00-backup-files	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,10 @@
+#!/bin/sh
+for location in var/www etc/apache2 etc/cron.*; do
+	target="/var/files/backups/`echo $location | sed 's,/,_,g'`-`date +%Y%m%d%H%M`"
+	oldmask=`umask`
+	umask 0277
+	cd /
+	tar cjf "$target".tar.bz2 "$location"
+	umask "$oldmask"
+done
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/scripted-deploy/config/logrotate.conf	Wed Aug 16 16:58:22 2017 +0100
@@ -0,0 +1,65 @@
+# see "man logrotate" for details
+# rotate log files weekly
+weekly
+
+# keep 4 weeks worth of backlogs
+rotate 4
+
+# create new (empty) log files after rotating old ones
+create
+
+# uncomment this if you want your log files compressed
+#compress
+
+# packages drop log rotation information into this directory
+include /etc/logrotate.d
+
+# no packages own wtmp, or btmp -- we'll rotate them here
+/var/log/wtmp {
+    missingok
+    monthly
+    create 0664 root utmp
+    rotate 1
+}
+
+/var/log/btmp {
+    missingok
+    monthly
+    create 0660 root utmp
+    rotate 1
+}
+
+# system-specific logs may be configured here
+/var/www/code/log/*.log {
+	weekly
+	missingok
+	rotate 52
+	compress
+	delaycompress
+	create 640 code code
+	sharedscripts
+	postrotate
+		touch /var/www/code/restart_files/restart.txt
+	endscript
+}
+
+/var/log/reposman.log {
+        weekly
+        missingok
+        rotate 52
+        compress
+        delaycompress
+        create 640 www-data code
+        sharedscripts
+}
+
+/var/log/external-repos.log {
+        weekly
+        missingok
+        rotate 52
+        compress
+        delaycompress
+        create 640 www-data code
+        sharedscripts
+}
+
--- a/extra/soundsoftware/scripted-deploy/docker/start.sh	Wed Aug 16 16:58:04 2017 +0100
+++ b/extra/soundsoftware/scripted-deploy/docker/start.sh	Wed Aug 16 16:58:22 2017 +0100
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+mydir=$(dirname "$0")
+
 dbpwd="$1"
 if [ -z "$dbpwd" ]; then
     echo "Usage: $0 <database-password>" 1>&2
@@ -8,9 +10,12 @@
 
 set -eu
 
-deploydir=./extra/soundsoftware/scripted-deploy
+sswdir="$mydir/../.."
+rootdir="$sswdir/../.."
+
+deploydir="$sswdir"/scripted-deploy
 if [ ! -d "$deploydir" ]; then
-    echo "Run this script from the root of a working copy of soundsoftware-site"
+    echo "ERROR: Unexpected repository layout - expected directory at $deploydir"
     exit 2
 fi
 
@@ -26,8 +31,14 @@
     exit 2
 fi
 
-if [ ! -f "postgres-dumpall" ]; then
-    echo "ERROR: I expect to find a Postgres SQL multi-db dump file in ./postgres-dumpall"
+if [ ! -f "$rootdir/postgres-dumpall" ]; then
+    echo "ERROR: I expect to find a Postgres SQL multi-db dump file in $rootdir/postgres-dumpall"
+    exit 2
+fi
+
+fontdir="$rootdir"/public/themes/soundsoftware/stylesheets/fonts
+if [ ! -f "$fontdir/24BC0E_0_0.woff" ]; then
+    echo "ERROR: I expect to find necessary webfonts in $fontdir"
     exit 2
 fi
 
@@ -37,6 +48,8 @@
             "$configdir/$f.interpolated"
 done
 
+cd "$rootdir"
+
 dockertag="cannam/soundsoftware-site"
 
 sudo docker build -t "$dockertag" -f "$managerdir/Dockerfile" .
--- a/extra/soundsoftware/scripted-deploy/vagrant/start.sh	Wed Aug 16 16:58:04 2017 +0100
+++ b/extra/soundsoftware/scripted-deploy/vagrant/start.sh	Wed Aug 16 16:58:22 2017 +0100
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+mydir=$(dirname "$0")
+
 dbpwd="$1"
 if [ -z "$dbpwd" ]; then
     echo "Usage: $0 <database-password>" 1>&2
@@ -8,9 +10,12 @@
 
 set -eu
 
-deploydir=./extra/soundsoftware/scripted-deploy
+sswdir="$mydir/../.."
+rootdir="$sswdir/../.."
+
+deploydir="$sswdir"/scripted-deploy
 if [ ! -d "$deploydir" ]; then
-    echo "Run this script from the root of a working copy of soundsoftware-site"
+    echo "ERROR: Unexpected repository layout - expected directory at $deploydir"
     exit 2
 fi
 
@@ -26,8 +31,14 @@
     exit 2
 fi
 
-if [ ! -f "postgres-dumpall" ]; then
-    echo "ERROR: I expect to find a Postgres SQL multi-db dump file in ./postgres-dumpall"
+if [ ! -f "$rootdir/postgres-dumpall" ]; then
+    echo "ERROR: I expect to find a Postgres SQL multi-db dump file in $rootdir/postgres-dumpall"
+    exit 2
+fi
+
+fontdir="$rootdir"/public/themes/soundsoftware/stylesheets/fonts
+if [ ! -f "$fontdir/24BC0E_0_0.woff" ]; then
+    echo "ERROR: I expect to find necessary webfonts in $fontdir"
     exit 2
 fi
 
--- a/extra/soundsoftware/scripted-deploy/vagrant/vagrant-provision.sh	Wed Aug 16 16:58:04 2017 +0100
+++ b/extra/soundsoftware/scripted-deploy/vagrant/vagrant-provision.sh	Wed Aug 16 16:58:22 2017 +0100
@@ -4,6 +4,9 @@
 # * cron jobs
 # * https
 # * web fonts
+# * reposman scripts (and their API key setup, etc)
+# * docgen script install
+# * logrotate config (check against system one)
 
 set -e