annotate scripts/training.sh @ 46:dfbb643b82a3

tee import logs to a file
author smith@nwoca.org
date Tue, 02 Feb 2016 21:24:28 +0000
parents ef52df9248de
children a0283d218ff5
rev   line source
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
1 #!/bin/bash
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
2
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
3 BASEDIR=$PWD
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
4
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
5 case "$1" in
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
6
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
7 create)
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
8
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
9 if [ ! -f $BASEDIR/training-00/docker-compose.override.yml ]; then
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
10 echo "no override file in training-00"
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
11 exit 0
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
12 fi
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
13 if [ ! -f $BASEDIR/training-00/config/application.properties ]; then
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
14 echo "application.admin.password=training" > training-00/config/application.properties
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
15 echo "application.admin.reset=true" >> training-00/config/application.properties
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
16 fi
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
17
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
18 for i in $(eval echo {01..${2:-10}}); do
46
dfbb643b82a3 tee import logs to a file
smith@nwoca.org
parents: 40
diff changeset
19 mkdir -p $BASEDIR/training-$i
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
20 done
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
21
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
22 for t in $( ls -d training-* ); do
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
23 if [ ! $t == "training-00" ]; then
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
24
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
25 echo $t
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
26 ln -sf ${BASEDIR}/training-00/docker-compose.yml ${BASEDIR}/$t/docker-compose.yml
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
27 mkdir -p ${BASEDIR}/$t/config
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
28 cp ${BASEDIR}/training-00/config/application.properties ${BASEDIR}/$t/config/application.properties
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
29 sed "s/training-00/$t/g" training-00/docker-compose.override.yml > $t/docker-compose.override.yml
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
30
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
31 fi
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
32 done
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
33
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
34 ;;
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
35
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
36 compose)
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
37
46
dfbb643b82a3 tee import logs to a file
smith@nwoca.org
parents: 40
diff changeset
38 for t in $( ls -d *training-* ); do
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
39 cd $BASEDIR/$t
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
40 docker-compose ${*:2}
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
41 done
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
42 ;;
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
43
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
44 reset)
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
45
46
dfbb643b82a3 tee import logs to a file
smith@nwoca.org
parents: 40
diff changeset
46 for t in $( ls -d *training-* ); do
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
47 cd $BASEDIR/$t
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
48
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
49 docker-compose stop
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
50 docker-compose rm -f usasdb uspsdb
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
51 docker-compose up -d usasdb uspsdb
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
52 sleep 30 # delay to allow database startup and restore
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
53 docker-compose up -d
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
54 sleep 60 # delay to prevent overwhelming host
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
55
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
56 done
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
57 ;;
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
58
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
59
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
60 *)
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
61 echo "usage:"
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
62 echo " create [n:-10] creates training-nn configs based on training-00 directory"
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
63 echo " compose {cmd} [args...] executes docker compose command on each training instance"
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
64 echo " reset resets training database on each training instance"
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
65 ;;
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
66 esac
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
67 echo "done"
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
68 cd $BASEDIR