adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # ============LICENSE_START==================================================== |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 4 | # Copyright (C) 2023-2024 Nordix Foundation. |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 5 | # ============================================================================= |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ============LICENSE_END====================================================== |
| 20 | |
| 21 | echo "Shut down started!" |
| 22 | if [ -z "${WORKSPACE}" ]; then |
| 23 | WORKSPACE=$(git rev-parse --show-toplevel) |
| 24 | export WORKSPACE |
| 25 | fi |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 26 | |
adheli.tavares | d802fd9 | 2024-08-15 12:39:19 +0100 | [diff] [blame] | 27 | database=postgres |
adheli.tavares | 3612747 | 2024-07-02 11:51:35 +0100 | [diff] [blame] | 28 | |
adheli.tavares | d802fd9 | 2024-08-15 12:39:19 +0100 | [diff] [blame] | 29 | while [[ $# -gt 0 ]] |
| 30 | do |
| 31 | key="$1" |
| 32 | |
| 33 | case $key in |
| 34 | --mariadb) |
| 35 | database=mariadb |
| 36 | shift |
| 37 | ;; |
| 38 | --postgres) |
| 39 | database=postgres |
| 40 | shift |
| 41 | ;; |
| 42 | *) |
| 43 | component="$1" |
| 44 | shift |
| 45 | ;; |
| 46 | esac |
| 47 | done |
| 48 | |
| 49 | if [ -z "$component" ]; then |
| 50 | export component=api |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 51 | fi |
| 52 | |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 53 | COMPOSE_FOLDER="${WORKSPACE}"/compose |
| 54 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 55 | cd ${COMPOSE_FOLDER} |
| 56 | |
| 57 | source export-ports.sh > /dev/null 2>&1 |
| 58 | source get-versions.sh > /dev/null 2>&1 |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 59 | |
| 60 | echo "Collecting logs from docker compose containers..." |
adheli.tavares | f11e6d9 | 2024-08-01 14:18:34 +0100 | [diff] [blame] | 61 | rm -rf *.log |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 62 | |
adheli.tavares | d802fd9 | 2024-08-15 12:39:19 +0100 | [diff] [blame] | 63 | #COMPOSE_FILES="-f compose.${database}.yml -f compose.pdp.scale.yml -f compose.acm.scale.yml" |
| 64 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 65 | # this will collect logs by service instead of mixing all together |
| 66 | containers=$(docker compose ps --all --format '{{.Service}}') |
| 67 | |
| 68 | IFS=$'\n' read -d '' -r -a item_list <<< "$containers" |
| 69 | for item in "${item_list[@]}" |
| 70 | do |
| 71 | if [ -n "$item" ]; then |
adheli.tavares | f11e6d9 | 2024-08-01 14:18:34 +0100 | [diff] [blame] | 72 | docker compose logs $item >> $item.log |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 73 | fi |
| 74 | done |
| 75 | |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 76 | echo "Tearing down containers..." |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 77 | docker compose down -v --remove-orphans |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 78 | |
| 79 | cd ${WORKSPACE} |