bridgehead/bridgehead

160 lines
4.4 KiB
Plaintext
Raw Normal View History

#!/bin/bash -e
baseDir() {
# see https://stackoverflow.com/questions/59895
SOURCE=${BASH_SOURCE[0]}
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
echo $DIR
}
BASE=$(baseDir)
cd $BASE
source ./lib/functions.sh
ACTION=$1
export PROJECT=$2
if [[ -z $1 || -z $2 ]]; then
printUsage
exit 1
fi
case "$PROJECT" in
ccp)
#nothing extra to do
;;
2022-10-25 11:45:01 +02:00
bbmri)
#nothing extra to do
;;
2023-05-10 12:54:05 +02:00
minimal)
#nothing extra to do
;;
*)
printUsage
exit 1
;;
esac
loadVars() {
# Load variables from /etc/bridgehead and /srv/docker/bridgehead
set -a
source /etc/bridgehead/$PROJECT.conf || fail_and_report 1 "/etc/bridgehead/$PROJECT.conf not found"
if [ -e /etc/bridgehead/$PROJECT.local.conf ]; then
log INFO "Applying /etc/bridgehead/$PROJECT.local.conf"
source /etc/bridgehead/$PROJECT.local.conf || fail_and_report 1 "Found /etc/bridgehead/$PROJECT.local.conf but failed to import"
fi
fetchVarsFromVaultByFile /etc/bridgehead/$PROJECT.conf || fail_and_report 1 "Unable to fetchVarsFromVaultByFile"
2023-11-16 14:21:19 +01:00
setHostname
optimizeBlazeMemoryUsage
[ -e ./$PROJECT/vars ] && source ./$PROJECT/vars
set +a
2022-10-06 16:27:52 +02:00
OVERRIDE=${OVERRIDE:=""}
2023-05-10 12:54:05 +02:00
# minimal contains shared components, so potential overrides must be applied in every project
if [ -f "minimal/docker-compose.override.yml" ]; then
2023-05-19 13:53:03 +02:00
log INFO "Applying Bridgehead common components override (minimal/docker-compose.override.yml)"
2023-05-10 12:54:05 +02:00
OVERRIDE+=" -f ./minimal/docker-compose.override.yml"
fi
if [ -f "$PROJECT/docker-compose.override.yml" ]; then
log INFO "Applying $PROJECT/docker-compose.override.yml"
OVERRIDE+=" -f ./$PROJECT/docker-compose.override.yml"
fi
detectCompose
2023-10-05 09:43:57 +02:00
setupProxy
# Set some project-independent default values
: ${ENVIRONMENT:=production}
2024-01-08 15:49:46 +01:00
case "$ENVIRONMENT" in
"production")
2024-01-09 11:43:57 +01:00
export FOCUS_TAG=main
2024-01-08 15:49:46 +01:00
;;
"test")
2024-01-09 11:43:57 +01:00
export FOCUS_TAG=develop
2024-01-08 15:49:46 +01:00
;;
*)
report_error 7 "Environment \"$ENVIRONMENT\" is unknown. Assuming production. FIX THIS!"
2024-01-09 11:43:57 +01:00
export FOCUS_TAG=main
2024-01-08 15:49:46 +01:00
;;
esac
}
2022-10-28 10:12:21 +02:00
case "$ACTION" in
start)
loadVars
hc_send log "Bridgehead $PROJECT startup: Checking requirements ..."
checkRequirements
sync_secrets
hc_send log "Bridgehead $PROJECT startup: Requirements checked out. Now starting bridgehead ..."
2023-06-29 09:52:11 +02:00
exec $COMPOSE -p $PROJECT -f ./minimal/docker-compose.yml -f ./$PROJECT/docker-compose.yml $OVERRIDE up --abort-on-container-exit
;;
stop)
loadVars
2024-04-15 13:12:17 +02:00
# Kill stale secret-sync instances if present
docker kill $(docker ps -q --filter ancestor=docker.verbis.dkfz.de/cache/samply/secret-sync-local) 2>/dev/null || true
2023-05-19 13:53:03 +02:00
# HACK: This is temporarily to properly shut down false bridgehead instances (bridgehead-ccp instead ccp)
2023-05-10 12:54:05 +02:00
$COMPOSE -p bridgehead-$PROJECT -f ./minimal/docker-compose.yml -f ./$PROJECT/docker-compose.yml $OVERRIDE down
2023-06-29 10:27:00 +02:00
exec $COMPOSE -p $PROJECT -f ./minimal/docker-compose.yml -f ./$PROJECT/docker-compose.yml $OVERRIDE down
;;
is-running)
bk_is_running
exit $?
;;
2024-02-14 15:28:16 +01:00
logs)
loadVars
shift 2
exec journalctl -u bridgehead@$PROJECT -u bridgehead-update@$PROJECT -a $@
;;
docker-logs)
2024-02-14 15:28:16 +01:00
loadVars
shift 2
exec $COMPOSE -p $PROJECT -f ./minimal/docker-compose.yml -f ./$PROJECT/docker-compose.yml $OVERRIDE logs -f $@
;;
update)
loadVars
exec ./lib/update-bridgehead.sh $PROJECT
;;
install)
2023-02-24 16:32:17 +01:00
source ./lib/prepare-system.sh NODEV
loadVars
exec ./lib/install-bridgehead.sh $PROJECT
;;
dev-install)
exec ./lib/prepare-system.sh DEV
loadVars
exec ./lib/install-bridgehead.sh $PROJECT
;;
uninstall)
exec ./lib/uninstall-bridgehead.sh $PROJECT
;;
adduser)
loadVars
2023-08-09 09:10:20 +02:00
log "INFO" "Adding encrypted credentials in /etc/bridgehead/$PROJECT.local.conf"
2023-08-09 09:24:23 +02:00
read -p "Please choose the component (LDM_AUTH|NNGM_AUTH) you want to add a user to : " COMPONENT
read -p "Please enter a username: " USER
read -s -p "Please enter a password (will not be echoed): "$'\n' PASSWORD
add_basic_auth_user $USER $PASSWORD $COMPONENT $PROJECT
;;
2022-10-17 14:38:34 +02:00
enroll)
loadVars
2023-08-07 13:00:37 +02:00
do_enroll $PROXY_ID
2022-10-17 14:38:34 +02:00
;;
preRun | preUpdate)
fixPermissions
;;
postRun | postUpdate)
;;
*)
printUsage
exit 1
;;
esac
exit 0