annotate scripts/training.sh @ 191:fea886ba7279

DEP-12: add source for .functions.sh to all scripts using compose
author smith@nwoca.org
date Wed, 20 Sep 2017 17:56:23 +0100
parents e155908fa039
children
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)
47
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
8
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
9 prefix=${3:+$3-}
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
10
47
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
11 mkdir -p $BASEDIR/${prefix}training-00/config
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
12
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
13 if [ ! -f $BASEDIR/${prefix}training-00/config/application.properties ]; then
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
14 echo "application.admin.password=training" > ${prefix}training-00/config/application.properties
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
15 echo "application.admin.reset=true" >> ${prefix}training-00/config/application.properties
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
16 echo "cache.config.file=ehcache-compact.xml" >> ${prefix}training-00/config/application.properties
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
17 fi
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
18
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
19 for i in $(eval echo {01..${2:-10}}); do
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
20 mkdir -p $BASEDIR/${prefix}training-$i
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
21 done
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
22
47
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
23 for t in $( ls -d *training-* ); do
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
24 if [ ! $t == "${prefix}training-00" ]; then
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
25
47
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
26 echo $t
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
27
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
28 mkdir -p ${BASEDIR}/$t/config
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
29 cp ${BASEDIR}/${prefix}training-00/config/application.properties ${BASEDIR}/$t/config/application.properties
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
30
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
31 sed "s/${prefix}training-00/$t/g" ${prefix}training-00/docker-compose.yml > $t/docker-compose.yml
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
32 if [ -f $BASEDIR/${prefix}training-00/docker-compose.override.yml ]; then
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
33 sed "s/${prefix}training-00/$t/g" ${prefix}training-00/docker-compose.override.yml > $t/docker-compose.override.yml
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
34 fi
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
35
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
36 fi
47
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
37 done
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
38 ;;
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
39
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
40 compose)
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
41
46
dfbb643b82a3 tee import logs to a file
smith@nwoca.org
parents: 40
diff changeset
42 for t in $( ls -d *training-* ); do
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
43 cd $BASEDIR/$t
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
44 docker-compose ${*:2}
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
45 done
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
46 ;;
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
47
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
48 reset)
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
49
46
dfbb643b82a3 tee import logs to a file
smith@nwoca.org
parents: 40
diff changeset
50 for t in $( ls -d *training-* ); do
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
51 cd $BASEDIR/$t
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
52
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
53 docker-compose stop
65
e155908fa039 improve import and training scripts. include all containers in info
smith@nwoca.org
parents: 47
diff changeset
54 docker-compose rm -f usasdb uspsdb usasapp uspsapp
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
55 docker-compose up -d usasdb uspsdb
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
56 sleep 30 # delay to allow database startup and restore
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
57 docker-compose up -d
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
58 sleep 60 # delay to prevent overwhelming host
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 done
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
61 ;;
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
62
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
63
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
64 *)
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
65 echo "usage:"
47
a0283d218ff5 handle training instances with prefix in directory name. use docker-compose.yml as template instead of linking. set application property to reduce memory requirements
smith@nwoca.org
parents: 46
diff changeset
66 echo " create [n:-10] [prefix] creates training-nn configs based on training-00 directory"
40
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
67 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
68 echo " reset resets training database on each training instance"
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
69 ;;
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
70 esac
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
71 echo "done"
ef52df9248de add training setup helper script
Dave smith <smith@nwoca.org>
parents:
diff changeset
72 cd $BASEDIR