| 1 |
#!/usr/bin/env bash |
| 2 |
# Copyright 2023 The Archivista Contributors |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
|
| 16 |
set -e |
| 17 |
|
| 18 |
DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" |
| 19 |
|
| 20 |
checkprograms() { |
| 21 |
local result=0 |
| 22 |
for prog in "$@" |
| 23 |
do |
| 24 |
if ! command -v "$prog" > /dev/null; then |
| 25 |
print "$prog is required to run this script. please ensure it is installed and in your PATH\n" |
| 26 |
result=1 |
| 27 |
fi |
| 28 |
done |
| 29 |
|
| 30 |
return $result |
| 31 |
} |
| 32 |
|
| 33 |
waitForArchivista() { |
| 34 |
echo "Waiting for archivista to be ready..." |
| 35 |
for attempt in $(seq 1 6); do |
| 36 |
sleep 10 |
| 37 |
local archivistastate |
| 38 |
archivistastate=$(docker compose -f "$DIR/../compose.yml" ps archivista --format json | jq -r '.State') |
| 39 |
if [ "$archivistastate" == "running" ]; then |
| 40 |
break |
| 41 |
fi |
| 42 |
|
| 43 |
if [[ attempt -eq 6 ]]; then |
| 44 |
echo "timed out waiting for archivista" |
| 45 |
docker compose logs |
| 46 |
exit 1 |
| 47 |
fi |
| 48 |
done |
| 49 |
} |
| 50 |
|
| 51 |
if ! checkprograms docker jq ; then |
| 52 |
exit 1 |
| 53 |
fi |
| 54 |
|
| 55 |
startMySQL() { |
| 56 |
echo "Test mysql..." |
| 57 |
docker compose -f "$DIR/../compose.yml" up --build -d |
| 58 |
waitForArchivista |
| 59 |
} |
| 60 |
|
| 61 |
startPgSQL(){ |
| 62 |
echo "Test psql..." |
| 63 |
docker compose -f "$DIR/../compose.yml" -f "$DIR/../compose-psql.yml" up --build -d |
| 64 |
waitForArchivista |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
stopServices() { |
| 69 |
docker compose -f "$DIR/../compose.yml" -f "$DIR/../compose-psql.yml" down -v |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
case $1 in |
| 74 |
start-mysql) |
| 75 |
startMySQL |
| 76 |
waitForArchivista |
| 77 |
;; |
| 78 |
|
| 79 |
start-pgsql) |
| 80 |
startPgSQL |
| 81 |
waitForArchivista |
| 82 |
;; |
| 83 |
|
| 84 |
stop) |
| 85 |
stopServices |
| 86 |
;; |
| 87 |
|
| 88 |
*) |
| 89 |
echo "Wrong option. Use $0 start-mysql|start-pgsql|stop" |
| 90 |
;; |
| 91 |
esac |