diff --git a/mongodb/status.sh b/mongodb/status.sh index 764d1b0..ccc9747 100755 --- a/mongodb/status.sh +++ b/mongodb/status.sh @@ -1,7 +1,29 @@ #!/bin/bash set -eu -currentDir="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +# Get format option +format="" +while getopts ":f:" opt; do + case ${opt} in + f) + format="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" 1>&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." 1>&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +currentDir="$( + cd "$(dirname "$0")" >/dev/null 2>&1 + pwd -P +)" cd $currentDir . functions.sh @@ -17,4 +39,20 @@ dir=$currentDir/versions/$optVersion exitIfNotExistDir $dir/datadir/$optName exitIfNotRunningPort $optPort -$dir/basedir/bin/mongo --port $optPort --eval "db.serverStatus()" + +status=$($dir/basedir/bin/mongo --port $optPort --quiet --eval "db.serverStatus().ok") + +normalOutputs="" +normalOutputs="${normalOutputs}$status" + +jsonOutputs="" +jsonOutputs="$jsonOutputs{ + \"status\": \"$status\" +}" + +# Output +if [ "$format" = "json" ]; then + echo -e "${jsonOutputs}" +else + echo -e "${normalOutputs}" +fi diff --git a/mysql/status.sh b/mysql/status.sh index 13b195d..0286609 100755 --- a/mysql/status.sh +++ b/mysql/status.sh @@ -1,7 +1,29 @@ #!/bin/bash set -eu -currentDir="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +# Get format option +format="" +while getopts ":f:" opt; do + case ${opt} in + f) + format="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" 1>&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." 1>&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +currentDir="$( + cd "$(dirname "$0")" >/dev/null 2>&1 + pwd -P +)" cd $currentDir . functions.sh @@ -18,4 +40,19 @@ dir=$currentDir/versions/$optVersion exitIfNotExistDir $dir/datadir/$optName exitIfNotRunningPort $optPort -$dir/basedir/bin/mysqladmin --user=root --host=localhost --port=$optPort --socket=$optSocket status +status=$($dir/basedir/bin/mysqladmin --user=root --host=localhost --port=$optPort --socket=$optSocket status) + +normalOutputs="" +normalOutputs="${normalOutputs}$status" + +jsonOutputs="" +jsonOutputs="$jsonOutputs{ + \"status\": \"$status\" +}" + +# Output +if [ "$format" = "json" ]; then + echo -e "${jsonOutputs}" +else + echo -e "${normalOutputs}" +fi diff --git a/postgresql/status.sh b/postgresql/status.sh index b805c0e..7bf3d49 100755 --- a/postgresql/status.sh +++ b/postgresql/status.sh @@ -1,7 +1,29 @@ #!/bin/bash set -eu -currentDir="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +# Get format option +format="" +while getopts ":f:" opt; do + case ${opt} in + f) + format="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" 1>&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." 1>&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +currentDir="$( + cd "$(dirname "$0")" >/dev/null 2>&1 + pwd -P +)" cd $currentDir . functions.sh @@ -17,8 +39,24 @@ dir=$currentDir/versions/$optVersion exitIfNotExistDir $dir/datadir/$optName exitIfNotRunningPort $optPort -$dir/basedir/bin/pg_ctl \ +status=$($dir/basedir/bin/pg_ctl \ --pgdata $dir/datadir/$optName \ --log $dir/datadir/$optName/postgres.log \ -o "-p $optPort" \ - status + --silent \ + status|grep "server is") + +normalOutputs="" +normalOutputs="${normalOutputs}$status" + +jsonOutputs="" +jsonOutputs="$jsonOutputs{ + \"status\": \"$status\" +}" + +# Output +if [ "$format" = "json" ]; then + echo -e "${jsonOutputs}" +else + echo -e "${normalOutputs}" +fi diff --git a/redis/status.sh b/redis/status.sh index 19d3dda..803e312 100755 --- a/redis/status.sh +++ b/redis/status.sh @@ -1,7 +1,29 @@ #!/bin/bash set -eu -currentDir="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +# Get format option +format="" +while getopts ":f:" opt; do + case ${opt} in + f) + format="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" 1>&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." 1>&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +currentDir="$( + cd "$(dirname "$0")" >/dev/null 2>&1 + pwd -P +)" cd $currentDir . functions.sh @@ -18,4 +40,19 @@ dir=$currentDir/versions/$optVersion exitIfNotExistDir $dir/datadir/$optName exitIfNotRunningPort $optPort -$dir/basedir/src/redis-cli -p $optPort ping +status=$($dir/basedir/src/redis-cli -p $optPort ping) + +normalOutputs="" +normalOutputs="${normalOutputs}$status" + +jsonOutputs="" +jsonOutputs="$jsonOutputs{ + \"status\": \"$status\" +}" + +# Output +if [ "$format" = "json" ]; then + echo -e "${jsonOutputs}" +else + echo -e "${normalOutputs}" +fi