summaryrefslogtreecommitdiff
path: root/run.sh
diff options
context:
space:
mode:
Diffstat (limited to 'run.sh')
-rwxr-xr-xrun.sh51
1 files changed, 51 insertions, 0 deletions
diff --git a/run.sh b/run.sh
new file mode 100755
index 0000000..32ad77f
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,51 @@
1#!/bin/bash
2
3export PYTHONPATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
4
5source $(dirname "$PYTHONPATH")/venv/bin/activate
6
7WORKERS=2
8BACKUP_KEY="$HOME/.private/backupkey.pem"
9BIND_PATH="127.0.0.1:9000"
10[[ -z "$2" ]] || BIND_PATH="$2"
11
12MAX_KEEP=`python -c "import wikiconfig; print wikiconfig.Config.backup_set_keep" 2>/dev/null`
13S3_BUCKET=`python -c "import wikiconfig; print wikiconfig.Config.backup_s3_bucket" 2>/dev/null`
14
15APPLICATION="MoinMoin.wsgiapp:application"
16[[ -z "$DEBUG" ]] || APPLICATION="wsgi:application"
17
18if [[ "$1" == "serve" ]]; then
19 gunicorn --timeout=300 --preload -w $WORKERS -b $BIND_PATH $APPLICATION
20elif [[ "$1" == "cron" ]]; then
21 moin maint makecache
22elif [[ "$1" == "reindex" ]]; then
23 moin index build --mode=rebuild
24elif [[ "$1" == "backup" ]]; then
25 if [[ -z "$S3_BUCKET" || -z "$MAX_KEEP" || ! -r $BACKUP_KEY ]]; then
26 echo "Not properly configured"
27 exit 1
28 fi
29
30 FILENAME="$HOME/backup-`date +%Y%m%d%H%M%S`.bak"
31
32 # Backup first
33 #
34 # Place CACHEDIR.TAG files in cache directories to prevent backup.
35 # This is needed because thumbnail images in caches can cause lots of
36 # wasted backup space.
37 find "$HOME/wiki-data/" -type d -name 'cache' -exec bash -c 'echo "Signature: 8a477f597d28d172789f06886806bc55" > "{}/CACHEDIR.TAG"' \;
38
39 ( cd $HOME && tar -cj --exclude-caches wiki-data/ | openssl aes-256-cbc -pass "file:$BACKUP_KEY" > $FILENAME )
40 s3cmd put --no-progress $FILENAME $S3_BUCKET
41 rm $FILENAME
42
43 # Then prune the backup set to a maximum of N files
44 ALL_FILES=( $(s3cmd ls $S3_BUCKET | awk '{ print $4 }' | sort -nr) )
45
46 for (( i=$MAX_KEEP ; i < ${#ALL_FILES[@]}; i++ )); do
47 s3cmd del ${ALL_FILES[i]}
48 done
49else
50 moin $*
51fi