Skip to content

Commit

Permalink
[fix]playbook/memcached
Browse files Browse the repository at this point in the history
Signed-off-by: Cyber-SiKu <[email protected]>
  • Loading branch information
Cyber-SiKu authored and Wine93 committed Feb 22, 2023
1 parent d59ff96 commit c0a38f1
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 6 deletions.
9 changes: 9 additions & 0 deletions playbook/memcached/hosts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ hosts:
- EXT_PATH=/mnt/memcachefile/cachefile:1024G
- EXT_WBUF_SIZE=8 # size in megabytes of page write buffers.
- EXT_ITEM_AGE=1 # store items idle at least this long (seconds, default: no age limit)
- VERBOSE="v" # v: verbose (print errors/warnings while in event loop)
# vv: very verbose (also print client commands/responses)
# vvv: extremely verbose (internal state transitions)
- host: server-host2
hostname: 10.0.1.2
labels:
Expand All @@ -32,6 +35,9 @@ hosts:
- EXT_PATH=/mnt/memcachefile/cachefile:1024G
- EXT_WBUF_SIZE=8 # size in megabytes of page write buffers.
- EXT_ITEM_AGE=1 # store items idle at least this long (seconds, default: no age limit)
- VERBOSE="v" # v: verbose (print errors/warnings while in event loop)
# vv: very verbose (also print client commands/responses)
# vvv: extremely verbose (internal state transitions)
- host: server-host3
hostname: 10.0.1.3
labels:
Expand All @@ -46,3 +52,6 @@ hosts:
- EXT_PATH=/mnt/memcachefile/cachefile:1024G
- EXT_WBUF_SIZE=8 # size in megabytes of page write buffers.
- EXT_ITEM_AGE=1 # store items idle at least this long (seconds, default: no age limit)
- VERBOSE="v" # v: verbose (print errors/warnings while in event loop)
# vv: very verbose (also print client commands/responses)
# vvv: extremely verbose (internal state transitions)
7 changes: 7 additions & 0 deletions playbook/memcached/scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

g_container_name="memcached-"${PORT}
g_docker_cmd="${SUDO_ALIAS} docker"
g_rm_cmd="${SUDO_ALIAS} rm -rf"

function msg() {
printf '%b' "$1" >&2
Expand Down Expand Up @@ -33,5 +34,11 @@ stop_container() {
success "rm container[${g_container_name}]\n"
}

rm_cachefile() {
cachefile_path=(${EXT_PATH//:/ })
${g_rm_cmd} ${cachefile_path}
}

precheck
stop_container
rm_cachefile
15 changes: 10 additions & 5 deletions playbook/memcached/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ g_container_name="memcached-"${PORT}
g_start_args=""
g_docker_cmd="${SUDO_ALIAS} docker"
g_lsof_cmd="${SUDO_ALIAS} lsof"
g_rm_cmd="${SUDO_ALIAS} rm -rf"
g_mkdir_cmd="${SUDO_ALIAS} mkdir -p"
g_touch_cmd="${SUDO_ALIAS} touch"
g_volume_bind=""
g_status=""
g_user=""
Expand Down Expand Up @@ -37,11 +40,10 @@ precheck() {

# check ext path
if [ "${EXT_PATH}" ]; then
volume_path=(${EXT_PATH//:/ })
if [ -f ${volume_path} ]; then
die "no file[${volume_path}]"
exit 1
fi
cachefile_path=(${EXT_PATH//:/ })
${g_rm_cmd} ${cachefile_path}
${g_mkdir_cmd} $(dirname ${cachefile_path})
${g_touch_cmd} ${cachefile_path}
fi
}

Expand Down Expand Up @@ -74,6 +76,9 @@ init() {
if [ "${EXT_ITEM_AGE}" ]; then
g_start_args="${g_start_args} --extended ext_item_age=${EXT_ITEM_AGE}"
fi
if [ "${VERBOSE}" ];then
g_start_args="${g_start_args} -${VERBOSE}"
fi
}

create_container() {
Expand Down
44 changes: 44 additions & 0 deletions playbook/memcached/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

g_container_name="memcached-"${PORT}
g_docker_cmd="${SUDO_ALIAS} docker"
g_rm_cmd="${SUDO_ALIAS} rm -rf"
g_mkdir_cmd="${SUDO_ALIAS} mkdir -p"
g_touch_cmd="${SUDO_ALIAS} touch"
g_status="running"

function msg() {
printf '%b' "$1" >&2
}

function success() {
msg "\33[32m[✔]\33[0m ${1}${2}"
}

function die() {
msg "\33[31m[✘]\33[0m ${1}${2}"
exit 1
}

precheck() {
# check ext path
get_status_container
if [ "${EXT_PATH}" ] && [ ${g_status} != "running" ]; then
cachefile_path=(${EXT_PATH//:/ })
${g_rm_cmd} ${cachefile_path}
${g_mkdir_cmd} $(dirname ${cachefile_path})
${g_touch_cmd} ${cachefile_path}
fi
}

start_container() {
${g_docker_cmd} start ${g_container_name} >& /dev/null
success "start container[${g_container_name}]\n"
}

get_status_container() {
g_status=`${g_docker_cmd} inspect --format='{{.State.Status}}' ${g_container_name}`
}

precheck
start_container
11 changes: 10 additions & 1 deletion playbook/memcached/scripts/status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ g_start_args=""
g_docker_cmd="${SUDO_ALIAS} docker"
g_volume_bind=""
g_container_id=""
g_status="running"

function msg() {
printf '%b' "$1" >&2
Expand Down Expand Up @@ -35,6 +36,14 @@ show_ip_port() {
printf "memcached addr:\t%s:%d\n" ${LISTEN} ${PORT}
}

get_status_container() {
g_status=`${g_docker_cmd} inspect --format='{{.State.Status}}' ${g_container_name}`
if [ ${g_status} != "running" ]; then
exit 1
fi
}

precheck
show_ip_port
show_info_container
show_ip_port
get_status_container

0 comments on commit c0a38f1

Please sign in to comment.