Skip to content

Commit f9830eb

Browse files
Cyber-SiKuWine93
authored andcommitted
playbook(memcache): support sudo alias.
Signed-off-by: Cyber-SiKu <[email protected]>
1 parent e771538 commit f9830eb

File tree

5 files changed

+83
-6
lines changed

5 files changed

+83
-6
lines changed

playbook/memcached/hosts.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ hosts:
99
labels:
1010
- memcached
1111
envs:
12+
- SUDO_ALIAS=sudo
1213
- IMAGE=memcached:1.6.17
1314
- LISTEN=10.0.1.1
1415
- PORT=11211
@@ -18,11 +19,15 @@ hosts:
1819
- EXT_PATH=/mnt/memcachefile/cachefile:1024G
1920
- EXT_WBUF_SIZE=8 # size in megabytes of page write buffers.
2021
- EXT_ITEM_AGE=1 # store items idle at least this long (seconds, default: no age limit)
22+
- VERBOSE="v" # v: verbose (print errors/warnings while in event loop)
23+
# vv: very verbose (also print client commands/responses)
24+
# vvv: extremely verbose (internal state transitions)
2125
- host: server-host2
2226
hostname: 10.0.1.2
2327
labels:
2428
- memcached
2529
envs:
30+
- SUDO_ALIAS=sudo
2631
- IMAGE=memcached:1.6.17
2732
- LISTEN=10.0.1.2
2833
- PORT=11211
@@ -32,11 +37,15 @@ hosts:
3237
- EXT_PATH=/mnt/memcachefile/cachefile:1024G
3338
- EXT_WBUF_SIZE=8 # size in megabytes of page write buffers.
3439
- EXT_ITEM_AGE=1 # store items idle at least this long (seconds, default: no age limit)
40+
- VERBOSE="v" # v: verbose (print errors/warnings while in event loop)
41+
# vv: very verbose (also print client commands/responses)
42+
# vvv: extremely verbose (internal state transitions)
3543
- host: server-host3
3644
hostname: 10.0.1.3
3745
labels:
3846
- memcached
3947
envs:
48+
- SUDO_ALIAS=sudo
4049
- IMAGE=memcached:1.6.17
4150
- LISTEN=10.0.1.3
4251
- PORT=11211
@@ -46,3 +55,6 @@ hosts:
4655
- EXT_PATH=/mnt/memcachefile/cachefile:1024G
4756
- EXT_WBUF_SIZE=8 # size in megabytes of page write buffers.
4857
- EXT_ITEM_AGE=1 # store items idle at least this long (seconds, default: no age limit)
58+
- VERBOSE="v" # v: verbose (print errors/warnings while in event loop)
59+
# vv: very verbose (also print client commands/responses)
60+
# 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)