2017-07-07 09:36:32 +00:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
|
|
# Initialize variables
|
|
|
|
readonly traefik_url="traefik.localhost.com"
|
|
|
|
readonly basedir=$(dirname $0)
|
2018-03-05 19:54:04 +00:00
|
|
|
readonly doc_file=$basedir"/docker-compose.yml"
|
2017-07-07 09:36:32 +00:00
|
|
|
|
|
|
|
# Stop and remove Docker environment
|
|
|
|
down_environment() {
|
|
|
|
echo "STOP Docker environment"
|
|
|
|
! docker-compose -f $doc_file down -v &>/dev/null && \
|
2018-05-16 09:44:03 +00:00
|
|
|
echo "[ERROR] Unable to stop the Docker environment" && exit 11
|
2017-07-07 09:36:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create and start Docker-compose environment or subpart of its services (if services are listed)
|
|
|
|
# $@ : List of services to start (optional)
|
|
|
|
up_environment() {
|
|
|
|
echo "START Docker environment"
|
|
|
|
! docker-compose -f $doc_file up -d $@ &>/dev/null && \
|
2018-05-16 09:44:03 +00:00
|
|
|
echo "[ERROR] Unable to start Docker environment" && exit 21
|
2017-07-07 09:36:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Init the environment : get IP address and create needed files
|
|
|
|
init_environment() {
|
|
|
|
echo "CREATE empty acme.json file"
|
|
|
|
rm -f $basedir/acme.json && \
|
|
|
|
touch $basedir/acme.json && \
|
|
|
|
chmod 600 $basedir/acme.json # Needed for ACME
|
|
|
|
}
|
|
|
|
|
|
|
|
# Start all the environement
|
2018-03-05 19:54:04 +00:00
|
|
|
start_boulder() {
|
2017-07-07 09:36:32 +00:00
|
|
|
init_environment
|
|
|
|
echo "Start boulder environment"
|
2018-03-26 12:12:03 +00:00
|
|
|
up_environment bmysql bhsm boulder
|
2017-07-07 09:36:32 +00:00
|
|
|
waiting_counter=12
|
|
|
|
# Not start Traefik if boulder is not started
|
|
|
|
echo "WAIT for boulder..."
|
2018-03-05 19:54:04 +00:00
|
|
|
while [[ -z $(curl -s http://127.0.0.1:4000/directory) ]]; do
|
2017-07-07 09:36:32 +00:00
|
|
|
sleep 5
|
|
|
|
let waiting_counter-=1
|
|
|
|
if [[ $waiting_counter -eq 0 ]]; then
|
2018-05-16 09:44:03 +00:00
|
|
|
echo "[ERROR] Unable to start boulder container in the allowed time, the Docker environment will be stopped"
|
2017-07-07 09:36:32 +00:00
|
|
|
down_environment
|
|
|
|
exit 41
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Script usage
|
|
|
|
show_usage() {
|
|
|
|
echo
|
|
|
|
echo "USAGE : manage_acme_docker_environment.sh [--start|--stop|--restart]"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
# Main method
|
|
|
|
# $@ All parameters given
|
|
|
|
main() {
|
|
|
|
|
|
|
|
[[ $# -ne 1 ]] && show_usage && exit 1
|
|
|
|
|
|
|
|
case $1 in
|
2018-03-05 19:54:04 +00:00
|
|
|
"--dev")
|
|
|
|
start_boulder
|
|
|
|
;;
|
2017-07-07 09:36:32 +00:00
|
|
|
"--start")
|
|
|
|
# Start boulder environment
|
2018-03-05 19:54:04 +00:00
|
|
|
start_boulder
|
|
|
|
echo "START Traefik container"
|
|
|
|
up_environment traefik
|
2017-07-07 09:36:32 +00:00
|
|
|
echo "ENVIRONMENT SUCCESSFULLY STARTED"
|
|
|
|
;;
|
|
|
|
"--stop")
|
|
|
|
! down_environment
|
|
|
|
echo "ENVIRONMENT SUCCESSFULLY STOPPED"
|
|
|
|
;;
|
|
|
|
"--restart")
|
|
|
|
down_environment
|
2018-03-05 19:54:04 +00:00
|
|
|
start_boulder
|
|
|
|
echo "START Traefik container"
|
|
|
|
up_environment traefik
|
|
|
|
echo "ENVIRONMENT SUCCESSFULLY RESTARTED"
|
2017-07-07 09:36:32 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
show_usage && exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
main $@
|