-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from blockapps/notification-server
added the notification-server script
- Loading branch information
Showing
8 changed files
with
210 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4.5.0 | ||
4.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
Green='\033[0;32m' | ||
Red='\033[0;31m' | ||
Yellow='\033[0;33m' | ||
BYellow='\033[1;33m' | ||
NC='\033[0m' | ||
|
||
function outputLogo { | ||
echo ' | ||
╔╦╗┌─┐┬─┐┌─┐┌─┐┌┬┐┌─┐ ╔╗╔┌─┐┌┬┐┬┌─┐┬┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐ | ||
║║║├┤ ├┬┘│ ├─┤ │ ├─┤ ║║║│ │ │ │├┤ ││ ├─┤ │ ││ ││││└─┐ | ||
╩ ╩└─┘┴└─└─┘┴ ┴ ┴ ┴ ┴ ╝╚╝└─┘ ┴ ┴└ ┴└─┘┴ ┴ ┴ ┴└─┘┘└┘└─┘ | ||
' | ||
} | ||
|
||
function help { | ||
outputLogo | ||
echo -e "${BYellow}Notification Server Run Script${NC} | ||
Kickstart a Notification Server. | ||
${Yellow}Optional flags:${NC} | ||
The entrypoints are mutually exclusive. | ||
--help|-h - this help. | ||
--stop - stop Notification server containers (keeps containers and volumes.) | ||
--start - start the existing Notification server containers after they were stopped (the opposite to --stop.) | ||
--down - remove Notification server containers and leave all volumes intact. | ||
--wipe - stop and remove Notification server containers and wipe out volumes. | ||
--compose - fetch the latest stable docker-compose.notification.yml. | ||
--pull - pull images used in docker-compose.notification.yml. | ||
${Yellow}Environment variables:${NC} | ||
HTTP_PORT - (default: 80) Port for HTTP traffic listener. | ||
HTTPS_PORT - (default: 443) Port for HTTPS traffic listener; only used with ssl=true. | ||
OAUTH_DISCOVERY_URL - (required) OAuth provider's OpenID Connect discovery URL. | ||
ssl - (default: false) [true|false] to run the node with SSL/TLS. | ||
sslCertFileType - (default: pem) [pem|crt] the SSL certificate type and file extension (should be accessible at ./ssl/certs/server.<sslCertFileType> at deploy time.) | ||
" | ||
} | ||
|
||
function wipe { | ||
echo -e "${Yellow}Removing notification server containers and wiping out volumes${NC}" | ||
${docker_compose} down -vt 0 --remove-orphans | ||
} | ||
|
||
function down { | ||
echo -e "${Yellow}Removing notification server containers${NC}" | ||
${docker_compose} down --remove-orphans | ||
} | ||
|
||
function stop { | ||
echo -e "${Yellow}Gently stopping notification server containers${NC}" | ||
${docker_compose} stop | ||
} | ||
|
||
function start { | ||
echo -e "${Yellow}Starting the earlier stopped notification server containers${NC}" | ||
${docker_compose} start | ||
} | ||
|
||
function getCompose { | ||
echo -e "${Yellow}Downloading the latest stable version of docker-compose.notification.yml...${NC}" | ||
curl -fLo docker-compose.notification.yml https://github.com/blockapps/strato-getting-started/releases/download/$(curl -s -L https://github.com/blockapps/strato-getting-started/releases/latest | grep -om1 '"/blockapps/strato-getting-started/releases/tag/[^"]*' | grep -oE "[^/]+$")/docker-compose.notification.yml | ||
echo -e "${Yellow}docker-compose.notification.yml downloaded successfully.${NC}" | ||
} | ||
|
||
function pullImages { | ||
${docker_compose} pull | ||
} | ||
|
||
|
||
if [ ! -f $(pwd)/strato ]; then | ||
echo -e "${Red}Should be run from within the strato-getting-started directory. Exit.${NC}" | ||
exit 4 | ||
fi | ||
|
||
if ! docker ps &> /dev/null | ||
then | ||
echo -e "${Red}Error: docker is required: https://www.docker.com/ . If you have it installed - you may need to execute as super user${NC}" | ||
exit 1 | ||
fi | ||
|
||
if ! docker compose version &> /dev/null && ! docker-compose -v &> /dev/null | ||
then | ||
echo -e "${Red}Error: Docker Compose is required: https://docs.docker.com/compose/install/" | ||
exit 2 | ||
else | ||
if ! docker compose version &> /dev/null | ||
then | ||
docker_compose="docker-compose -p notification-server -f docker-compose.notification.yml --log-level ERROR" | ||
else | ||
docker_compose="docker -l error compose -p notification-server -f docker-compose.notification.yml" | ||
fi | ||
fi | ||
|
||
STRATOGS_REQUIRED_VERSION=$(grep strato-getting-started-min-version docker-compose.notification.yml | awk -F":" '{print $NF}') | ||
if [ ${STRATOGS_REQUIRED_VERSION} ]; then | ||
STRATOGS_CURRENT_VERSION=$(< VERSION) | ||
if ! awk -v VER=${STRATOGS_CURRENT_VERSION//.} -v REQ_VER=${STRATOGS_REQUIRED_VERSION//.} 'BEGIN {exit (VER < REQ_VER)}' | ||
then | ||
echo -e "${Red}The STRATO version from docker-compose.notification.yml is incompatible with this strato-getting-started. Please update to v${STRATOGS_REQUIRED_VERSION}." | ||
exit 12 | ||
fi | ||
fi | ||
|
||
while [ ${#} -gt 0 ]; do | ||
case "${1}" in | ||
--help|-h) | ||
help | ||
exit 0 | ||
;; | ||
--stop) | ||
stop | ||
exit 0 | ||
;; | ||
--start) | ||
start | ||
exit 0 | ||
;; | ||
--down) | ||
down | ||
exit 0 | ||
;; | ||
--wipe) | ||
wipe | ||
exit 0 | ||
;; | ||
--compose) | ||
getCompose | ||
exit 0 | ||
;; | ||
--pull) | ||
pullImages | ||
exit 0 | ||
;; | ||
*) | ||
echo -e "${Red}Unknown flag ${1} provided, please check --help. Exit.${NC}" | ||
exit 5 | ||
;; | ||
esac | ||
shift 1 | ||
done | ||
|
||
outputLogo | ||
|
||
if [ "$ssl" = true ] ; then | ||
http_protocol=https | ||
main_port=${HTTPS_PORT} | ||
else | ||
http_protocol=http | ||
main_port=${HTTP_PORT} | ||
fi | ||
export sslCertFileType=${sslCertFileType:-pem} | ||
|
||
echo "" && echo "*** Common Config ***" | ||
echo "HTTP_PORT: $HTTP_PORT" | ||
echo "HTTPS_PORT: $HTTPS_PORT" | ||
echo "ssl: $ssl" | ||
echo "sslCertFileType: $sslCertFileType" | ||
|
||
if [ ! -f docker-compose.notification.yml ] | ||
then | ||
getCompose | ||
else | ||
echo -e "${BYellow}Using the existing docker-compose.notification.yml (to download the most recent stable version - remove the file and restart the script)${NC}" | ||
fi | ||
|
||
# COMPOSE FILE PRE-PROCESSING | ||
function cleanup { | ||
rm docker-compose-notification-temp.yml | ||
} | ||
trap cleanup EXIT | ||
|
||
if [ "$ssl" != true ]; then | ||
sed -n '/#TAG_REMOVE_WHEN_NO_SSL/!p' docker-compose.notification.yml > docker-compose-notification-temp.yml | ||
else | ||
if [ "$HTTPS_PORT" != "443" ]; then | ||
sed -n '/#TAG_REMOVE_WHEN_SSL_CUSTOM_HTTPS_PORT/!p' docker-compose.notification.yml > docker-compose-notification-temp.yml | ||
else | ||
cp docker-compose.notification.yml docker-compose-notification-temp.yml | ||
fi | ||
fi | ||
# END OF COMPOSE FILE PRE-PROCESSING | ||
|
||
${docker_compose} -f docker-compose-notification-temp.yml up -d --remove-orphans | ||
until curl --silent --output /dev/null --fail --insecure --location "${http_protocol}://localhost:${main_port}/_ping" ; do sleep 0.5; done | ||
|
||
echo -e "\n${Green}STRATO Notification Server has awoken.${NC}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters