diff --git a/README.md b/README.md index 0b880a5..4a54d29 100644 --- a/README.md +++ b/README.md @@ -173,14 +173,14 @@ sudo git clone https://github.com/samply/bridgehead-config.git /etc/bridgehead; You should now be able to run a bridgehead instance. To check if everything works, execute the following: ``` shell -/srv/docker/bridgehead/bridgehead start +/srv/docker/bridgehead/bridgehead start ``` You should now be able to access the landing page on your system, e.g "https:///" To shutdown the bridgehead just run. ``` shell -/srv/docker/bridgehead/bridgehead stop +/srv/docker/bridgehead/bridgehead stop ``` We recommend to run first with the start and stop script and if aviable run the systemd service, which also enables automatic updates and more. @@ -189,12 +189,12 @@ We recommend to run first with the start and stop script and if aviable run the For a server, we highly recommend that you install the system units for managing the bridgehead, provided by us. You can do this by executing the [bridgehead](./bridgehead) script: ``` shell -sudo /srv/docker/bridgehead/bridgehead install +sudo /srv/docker/bridgehead/bridgehead install ``` Finally, you need to configure your sites secrets. These are places as configuration for each bridgeheads system unit. Refer to the section for your specific project: -For Every Project you need to set the proxy this way, if you have a proxy. +For Every project you need to set the proxy this way, if you have a proxy. ``` conf [Service] diff --git a/bridgehead b/bridgehead index 64a1463..0634d06 100755 --- a/bridgehead +++ b/bridgehead @@ -17,15 +17,15 @@ cd $BASE source ./lib/functions.sh -action=$1 -export project=$2 +ACTION=$1 +export PROJECT=$2 if [[ -z $1 || -z $2 ]]; then printUsage exit 1 fi -case "$project" in +case "$PROJECT" in ccp) #nothing extra to do ;; @@ -43,16 +43,16 @@ esac source /etc/bridgehead/site.conf -case "$action" in +case "$ACTION" in start) checkRequirements - exec docker-compose -f ./$project/docker-compose.yml --env-file /etc/bridgehead/$project.env up + exec docker-compose -f ./$PROJECT/docker-compose.yml --env-file /etc/bridgehead/$PROJECT.env up ;; stop) - exec docker-compose -f ./$project/docker-compose.yml --env-file /etc/bridgehead/$project.env down + exec docker-compose -f ./$PROJECT/docker-compose.yml --env-file /etc/bridgehead/$PROJECT.env down ;; update) - exec ./lib/update-bridgehead.sh $project + exec ./lib/update-bridgehead.sh $PROJECT ;; install) exec ./lib/setup-bridgehead-units.sh $project diff --git a/ccp/docker-compose.yml b/ccp/docker-compose.yml index dc0a3fc..73e3910 100644 --- a/ccp/docker-compose.yml +++ b/ccp/docker-compose.yml @@ -47,8 +47,8 @@ services: - "traefik.http.routers.landing.tls=true" environment: HOST: ${HOST} - project: ${project} - site_name: ${site_name} + PROJECT: ${PROJECT} + SITE_NAME: ${SITE_NAME} blaze: image: "samply/blaze:0.17" diff --git a/gbn/docker-compose.yml b/gbn/docker-compose.yml index 36b7263..c14883b 100644 --- a/gbn/docker-compose.yml +++ b/gbn/docker-compose.yml @@ -52,8 +52,8 @@ services: - "traefik.http.routers.landing.tls=true" environment: HOST: ${HOST} - project: ${project} - site_name: ${site_name} + PROJECT: ${PROJECT} + SITE_NAME: ${SITE_NAME} blaze: image: "samply/blaze:0.17" diff --git a/lib/prerequisites.sh b/lib/prerequisites.sh index 130036e..60fa945 100755 --- a/lib/prerequisites.sh +++ b/lib/prerequisites.sh @@ -45,14 +45,14 @@ source /etc/bridgehead/site.conf # TODO: Check all required variables here in a generic loop -if [ -z "$site_name" ]; then +if [ -z "$SITE_NAME" ]; then log ERROR "Please set site_name." exit 1 fi #check if project env is present -if [ -d "/etc/bridgehead/${project}.env" ]; then - log ERROR "Project config not found. Please copy the template from ${project} and put it under /etc/bridgehead-config/${project}.env." +if [ -d "/etc/bridgehead/${PROJECT}.env" ]; then + log ERROR "Project config not found. Please copy the template from ${PROJECT} and put it under /etc/bridgehead-config/${PROJECT}.env." exit 1 fi diff --git a/lib/remove-bridgehead-units.sh b/lib/remove-bridgehead-units.sh index 789c2e0..7de201f 100755 --- a/lib/remove-bridgehead-units.sh +++ b/lib/remove-bridgehead-units.sh @@ -12,12 +12,12 @@ if [ $1 != "ccp" ] && [ $1 != "nngm" ] && [ $1 != "gbn" ]; then exit 1 fi -export project=$1 +export PROJECT=$1 #checkRequirements // not needed when uninstalling log "Stopping systemd services and removing bridgehead ..." -systemctl disable --now bridgehead@${project}.service bridgehead-update@${project}.timer bridgehead-update@${project}.service +systemctl disable --now bridgehead@${PROJECT}.service bridgehead-update@${PROJECT}.timer bridgehead-update@${PROJECT}.service rm -v /etc/systemd/system/{bridgehead\@.service,bridgehead-update\@.timer,bridgehead-update\@.service} diff --git a/lib/setup-bridgehead-units.sh b/lib/setup-bridgehead-units.sh index f0e39d8..e6d93f0 100755 --- a/lib/setup-bridgehead-units.sh +++ b/lib/setup-bridgehead-units.sh @@ -14,7 +14,7 @@ if [ $1 != "ccp" ] && [ $1 != "nngm" ] && [ $1 != "gbn" ]; then exit 1 fi -export project=$1 +export PROJECT=$1 checkRequirements @@ -29,11 +29,11 @@ systemctl daemon-reload echo -if ! systemctl is-active --quiet bridgehead@"${project}"; then - log "Enabling autostart of bridgehead@${project}.service" - systemctl enable bridgehead@"${project}" - log "Enabling nightly updates for bridgehead@${project}.service ..." - systemctl enable --now bridgehead-update@"${project}".timer +if ! systemctl is-active --quiet bridgehead@"${PROJECT}"; then + log "Enabling autostart of bridgehead@${PROJECT}.service" + systemctl enable bridgehead@"${PROJECT}" + log "Enabling nightly updates for bridgehead@${PROJECT}.service ..." + systemctl enable --now bridgehead-update@"${PROJECT}".timer fi -echo -e "\nDone - now start your bridgehead by running\n\tsystemctl start bridgehead@${project}.service\nor by rebooting your machine." +echo -e "\nDone - now start your bridgehead by running\n\tsystemctl start bridgehead@${PROJECT}.service\nor by rebooting your machine." diff --git a/lib/update-bridgehead.sh b/lib/update-bridgehead.sh index b6a7f56..e15623a 100755 --- a/lib/update-bridgehead.sh +++ b/lib/update-bridgehead.sh @@ -1,34 +1,35 @@ #!/bin/bash -service="bridgehead" - source lib/functions.sh -#checkRequirements // not required for mere update +log "INFO" "Checking for updates of services" -log "INFO" "Checking for updates of $service" -# check prerequisites +# Check git updates +for DIR in /etc/bridgehead $(pwd); do + old_git_hash="$(git -C $DIR rev-parse --verify HEAD)" + git -C $DIR fetch 2>&1 + git -C $DIR pull 2>&1 + new_git_hash="$(git -C $DIR rev-parse --verify HEAD)" + git_updated="false" + if [ "$old_git_hash" != "$new_git_hash" ]; then + log "INFO" "Pulled new changes from origin" + git_updated="true" + fi +done -# check if updates are available -old_git_hash="$(git rev-parse --verify HEAD)" -git fetch 2>&1 -git pull 2>&1 -new_git_hash="$(git rev-parse --verify HEAD)" -git_updated="false" -if [ "$old_git_hash" != "$new_git_hash" ]; then - log "INFO" "Pulled new changes from origin" - git_updated="true" -fi +# Check docker updates docker_updated="false" -for image in $(docker ps --filter "name=$service" --format {{.Image}}); do - log "INFO" "Checking for Updates of Image: $image" - if docker pull $image | grep "Downloaded newer image"; then - log "INFO" "$image updated." +for IMAGE in $(docker ps --filter "name=bridgehead" --format {{.Image}}); do + log "INFO" "Checking for Updates of Image: $IMAGE" + if docker pull $IMAGE | grep "Downloaded newer image"; then + log "INFO" "$IMAGE updated." docker_updated="true" fi done + +# If anything is updated, restart service if [ $git_updated = "true" ] || [ $docker_updated = "true" ]; then - log "INFO" "Due to previous updates now restarting $service@$1" - systemctl restart "$service@$1.service" + log "INFO" "Due to previous updates now restarting bridgehead" + systemctl restart 'bridgehead@*' fi log "INFO" "checking updates finished" -exit 0 +exit 0 \ No newline at end of file diff --git a/nngm/docker-compose.yml b/nngm/docker-compose.yml index 938ad59..3b28580 100644 --- a/nngm/docker-compose.yml +++ b/nngm/docker-compose.yml @@ -42,8 +42,8 @@ services: - "traefik.http.routers.landing.tls=true" environment: HOST: ${HOST} - project: ${project} - site_name: ${site_name} + PROJECT: ${PROJECT} + SITE_NAME: ${SITE_NAME} nngm-connector: container_name: bridgehead-nngm-connector