Skip to content

Commit

Permalink
Json for status command
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki777 committed May 6, 2023
1 parent 7805f87 commit 3e21b5b
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 9 deletions.
42 changes: 40 additions & 2 deletions mongodb/status.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
41 changes: 39 additions & 2 deletions mysql/status.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
44 changes: 41 additions & 3 deletions postgresql/status.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
41 changes: 39 additions & 2 deletions redis/status.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

0 comments on commit 3e21b5b

Please sign in to comment.