From d11c100ab549efe7237694e1e713eacebc48d378 Mon Sep 17 00:00:00 2001 From: Muawia Khan Date: Wed, 16 Aug 2017 13:15:24 +0200 Subject: [PATCH] Improve error message for all bdb docker entrypoint scripts - If a mandatory variable is not specified, it will exit with the relevant code and error message. - For more verbosity, we will also echo the values for all the mandatory variables. --- .../mongodb_backup_agent_entrypoint.bash | 18 +++++---- .../mongodb_mon_agent_entrypoint.bash | 18 +++++---- k8s/mongodb/container/mongod_entrypoint.bash | 27 ++++++++----- .../container/nginx_entrypoint.bash | 29 +++++++++----- .../container/nginx_entrypoint.bash | 38 ++++++++++++------- 5 files changed, 83 insertions(+), 47 deletions(-) diff --git a/k8s/mongodb-backup-agent/container/mongodb_backup_agent_entrypoint.bash b/k8s/mongodb-backup-agent/container/mongodb_backup_agent_entrypoint.bash index 13a40bb5..ae92a46f 100755 --- a/k8s/mongodb-backup-agent/container/mongodb_backup_agent_entrypoint.bash +++ b/k8s/mongodb-backup-agent/container/mongodb_backup_agent_entrypoint.bash @@ -7,14 +7,18 @@ MONGODB_BACKUP_CONF_FILE=/etc/mongodb-mms/backup-agent.config mms_api_keyfile_path=`printenv MMS_API_KEYFILE_PATH` mms_groupid_keyfile_path=`printenv MMS_GROUPID_KEYFILE_PATH` ca_crt_path=`printenv CA_CRT_PATH` -backup_crt_path=`printenv BACKUP_PEM_PATH` +backup_pem_path=`printenv BACKUP_PEM_PATH` -if [[ -z "${mms_api_keyfile_path}" || \ - -z "${ca_crt_path}" || \ - -z "${backup_crt_path}" || \ - -z "${mms_groupid_keyfile_path}" ]]; then - echo "Invalid environment settings detected. Exiting!" +if [[ -z "${mms_api_keyfile_path:?MMS API Keyfile path not specified. Exiting!}" || \ + -z "${ca_crt_path:?CA CRT path not specified. Exiting!}" || \ + -z "${backup_pem_path:?Backup PEM path not specified. Exiting!}" || \ + -z "${mms_groupid_keyfile_path:?MMS GroupID keyfile path not specified. Exiting!}" ]]; then exit 1 +else + echo MMS_API_KEYFILE_PATH="$mms_api_key" + echo MMS_GROUPID_KEYFILE_PATH="$mms_groupid_keyfile_path" + echo CA_CRT_PATH="$ca_crt_path" + echo BACKUP_PEM_PATH="$backup_pem_path" fi sed -i '/mmsApiKey/d' ${MONGODB_BACKUP_CONF_FILE} @@ -33,7 +37,7 @@ echo "mothership=api-backup.eu-west-1.mongodb.com" >> ${MONGODB_BACKUP_CONF_FILE echo "useSslForAllConnections=true" >> ${MONGODB_BACKUP_CONF_FILE} echo "sslRequireValidServerCertificates=true" >> ${MONGODB_BACKUP_CONF_FILE} echo "sslTrustedServerCertificates="${ca_crt_path} >> ${MONGODB_BACKUP_CONF_FILE} -echo "sslClientCertificate="${backup_crt_path} >> ${MONGODB_BACKUP_CONF_FILE} +echo "sslClientCertificate="${backup_pem_path} >> ${MONGODB_BACKUP_CONF_FILE} echo "#sslClientCertificatePassword=" >> ${MONGODB_BACKUP_CONF_FILE} echo "INFO: starting mdb backup..." diff --git a/k8s/mongodb-monitoring-agent/container/mongodb_mon_agent_entrypoint.bash b/k8s/mongodb-monitoring-agent/container/mongodb_mon_agent_entrypoint.bash index 7ae161e3..0f5236b1 100755 --- a/k8s/mongodb-monitoring-agent/container/mongodb_mon_agent_entrypoint.bash +++ b/k8s/mongodb-monitoring-agent/container/mongodb_mon_agent_entrypoint.bash @@ -11,14 +11,18 @@ MONGODB_MON_CONF_FILE=/etc/mongodb-mms/monitoring-agent.config mms_api_keyfile_path=`printenv MMS_API_KEYFILE_PATH` mms_groupid_keyfile_path=`printenv MMS_GROUPID_KEYFILE_PATH` ca_crt_path=`printenv CA_CRT_PATH` -monitoring_crt_path=`printenv MONITORING_PEM_PATH` +monitoring_pem_path=`printenv MONITORING_PEM_PATH` -if [[ -z "${mms_api_keyfile_path}" || \ - -z "${ca_crt_path}" || \ - -z "${monitoring_crt_path}" || \ - -z "${mms_groupid_keyfile_path}" ]]; then - echo "Invalid environment settings detected. Exiting!" +if [[ -z "${mms_api_keyfile_path:?MMS API keyfile path not specified. Exiting!}" || \ + -z "${ca_crt_path:?CA CRT path not specified. Exiting!}" || \ + -z "${monitoring_pem_path:?Monitoring PEM path not specified. Exiting!}" || \ + -z "${mms_groupid_keyfile_path:?MMS GroupID keyfile path not specified. Exiting!}" ]];then exit 1 +else + echo MMS_API_KEYFILE_PATH="$mms_api_keyfile_path" + echo MMS_GROUPID_KEYFILE_PATH="$mms_groupid_keyfile_path" + echo CA_CRT_PATH="$ca_crt_path" + echo MONITORING_PEM_PATH="$monitoring_pem_path" fi # Delete the line containing "mmsApiKey" and the line containing "mmsGroupId" @@ -40,7 +44,7 @@ echo "mmsGroupId="${mms_groupid_key} >> ${MONGODB_MON_CONF_FILE} echo "useSslForAllConnections=true" >> ${MONGODB_MON_CONF_FILE} echo "sslRequireValidServerCertificates=true" >> ${MONGODB_MON_CONF_FILE} echo "sslTrustedServerCertificates="${ca_crt_path} >> ${MONGODB_MON_CONF_FILE} -echo "sslClientCertificate="${monitoring_crt_path} >> ${MONGODB_MON_CONF_FILE} +echo "sslClientCertificate="${monitoring_pem_path} >> ${MONGODB_MON_CONF_FILE} echo "#sslClientCertificatePassword=" >> ${MONGODB_MON_CONF_FILE} # start mdb monitoring agent diff --git a/k8s/mongodb/container/mongod_entrypoint.bash b/k8s/mongodb/container/mongod_entrypoint.bash index 157c92c9..2b085494 100755 --- a/k8s/mongodb/container/mongod_entrypoint.bash +++ b/k8s/mongodb/container/mongod_entrypoint.bash @@ -55,16 +55,23 @@ while [[ $# -gt 1 ]]; do done # sanity checks -if [[ -z "${REPLICA_SET_NAME}" || \ - -z "${MONGODB_PORT}" || \ - -z "${MONGODB_FQDN}" || \ - -z "${MONGODB_IP}" || \ - -z "${MONGODB_KEY_FILE_PATH}" || \ - -z "${MONGODB_CA_FILE_PATH}" || \ - -z "${MONGODB_CRL_FILE_PATH}" ]] ; then - #-z "${MONGODB_KEY_FILE_PASSWORD}" || \ - echo "Empty parameters detected. Exiting!" - exit 2 +if [[ -z "${REPLICA_SET_NAME:?MongoDB Replica Set name not specified. Exiting!}" || \ + -z "${MONGODB_PORT:?MongoDB Port not specified. Exiting!}" || \ + -z "${MONGODB_FQDN:?MongoDB FQDN not specified. Exiting!}" || \ + -z "${MONGODB_IP:?MongoDB IP not specified. Exiting!}" || \ + -z "${MONGODB_KEY_FILE_PATH:?MongoDB Key File path not specified. Exiting!}" || \ + -z "${MONGODB_CA_FILE_PATH:?MongoDB CA File path not specified. Exiting!}" || \ + -z "${MONGODB_CRL_FILE_PATH:?MongoDB CRL File path not specified. Exiting!}" ]] ; then + #-z "${MONGODB_KEY_FILE_PASSWORD:?MongoDB Key File Password not specified. Exiting!}" || \ + exit 1 +else + echo REPLICA_SET_NAME="$REPLICA_SET_NAME" + echo MONGODB_PORT="$MONGODB_PORT" + echo MONGODB_FQDN="$MONGODB_FQDN" + echo MONGODB_IP="$MONGODB_IP" + echo MONGODB_KEY_FILE_PATH="$MONGODB_KEY_FILE_PATH" + echo MONGODB_CA_FILE_PATH="$MONGODB_CA_FILE_PATH" + echo MONGODB_CRL_FILE_PATH="$MONGODB_CRL_FILE_PATH" fi MONGODB_CONF_FILE_PATH=/etc/mongod.conf diff --git a/k8s/nginx-http/container/nginx_entrypoint.bash b/k8s/nginx-http/container/nginx_entrypoint.bash index 5e379d08..ce5c6cd0 100755 --- a/k8s/nginx-http/container/nginx_entrypoint.bash +++ b/k8s/nginx-http/container/nginx_entrypoint.bash @@ -23,17 +23,26 @@ bdb_ws_port=`printenv BIGCHAINDB_WS_PORT` # sanity check -if [[ -z "${cluster_frontend_port}" || \ - -z "${mongo_frontend_port}" || \ - -z "${mongo_backend_host}" || \ - -z "${mongo_backend_port}" || \ - -z "${bdb_backend_host}" || \ - -z "${bdb_api_port}" || \ - -z "${bdb_ws_port}" || \ - -z "${dns_server}" || \ - -z "${health_check_port}" ]]; then - echo "Invalid environment settings detected. Exiting!" +if [[ -z "${cluster_frontend_port:?Cluster frontend port not specified. Exiting!}" || \ + -z "${mongo_frontend_port:?MongoDB frontend port not specified. Exiting!}" || \ + -z "${mongo_backend_host:?MongoDB backend host not specified. Exiting!}" || \ + -z "${mongo_backend_port:?MongoDB backend port not specified. Exiting!}" || \ + -z "${bdb_backend_host:?BigchainDB backend host not specified. Exiting!}" || \ + -z "${bdb_api_port:?BigchainDB API port not specified. Exiting!}" || \ + -z "${bdb_ws_port:?BigchainDB WS port not specified. Exiting!}" || \ + -z "${dns_server:?DNS server not specified. Exiting!}" || \ + -z "${health_check_port:?}" ]]; then exit 1 +else + echo CLUSTER_FRONTEND_PORT="$cluster_frontend_port" + echo DNS_SERVER="$dns_server" + echo HEALTH_CHECK_PORT="$health_check_port" + echo MONGODB_FRONTEND_PORT="$mongo_frontend_port" + echo MONGODB_BACKEND_HOST="$mongo_backend_host" + echo MONGODB_BACKEND_PORT="$mongo_backend_port" + echo BIGCHAINDB_BACKEND_HOST="$bdb_backend_host" + echo BIGCHAINDB_API_PORT="$bdb_api_port" + echo BIGCHAINDB_WS_PORT="$bdb_ws_port" fi NGINX_CONF_FILE=/etc/nginx/nginx.conf diff --git a/k8s/nginx-https/container/nginx_entrypoint.bash b/k8s/nginx-https/container/nginx_entrypoint.bash index 90adebf8..09992fae 100755 --- a/k8s/nginx-https/container/nginx_entrypoint.bash +++ b/k8s/nginx-https/container/nginx_entrypoint.bash @@ -29,20 +29,32 @@ bdb_ws_port=`printenv BIGCHAINDB_WS_PORT` # sanity check -if [[ -z "${cluster_frontend_port}" || \ - -z "${mongo_frontend_port}" || \ - -z "${mongo_backend_host}" || \ - -z "${mongo_backend_port}" || \ - -z "${openresty_backend_port}" || \ - -z "${openresty_backend_host}" || \ - -z "${bdb_backend_host}" || \ - -z "${bdb_api_port}" || \ - -z "${bdb_ws_port}" || \ - -z "${dns_server}" || \ - -z "${health_check_port}" || \ - -z "${cluster_fqdn}" ]]; then - echo "Invalid environment settings detected. Exiting!" +if [[ -z "${cluster_frontend_port:?Cluster frontend port not specified. Exiting!}" || \ + -z "${mongo_frontend_port:?MongoDB frontend port not specified. Exiting!}" || \ + -z "${mongo_backend_host:?MongoDB backend host not specified. Exiting!}" || \ + -z "${mongo_backend_port:?MongoDB backend port not specified. Exiting!}" || \ + -z "${openresty_backend_port:?OpenResty backend port not specified. Exiting!}" || \ + -z "${openresty_backend_host:?OpenResty backend host not specified. Exiting!}" || \ + -z "${bdb_backend_host:?BigchainDB backend host not specified. Exiting!}" || \ + -z "${bdb_api_port:?BigchainDB API port not specified. Exiting!}" || \ + -z "${bdb_ws_port:?BigchainDB WS port not specified. Exiting!}" || \ + -z "${dns_server:?DNS server not specified. Exiting!}" || \ + -z "${health_check_port:?Health check port not specified. Exiting!}" || \ + -z "${cluster_fqdn:?Cluster FQDN not specified. Exiting!}" ]]; then exit 1 +else + echo CLUSTER_FQDN="$cluster_fqdn" + echo CLUSTER_FRONTEND_PORT="$cluster_frontend_port" + echo DNS_SERVER="$dns_server" + echo HEALTH_CHECK_PORT="$health_check_port" + echo MONGODB_FRONTEND_PORT="$mongo_frontend_port" + echo MONGODB_BACKEND_HOST="$mongo_backend_host" + echo MONGODB_BACKEND_PORT="$mongo_backend_port" + echo OPENRESTY_BACKEND_HOST="$openresty_backend_host" + echo OPENRESTY_BACKEND_PORT="$openresty_backend_port" + echo BIGCHAINDB_BACKEND_HOST="$bdb_backend_host" + echo BIGCHAINDB_API_PORT="$bdb_api_port" + echo BIGCHAINDB_WS_PORT="$bdb_ws_port" fi NGINX_CONF_FILE=/etc/nginx/nginx.conf