Skip to content

Commit c0a38f1

Browse files
Cyber-SiKuWine93
authored andcommitted
[fix]playbook/memcached
Signed-off-by: Cyber-SiKu <[email protected]>
1 parent d59ff96 commit c0a38f1

File tree

5 files changed

+80
-6
lines changed

5 files changed

+80
-6
lines changed

playbook/memcached/hosts.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ hosts:
1818
- EXT_PATH=/mnt/memcachefile/cachefile:1024G
1919
- EXT_WBUF_SIZE=8 # size in megabytes of page write buffers.
2020
- EXT_ITEM_AGE=1 # store items idle at least this long (seconds, default: no age limit)
21+
- VERBOSE="v" # v: verbose (print errors/warnings while in event loop)
22+
# vv: very verbose (also print client commands/responses)
23+
# vvv: extremely verbose (internal state transitions)
2124
- host: server-host2
2225
hostname: 10.0.1.2
2326
labels:
@@ -32,6 +35,9 @@ hosts:
3235
- EXT_PATH=/mnt/memcachefile/cachefile:1024G
3336
- EXT_WBUF_SIZE=8 # size in megabytes of page write buffers.
3437
- EXT_ITEM_AGE=1 # store items idle at least this long (seconds, default: no age limit)
38+
- VERBOSE="v" # v: verbose (print errors/warnings while in event loop)
39+
# vv: very verbose (also print client commands/responses)
40+
# vvv: extremely verbose (internal state transitions)
3541
- host: server-host3
3642
hostname: 10.0.1.3
3743
labels:
@@ -46,3 +52,6 @@ hosts:
4652
- EXT_PATH=/mnt/memcachefile/cachefile:1024G
4753
- EXT_WBUF_SIZE=8 # size in megabytes of page write buffers.
4854
- EXT_ITEM_AGE=1 # store items idle at least this long (seconds, default: no age limit)
55+
- VERBOSE="v" # v: verbose (print errors/warnings while in event loop)
56+
# vv: very verbose (also print client commands/responses)
57+
# vvv: extremely verbose (internal state transitions)

playbook/memcached/scripts/clean.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
g_container_name="memcached-"${PORT}
44
g_docker_cmd="${SUDO_ALIAS} docker"
5+
g_rm_cmd="${SUDO_ALIAS} rm -rf"
56

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

37+
rm_cachefile() {
38+
cachefile_path=(${EXT_PATH//:/ })
39+
${g_rm_cmd} ${cachefile_path}
40+
}
41+
3642
precheck
3743
stop_container
44+
rm_cachefile

playbook/memcached/scripts/deploy.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ g_container_name="memcached-"${PORT}
44
g_start_args=""
55
g_docker_cmd="${SUDO_ALIAS} docker"
66
g_lsof_cmd="${SUDO_ALIAS} lsof"
7+
g_rm_cmd="${SUDO_ALIAS} rm -rf"
8+
g_mkdir_cmd="${SUDO_ALIAS} mkdir -p"
9+
g_touch_cmd="${SUDO_ALIAS} touch"
710
g_volume_bind=""
811
g_status=""
912
g_user=""
@@ -37,11 +40,10 @@ precheck() {
3740

3841
# check ext path
3942
if [ "${EXT_PATH}" ]; then
40-
volume_path=(${EXT_PATH//:/ })
41-
if [ -f ${volume_path} ]; then
42-
die "no file[${volume_path}]"
43-
exit 1
44-
fi
43+
cachefile_path=(${EXT_PATH//:/ })
44+
${g_rm_cmd} ${cachefile_path}
45+
${g_mkdir_cmd} $(dirname ${cachefile_path})
46+
${g_touch_cmd} ${cachefile_path}
4547
fi
4648
}
4749

@@ -74,6 +76,9 @@ init() {
7476
if [ "${EXT_ITEM_AGE}" ]; then
7577
g_start_args="${g_start_args} --extended ext_item_age=${EXT_ITEM_AGE}"
7678
fi
79+
if [ "${VERBOSE}" ];then
80+
g_start_args="${g_start_args} -${VERBOSE}"
81+
fi
7782
}
7883

7984
create_container() {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
g_container_name="memcached-"${PORT}
4+
g_docker_cmd="${SUDO_ALIAS} docker"
5+
g_rm_cmd="${SUDO_ALIAS} rm -rf"
6+
g_mkdir_cmd="${SUDO_ALIAS} mkdir -p"
7+
g_touch_cmd="${SUDO_ALIAS} touch"
8+
g_status="running"
9+
10+
function msg() {
11+
printf '%b' "$1" >&2
12+
}
13+
14+
function success() {
15+
msg "\33[32m[✔]\33[0m ${1}${2}"
16+
}
17+
18+
function die() {
19+
msg "\33[31m[✘]\33[0m ${1}${2}"
20+
exit 1
21+
}
22+
23+
precheck() {
24+
# check ext path
25+
get_status_container
26+
if [ "${EXT_PATH}" ] && [ ${g_status} != "running" ]; then
27+
cachefile_path=(${EXT_PATH//:/ })
28+
${g_rm_cmd} ${cachefile_path}
29+
${g_mkdir_cmd} $(dirname ${cachefile_path})
30+
${g_touch_cmd} ${cachefile_path}
31+
fi
32+
}
33+
34+
start_container() {
35+
${g_docker_cmd} start ${g_container_name} >& /dev/null
36+
success "start container[${g_container_name}]\n"
37+
}
38+
39+
get_status_container() {
40+
g_status=`${g_docker_cmd} inspect --format='{{.State.Status}}' ${g_container_name}`
41+
}
42+
43+
precheck
44+
start_container

playbook/memcached/scripts/status.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ g_start_args=""
55
g_docker_cmd="${SUDO_ALIAS} docker"
66
g_volume_bind=""
77
g_container_id=""
8+
g_status="running"
89

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

39+
get_status_container() {
40+
g_status=`${g_docker_cmd} inspect --format='{{.State.Status}}' ${g_container_name}`
41+
if [ ${g_status} != "running" ]; then
42+
exit 1
43+
fi
44+
}
45+
3846
precheck
47+
show_ip_port
3948
show_info_container
40-
show_ip_port
49+
get_status_container

0 commit comments

Comments
 (0)