From 8af4d277328540b090e16bb044c7fee0a76c15c2 Mon Sep 17 00:00:00 2001 From: Dobroslaw Zybort Date: Mon, 11 Sep 2017 10:54:25 +0200 Subject: [PATCH 1/2] Add more double quotes to sh files --- kafka-init/wait-for.sh | 14 +++++++------- kafka/start.sh | 14 +++++++------- keystone/keystone-bootstrap.sh | 18 +++++++++--------- keystone/start.sh | 4 ++-- kibana/start.sh | 4 ++-- kibana/wait-for.sh | 16 ++++++++-------- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/kafka-init/wait-for.sh b/kafka-init/wait-for.sh index 4e9bc4f33..854c2eaf1 100644 --- a/kafka-init/wait-for.sh +++ b/kafka-init/wait-for.sh @@ -2,7 +2,7 @@ # Use this script to test if a given TCP host/port are available # https://github.com/vishnubob/wait-for-it/blob/master/wait-for-it.sh -cmdname=$(basename $0) +cmdname=$(basename "$0") echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } @@ -34,10 +34,10 @@ wait_for() while : do if [[ $ISBUSY -eq 1 ]]; then - nc -z $HOST $PORT + nc -z "$HOST" "$PORT" result=$? else - (echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1 + (echo > /dev/tcp/"$HOST"/"$PORT") >/dev/null 2>&1 result=$? fi if [[ $result -eq 0 ]]; then @@ -54,9 +54,9 @@ wait_for_wrapper() { # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 if [[ $QUIET -eq 1 ]]; then - timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & + timeout "$BUSYTIMEFLAG" "$TIMEOUT" $0 --quiet" --child --host="$HOST" --port="$PORT" --timeout="$TIMEOUT" & else - timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & + timeout "$BUSYTIMEFLAG" "$TIMEOUT" $0 --child --host="$HOST" --port="$PORT" --timeout="$TIMEOUT" & fi PID=$! trap "kill -INT -$PID" INT @@ -172,7 +172,7 @@ if [[ $CLI != "" ]]; then echoerr "$cmdname: strict mode, refusing to execute subprocess" exit $RESULT fi - exec $CLI + exec "$CLI" else - exit $RESULT + exit "$RESULT" fi diff --git a/kafka/start.sh b/kafka/start.sh index 74ca2ae27..ed3b7704c 100755 --- a/kafka/start.sh +++ b/kafka/start.sh @@ -22,21 +22,21 @@ export STATE_CHANGE_LOG_LEVEL=${STATE_CHANGE_LOG_LEVEL:-"INFO"} export AUTHORIZER_LOG_LEVEL=${AUTHORIZER_LOG_LEVEL:-"WARN"} GC_LOG_ENABLED=${GC_LOG_ENABLED:-"False"} -first_zk=$(echo $ZOOKEEPER_CONNECTION_STRING | cut -d, -f1) -zk_host=$(echo $first_zk | cut -d\: -f1) -zk_port=$(echo $first_zk | cut -d\: -f2) +first_zk=$(echo "$ZOOKEEPER_CONNECTION_STRING" | cut -d, -f1) +zk_host=$(echo "$first_zk" | cut -d\: -f1) +zk_port=$(echo "$first_zk" | cut -d\: -f2) # wait for zookeeper to become available if [ "$ZOOKEEPER_WAIT" = "true" ]; then success="false" - for i in $(seq $ZOOKEEPER_WAIT_RETRIES); do - ok=$(echo ruok | nc $zk_host $zk_port -w $ZOOKEEPER_WAIT_TIMEOUT) + for i in $(seq "$ZOOKEEPER_WAIT_RETRIES"); do + ok=$(echo ruok | nc "$zk_host" "$zk_port" -w "$ZOOKEEPER_WAIT_TIMEOUT") if [ $? -eq 0 -a "$ok" = "imok" ]; then success="true" break else echo "Connect attempt $i of $ZOOKEEPER_WAIT_RETRIES failed, retrying..." - sleep $ZOOKEEPER_WAIT_DELAY + sleep "$ZOOKEEPER_WAIT_DELAY" fi done @@ -69,7 +69,7 @@ for f in $CONFIG_TEMPLATES/*.properties.j2; do done if [ -z "$KAFKA_HEAP_OPTS" ]; then - max_heap=$(python /heap.py $KAFKA_MAX_HEAP_MB) + max_heap=$(python /heap.py "$KAFKA_MAX_HEAP_MB") KAFKA_HEAP_OPTS="-Xmx${max_heap} -Xms${max_heap}" export KAFKA_HEAP_OPTS fi diff --git a/keystone/keystone-bootstrap.sh b/keystone/keystone-bootstrap.sh index 70c017502..5802a5397 100755 --- a/keystone/keystone-bootstrap.sh +++ b/keystone/keystone-bootstrap.sh @@ -41,15 +41,15 @@ fi if [[ -e /db-init ]]; then echo "Creating bootstrap credentials..." keystone-manage bootstrap \ - --bootstrap-password $admin_password \ - --bootstrap-username $admin_username \ - --bootstrap-project-name $admin_project \ - --bootstrap-role-name $admin_role \ - --bootstrap-service-name $admin_service \ - --bootstrap-region-id $admin_region \ - --bootstrap-admin-url $admin_url \ - --bootstrap-public-url $public_url \ - --bootstrap-internal-url $internal_url + --bootstrap-password "$admin_password" \ + --bootstrap-username "$admin_username" \ + --bootstrap-project-name "$admin_project" \ + --bootstrap-role-name "$admin_role" \ + --bootstrap-service-name "$admin_service" \ + --bootstrap-region-id "$admin_region" \ + --bootstrap-admin-url "$admin_url" \ + --bootstrap-public-url "$public_url" \ + --bootstrap-internal-url "$internal_url" sleep 5 diff --git a/keystone/start.sh b/keystone/start.sh index 81e721f83..f3d0e68fc 100755 --- a/keystone/start.sh +++ b/keystone/start.sh @@ -11,7 +11,7 @@ if [[ "$KEYSTONE_DATABASE_BACKEND" = "mysql" ]]; then echo "Waiting for mysql to become available..." success="false" - for i in $(seq $retries); do + for i in $(seq "$retries"); do mysqladmin status \ --host="$mysql_host" \ --user="$mysql_user" \ @@ -40,7 +40,7 @@ if [[ "$KEYSTONE_DATABASE_BACKEND" = "mysql" ]]; then /etc/keystone/keystone.conf # check to see if table exists already and skip init if so - mysql -h ${mysql_host} -u ${mysql_user} -p${mysql_pass} -e "desc ${mysql_db}.migrate_version" &> /dev/null + mysql -h "${mysql_host}" -u "${mysql_user}" -p"${mysql_pass}" -e "desc ${mysql_db}.migrate_version" &> /dev/null if [[ $? -eq 0 ]]; then echo "MySQL database has already been initialized, skipping..." else diff --git a/kibana/start.sh b/kibana/start.sh index ae56a52d1..2ab7e424a 100644 --- a/kibana/start.sh +++ b/kibana/start.sh @@ -2,8 +2,8 @@ python /template.py /kibana.yml.j2 /opt/kibana/config/kibana.yml -if [ $MONASCA_PLUGIN_ENABLED == True ]; then - /wait-for.sh $KEYSTONE_URI -- kibana +if [ "$MONASCA_PLUGIN_ENABLED" == True ]; then + /wait-for.sh "$KEYSTONE_URI" -- kibana else kibana fi diff --git a/kibana/wait-for.sh b/kibana/wait-for.sh index 8abfe51a2..337119666 100644 --- a/kibana/wait-for.sh +++ b/kibana/wait-for.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Use this script to test if a given TCP host/port are available -cmdname=$(basename $0) +cmdname=$(basename "$0") echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } @@ -33,10 +33,10 @@ wait_for() while : do if [[ $ISBUSY -eq 1 ]]; then - nc -z $HOST $PORT + nc -z "$HOST" "$PORT" result=$? else - (echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1 + (echo > /dev/tcp/"$HOST"/"$PORT") >/dev/null 2>&1 result=$? fi if [[ $result -eq 0 ]]; then @@ -53,9 +53,9 @@ wait_for_wrapper() { # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 if [[ $QUIET -eq 1 ]]; then - timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & + timeout "$BUSYTIMEFLAG" "$TIMEOUT" "$0" --quiet --child --host="$HOST" --port="$PORT" --timeout="$TIMEOUT" & else - timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT & + timeout "$BUSYTIMEFLAG" "$TIMEOUT" "$0" --child --host="$HOST" --port="$PORT" --timeout="$TIMEOUT" & fi PID=$! trap "kill -INT -$PID" INT @@ -142,7 +142,7 @@ CHILD=${CHILD:-0} QUIET=${QUIET:-0} # check to see if timeout is from busybox? -TIMEOUT_PATH=$(realpath $(which timeout)) +TIMEOUT_PATH=$(realpath "$(which timeout)") if [[ $TIMEOUT_PATH =~ "busybox" ]]; then ISBUSY=1 BUSYTIMEFLAG="-t" @@ -170,7 +170,7 @@ if [[ $CLI != "" ]]; then echoerr "$cmdname: strict mode, refusing to execute subprocess" exit $RESULT fi - exec $CLI + exec "$CLI" else - exit $RESULT + exit "$RESULT" fi From 4154d9111b7042007a1b7a2ce8ea491ef843f78e Mon Sep 17 00:00:00 2001 From: Dobroslaw Zybort Date: Wed, 20 Sep 2017 14:32:08 +0200 Subject: [PATCH 2/2] Fix broken wait script in kafka-init --- kafka-init/wait-for.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kafka-init/wait-for.sh b/kafka-init/wait-for.sh index 854c2eaf1..26c541496 100644 --- a/kafka-init/wait-for.sh +++ b/kafka-init/wait-for.sh @@ -54,12 +54,12 @@ wait_for_wrapper() { # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 if [[ $QUIET -eq 1 ]]; then - timeout "$BUSYTIMEFLAG" "$TIMEOUT" $0 --quiet" --child --host="$HOST" --port="$PORT" --timeout="$TIMEOUT" & + timeout "$BUSYTIMEFLAG" "$TIMEOUT" "$0" --quiet --child --host="$HOST" --port="$PORT" --timeout="$TIMEOUT" & else - timeout "$BUSYTIMEFLAG" "$TIMEOUT" $0 --child --host="$HOST" --port="$PORT" --timeout="$TIMEOUT" & + timeout "$BUSYTIMEFLAG" "$TIMEOUT" "$0" --child --host="$HOST" --port="$PORT" --timeout="$TIMEOUT" & fi PID=$! - trap "kill -INT -$PID" INT + trap 'kill -INT -$PID' INT wait $PID RESULT=$? if [[ $RESULT -ne 0 ]]; then @@ -144,7 +144,7 @@ QUIET=${QUIET:-0} # check to see if timeout is from busybox? # check to see if timeout is from busybox? -TIMEOUT_PATH=$(realpath $(which timeout)) +TIMEOUT_PATH=$(realpath "$(which timeout)") if [[ $TIMEOUT_PATH =~ "busybox" ]]; then ISBUSY=1 BUSYTIMEFLAG="-t"