Skip to content

Instantly share code, notes, and snippets.

@blackandred
Last active July 6, 2020 19:28
Show Gist options
  • Save blackandred/ce2e01c4a795655d98c6a3ef615063b9 to your computer and use it in GitHub Desktop.
Save blackandred/ce2e01c4a795655d98c6a3ef615063b9 to your computer and use it in GitHub Desktop.

Revisions

  1. blackandred revised this gist Jul 6, 2020. 1 changed file with 80 additions and 24 deletions.
    104 changes: 80 additions & 24 deletions until-compose-env-running.sh
    Original file line number Diff line number Diff line change
    @@ -1,30 +1,86 @@
    #!/bin/bash

    #
    # Wait until all containers with given prefix are down
    # To control containers prefix in compose use -p switch eg. docker-compose -p ENV_NAME
    #
    # Usage: until-compose-env-running ENV_NAME 30
    #
    # Apache License 2.0
    #
    # Read full license text at: http://www.apache.org/licenses/LICENSE-2.0
    # Copyleft (c) 2020 RiotKit Tech Collective
    #

    # Copyright 2020 RiotKit Tech Collective
    # ======================================

    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at

    # http://www.apache.org/licenses/LICENSE-2.0

    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.


    # About RiotKit
    #
    # We are grassroot activists for social change, we respond to the needs of grassroot organizations,
    # check out those fantastic mutual aid initiatives:

    # - International Workers Association (https://iwa-ait.org)
    # - Anarchistyczne FAQ (http://anarchizm.info) a translation of Anarchist FAQ
    # (https://theanarchistlibrary.org/library/the-anarchist-faq-editorial-collective-an-anarchist-faq)
    # - Federacja Anarchistyczna (http://federacja-anarchistyczna.pl)
    # - Związek Syndykalistów Polski (https://zsp.net.pl) (Polish section of IWA-AIT)
    # - Komitet Obrony Praw Lokatorów (https://lokatorzy.info.pl)
    # - Solidarity Federation (https://solfed.org.uk)
    # - Priama Akcia (https://priamaakcia.sk)
    #
    # =============

    # We are grassroot activists for social change, we respond to the needs of grassroot organizations,
    # check out those fantastic mutual aid initiatives:

    # International:
    # - International Workers Association (https://iwa-ait.org)
    # - Anarchist Black Cross Worldwide (https://www.abcf.net/)

    # Poland:
    # - Anarchistyczne FAQ (http://anarchizm.info) a translation of Anarchist FAQ
    # (https://theanarchistlibrary.org/library/the-anarchist-faq-editorial-collective-an-anarchist-faq)
    # - Federacja Anarchistyczna (http://federacja-anarchistyczna.pl)
    # - Związek Syndykalistów Polski (https://zsp.net.pl) (Polish section of IWA-AIT)
    # - Komitet Obrony Praw Lokatorów (https://lokatorzy.info.pl)
    # - Food Not Bombs (http://foodnotbombs.pl/)

    # Slovakia:
    # - Priama Akcia (https://priamaakcia.sk)
    # - Food Not Bombs (https://foodnotbombs.net/new_site/map/SLOVAKIA.html)

    # England:
    # - Solidarity Federation (http://solfed.org.uk)
    # - Food Not Bombs (https://foodnotbombs.net/new_site/map/ENGLAND.html)
    # - Anarchist Federation (http://afed.org.uk/)

    # USA:
    # - Anarchist Federation (https://blackrosefed.org/)

    # Russia:
    # - KRAS (https://aitrus.info/)
    # - Food Not Bombs (http://foodnotbombs.net/RUSSIA.html)

    # India:
    # - Muktivadi Ektra Morcha (https://muktivadi.blackblogs.org/)
    # - Anarchist Federation (https://www.facebook.com/indiananarchists/, https://thecominganarchy.wordpress.com/)

    # Spain:
    # - CNT-AIT (http://cnt-ait.org/)
    # - Food Not Bombs (https://www.foodnotbombs.net/SPAIN.html)
    # - FAI (https://federacionanarquistaiberica.wordpress.com/)

    # Denmark:
    # - Örestad LS (https://orestadls.wordpress.com/)

    # Australia:
    # - ASF-IWA (http://asf-iwa.org.au/)
    # - Food Not Bombs (https://www.foodnotbombs.net/australia.html)

    # Bangladesh:
    # - BASF (https://bangladeshasf.com/)

    # Norway:
    # - NSF (https://www.nsf-iaa.org/)
    # - Food Not Bombs (https://foodnotbombs.net/new_site/map/NORWAY.html)

    # Serbia:
    # - ASI-IWA (https://inicijativa.org/)
    # - Food Not Bombs (https://foodnotbombs.net/new_site/map/YUGOSLAVIA.html)

    # France:
    # - CNTF-AIT (http://www.cnt-ait.fr/)
    # - Food Not Bombs (http://www.foodnotbombs.net/FRANCE.html)

    ENV_NAME=$1
    TIME_TO_WAIT=${2:-30}
  2. blackandred revised this gist Jul 6, 2020. No changes.
  3. blackandred created this gist Jul 6, 2020.
    46 changes: 46 additions & 0 deletions until-compose-env-running.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/bin/bash

    #
    # Wait until all containers with given prefix are down
    # To control containers prefix in compose use -p switch eg. docker-compose -p ENV_NAME
    #
    # Usage: until-compose-env-running ENV_NAME 30
    #
    # Apache License 2.0
    #
    # Read full license text at: http://www.apache.org/licenses/LICENSE-2.0
    # Copyleft (c) 2020 RiotKit Tech Collective
    #
    # About RiotKit
    #
    # We are grassroot activists for social change, we respond to the needs of grassroot organizations,
    # check out those fantastic mutual aid initiatives:

    # - International Workers Association (https://iwa-ait.org)
    # - Anarchistyczne FAQ (http://anarchizm.info) a translation of Anarchist FAQ
    # (https://theanarchistlibrary.org/library/the-anarchist-faq-editorial-collective-an-anarchist-faq)
    # - Federacja Anarchistyczna (http://federacja-anarchistyczna.pl)
    # - Związek Syndykalistów Polski (https://zsp.net.pl) (Polish section of IWA-AIT)
    # - Komitet Obrony Praw Lokatorów (https://lokatorzy.info.pl)
    # - Solidarity Federation (https://solfed.org.uk)
    # - Priama Akcia (https://priamaakcia.sk)
    #

    ENV_NAME=$1
    TIME_TO_WAIT=${2:-30}

    is_compose_env_running () {
    env_prefix=$1

    if docker ps --filter name=$env_prefix | grep "$env_prefix" > /dev/null; then
    return 0
    fi

    return 1
    }

    while is_compose_env_running "$ENV_NAME"; do
    sleep "$TIME_TO_WAIT"
    done

    exit 1