Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support memcached #67

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
postgresql-12.4.sh,
postgresql-13.2.sh,
redis-6.2.14.sh,
redis-7.2.5.sh
redis-7.2.5.sh,
memcached-1.6.31.sh
]
steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
/redis/redis-*.tar.gz
/mongodb/versions
/mongodb/mongodb-*.tar.gz
/memcached/versions
/memcached/memcached-*.tar.gz
/memcached/libevent-*.tar.gz
.DS_Store
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cd dbdb

## MySQL

### Manage MySQL Server on localhost
### Commands for MySQL Server

```
./mysql/{create|start|stop|restart|port|status|connect|delete}.sh {name} {mysqlVersion} {port}
Expand Down Expand Up @@ -61,7 +61,7 @@ cd dbdb

## PostgreSQL

### Manage PostgreSQL Server on localhost
### Commands for PostgreSQL Server

```
./postgresql/{create|start|stop|restart|port|status|connect|delete}.sh {name} {postgresqlVersion} {port}
Expand Down Expand Up @@ -89,7 +89,7 @@ cd dbdb

## Redis

### Manage Redis Server on localhost
### Commands for Redis Server

```
./redis/{create|start|stop|restart|port|status|connect|delete}.sh {name} {redisVersion} {port}
Expand Down Expand Up @@ -118,7 +118,7 @@ cd dbdb

## MongoDB

### Manage MongoDB Server on localhost
### Commands for MongoDB Server

```
./mongodb/{create|start|stop|restart|port|status|connect|delete}.sh {name} {mongodbVersion} {port}
Expand All @@ -141,6 +141,32 @@ cd dbdb

</div></details>

<details><summary>Memcached</summary><div>

## Memcached

### Commands for Memcached Server

```
./memcached/{create|start|stop|restart|port|status|connect|delete}.sh {name} {memcachedVersion} {port}

# e.g.
./memcached/create.sh memcached1 1.6.31 11211
./memcached/start.sh memcached1
./memcached/stop.sh memcached1
./memcached/restart.sh memcached1
./memcached/port.sh memcached1
./memcached/status.sh memcached1
./memcached/connect.sh memcached1
./memcached/delete.sh memcached1
```

### Supported Memcached Versions

- 1.6.31

</div></details>

## Tips

### Create with random port.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0.3
v2.1.0
14 changes: 8 additions & 6 deletions dbdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ installDir=$(getInstallDir)

normalOutputs=""
jsonOutputs=""
dbTypes=(mongodb mysql postgresql redis)
dbTypes=(mongodb mysql postgresql redis memcached)
for dbType in "${dbTypes[@]}"; do
for dbVersion in $(ls "$installDir/$dbType/versions" 2>/dev/null); do
if [ -d "$installDir/$dbType/versions/$dbVersion" ]; then
Expand Down Expand Up @@ -85,13 +85,15 @@ for dbType in "${dbTypes[@]}"; do

# confName
if [ "$dbType" = "mongodb" ];then
confName=mongod.conf
confName="$installDir/$dbType/versions/$dbVersion/datadir/$dbServerName/mongod.conf"
elif [ "$dbType" = "mysql" ];then
confName=my.cnf
confName="$installDir/$dbType/versions/$dbVersion/datadir/$dbServerName/my.cnf"
elif [ "$dbType" = "postgresql" ];then
confName=postgresql.conf
confName="$installDir/$dbType/versions/$dbVersion/datadir/$dbServerName/postgresql.conf"
elif [ "$dbType" = "redis" ];then
confName=redis.conf
confName="$installDir/$dbType/versions/$dbVersion/datadir/$dbServerName/redis.conf"
elif [ "$dbType" = "memcached" ];then
confName=""
fi

# jsonOutputs
Expand All @@ -105,7 +107,7 @@ for dbType in "${dbTypes[@]}"; do
\"commandPath\": \"$currentDir/$dbType/\",
\"availableCommands\": $availableCommands,
\"dataDir\": \"$installDir/$dbType/versions/$dbVersion/datadir/$dbServerName\",
\"confPath\": \"$installDir/$dbType/versions/$dbVersion/datadir/$dbServerName/$confName\"
\"confPath\": \"$confName\"
},"
fi
fi
Expand Down
2 changes: 2 additions & 0 deletions lib/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ getType() {
echo "postgresql"
elif [[ "$(getCurrentDir)" == *"/dbdb/redis"* ]]; then
echo "redis"
elif [[ "$(getCurrentDir)" == *"/dbdb/memcached"* ]]; then
echo "memcached"
else
echo "unknown database type" 1>&2
exit 1
Expand Down
23 changes: 23 additions & 0 deletions memcached/connect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -eu

currentDir="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
cd $currentDir
. functions.sh

optName=$1

exitIfNotExistVersion "$optName"
optVersion=$(getVersionByName "$optName")

exitIfNotExistPortFile "$optName" "$optVersion"
optPort=$(getPortByName "$optName" "$optVersion")

installDir=$(getInstallDir $(getType))
dir=$installDir/versions/$optVersion

exitIfNotExistDir $dir/datadir/$optName
exitIfNotRunningPort $optPort

echo "You can connect to the server by executing the following command."
echo "telnet 127.0.0.1 $optPort"
40 changes: 40 additions & 0 deletions memcached/create-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# 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_ >&2
usage : $currentDir/create-start.sh {Name} {MemcachedVersion} {Port}
e.g. : $currentDir/create-start.sh memcached16-foo 1.6.31 11211
e.g. : $currentDir/create-start.sh memcached16-bar 1.6.31 11212
e.g. : $currentDir/create-start.sh memcached16-baz 1.6.31 random
_EOT_
exit 1
fi

./create.sh -f "$format" $1 $2 $3 > /dev/null
set -eu
./start.sh -f "$format" $1
105 changes: 105 additions & 0 deletions memcached/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/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_ >&2
usage : $currentDir/create.sh {Name} {MemcachedVersion} {Port}
e.g. : $currentDir/create.sh memcached16-foo 1.6.31 11211
e.g. : $currentDir/create.sh memcached16-bar 1.6.31 11212
e.g. : $currentDir/create.sh memcached16-baz 1.6.31 random
_EOT_
exit 1
fi

. functions.sh

os=$(getOS)
optName=$1
optVersion=$2
optPort=$(getOptPort $3)
optFileName=memcached-${optVersion}-${os}
installDir=$(getInstallDir $(getType))
dir=$installDir/versions/$optVersion

mkdir -p "$dir"
cd $dir

exitIfDuplicatedName $optName
exitIfExistDir $dir/datadir/$optName
exitIfRunningPort $optPort

# libevent
if [ ! -e $dir/share/lib ]; then
cd $dir
getUrlFileAs https://dbdb.shueisha-artsdigital.co.jp/memcached/libevent-2.1.12-stable.tar.gz libevent-2.1.12-stable.tar.gz
echo "Installing libevent..." 1>&2
tar zxf libevent-2.1.12-stable.tar.gz
cd $dir/libevent-2.1.12-stable
./configure --prefix=$(pwd)/../share > /dev/null 2>&1
make > /dev/null 2>&1
make install > /dev/null 2>&1
cd $dir
fi

# memcached
getUrlFileAs https://dbdb.shueisha-artsdigital.co.jp/memcached/$optFileName.tar.gz $optFileName.tar.gz
mkdir -p $dir/datadir/$optName
extractFile $dir $optFileName
if [ ! -e $dir/basedir/bin/memcached ]; then
echo "Installing Memcached..." 1>&2
cd $dir/basedir
./configure --prefix=$(pwd) --with-libevent=$(pwd)/../share > /dev/null 2>&1
make > /dev/null 2>&1
make install > /dev/null 2>&1
fi

echo $optPort > $dir/datadir/$optName/memcached.port.init

commands=$(getCommands $optName $optVersion $optPort $format)

normalOutputs=""
normalOutputs="${normalOutputs}Memcached Successfully created. $optName $optVersion $optPort\n"
normalOutputs="${normalOutputs}$commands\n"

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

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

# 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

optName=$1

exitIfNotExistVersion "$optName"
optVersion=$(getVersionByName "$optName")

exitIfNotExistPortFile "$optName" "$optVersion"
optPort=$(getPortByName "$optName" "$optVersion")

installDir=$(getInstallDir $(getType))
dir=$installDir/versions/$optVersion

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

set -eu
exitIfNotExistDir $dir/datadir/$optName
exitIfRunningPort $optPort
[ -d "$dir/datadir/$optName" ] && rm -fr $dir/datadir/$optName

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

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

# Output
if [ "$format" = "json" ]; then
echo -e "${jsonOutputs}"
else
echo -e "${normalOutputs}"
fi
1 change: 1 addition & 0 deletions memcached/functions.sh
Loading