Skip to content

Commit

Permalink
Merge pull request #53 from pj8/postgresql-json
Browse files Browse the repository at this point in the history
Support json on mongodb and postgresql
  • Loading branch information
yuki777 committed May 6, 2023
2 parents e0f9f0e + c01ae49 commit 1d3f0c1
Show file tree
Hide file tree
Showing 28 changed files with 904 additions and 240 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.2.10
v1.2.11
38 changes: 35 additions & 3 deletions mongodb/create-start.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
#!/bin/bash

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
./create.sh $1 $2 $3

if [ $# -eq 0 ]; then
cat <<_EOT_ >&2
usage : $currentDir/create.sh {Name} {MongodbVersion} {Port}
e.g. : $currentDir/create.sh mongo4-foo 4.4.10 27017
e.g. : $currentDir/create.sh mongo5-bar 5.0.3 37017
e.g. : $currentDir/create.sh mongo5-baz 5.0.3 random
_EOT_
exit 1
fi

./create.sh -f "$format" $1 $2 $3 > /dev/null
set -eu
./start.sh $1
./start.sh -f "$format" $1
58 changes: 49 additions & 9 deletions mongodb/create.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
#!/bin/bash
set -eu

# 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

if [ $# -eq 0 ]; then
cat <<_EOT_
# usage : $currentDir/create.sh {Name} {MongodbVersion} {Port}
# e.g. : $currentDir/create.sh mongo4-foo 4.4.10 27017
# e.g. : $currentDir/create.sh mongo5-bar 5.0.3 37017
# e.g. : $currentDir/create.sh mongo5-baz 5.0.3 random
cat <<_EOT_ >&2
usage : $currentDir/create.sh {Name} {MongodbVersion} {Port}
e.g. : $currentDir/create.sh mongo4-foo 4.4.10 27017
e.g. : $currentDir/create.sh mongo5-bar 5.0.3 37017
e.g. : $currentDir/create.sh mongo5-baz 5.0.3 random
_EOT_
exit 1
fi
Expand All @@ -37,10 +56,31 @@ mkdir -p $dir/datadir/$optName
extractFile $dir $optFileName

echo $optPort >$dir/datadir/$optName/mongodb.port.init
echo "#mongod.conf" > $dir/datadir/$optName/mongod.conf

echo "#mongod.conf" >$dir/datadir/$optName/mongod.conf
echo "mongod.conf is here. $dir/datadir/$optName/mongod.conf"

echo MongoDB Successfully created. $optName $optVersion $optPort
cd $currentDir
getCommands $optName $optVersion $optPort
commands=$(getCommands $optName $optVersion $optPort $format)

normalOutputs=""
normalOutputs="${normalOutputs}mongod.conf is here. $dir/datadir/$optName/mongod.conf\n"
normalOutputs="${normalOutputs}MongoDB Successfully created. $optName $optVersion $optPort\n"
normalOutputs="${normalOutputs}$commands\n"

jsonOutputs=""
jsonOutputs="$jsonOutputs{
\"message\": \"MongoDB Successfully created.\",
\"name\": \"$optName\",
\"type\": \"mongodb\",
\"version\": \"$optVersion\",
\"port\": \"$optPort\",
\"dataDir\": \"$dir/datadir/$optName\",
\"confPath\": \"$dir/datadir/$optName/mongod.conf\"
}"

# Output
if [ "$format" = "json" ]; then
echo -e "${jsonOutputs}"
else
echo -e "${normalOutputs}"
fi
48 changes: 45 additions & 3 deletions mongodb/delete.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#!/bin/bash

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 @@ -14,11 +36,31 @@ optPort=$(getPortByName "$optName" "$optVersion")

dir=$currentDir/versions/$optVersion

./stop.sh $optName $optVersion $optPort
./stop.sh -f "$format" $optName $optVersion $optPort > /dev/null
sleep 1

set -eu
exitIfNotExistDir $dir/datadir/$optName
exitIfRunningPort $optPort
[ -d "$dir/datadir/$optName" ] && rm -fr $dir/datadir/$optName
echo MongoDB Successfully deleted. $optName $optVersion $optPort

normalOutputs=""
normalOutputs="${normalOutputs}MongoDB Successfully deleted. $optName $optVersion $optPort"

jsonOutputs=""
jsonOutputs="$jsonOutputs{
\"message\": \"MongoDB Successfully deleted.\",
\"name\": \"$optName\",
\"type\": \"mongodb\",
\"version\": \"$optVersion\",
\"port\": \"$optPort\",
\"dataDir\": \"$dir/datadir/$optName\",
\"confPath\": \"$dir/datadir/$optName/mongod.conf\"
}"

# Output
if [ "$format" = "json" ]; then
echo -e "${jsonOutputs}"
else
echo -e "${normalOutputs}"
fi
39 changes: 37 additions & 2 deletions mongodb/port.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 @@ -21,4 +43,17 @@ optVersion=$(getVersionByName "$optName")
exitIfNotExistPortFile "$optName" "$optVersion"
optPort=$(getPortByName "$optName" "$optVersion")

echo "$optPort"
normalOutputs=""
normalOutputs="${normalOutputs}$optPort"

jsonOutputs=""
jsonOutputs="$jsonOutputs{
\"port\": \"$optPort\"
}"

# Output
if [ "$format" = "json" ]; then
echo -e "${jsonOutputs}"
else
echo -e "${normalOutputs}"
fi
28 changes: 25 additions & 3 deletions mongodb/restart.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
#!/bin/bash

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
./stop.sh $1
./stop.sh -f "$format" $1 > /dev/null

sleep 1

set -eu
./start.sh $1
./start.sh -f "$format" $1
50 changes: 46 additions & 4 deletions mongodb/start.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 @@ -25,7 +47,27 @@ $dir/basedir/bin/mongod \
--logpath $dir/datadir/$optName/mongodb.log \
--pidfilepath $dir/datadir/$optName/mongodb.pid \
--port $optPort \
--fork
--fork 1>&2
echo $optPort > $dir/datadir/$optName/mongodb.port
echo "Your config file is located $dir/datadir/$optName/mongod.conf"
echo MongoDB Successfully started. $optName $optVersion $optPort

normalOutputs=""
normalOutputs="${normalOutputs}MongoDB Successfully started. $optName $optVersion $optPort\n"
normalOutputs="${normalOutputs}Your config file is located $dir/datadir/$optName/mongodb.conf"

jsonOutputs=""
jsonOutputs="$jsonOutputs{
\"message\": \"MongoDB Successfully started.\",
\"name\": \"$optName\",
\"type\": \"mongodb\",
\"version\": \"$optVersion\",
\"port\": \"$optPort\",
\"dataDir\": \"$dir/datadir/$optName\",
\"confPath\": \"$dir/datadir/$optName/mongod.conf\"
}"

# Output
if [ "$format" = "json" ]; then
echo -e "${jsonOutputs}"
else
echo -e "${normalOutputs}"
fi
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
Loading

0 comments on commit 1d3f0c1

Please sign in to comment.