File tree Expand file tree Collapse file tree 5 files changed +80
-6
lines changed Expand file tree Collapse file tree 5 files changed +80
-6
lines changed Original file line number Diff line number Diff line change 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 :
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 :
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)
Original file line number Diff line number Diff line change 22
33g_container_name=" memcached-" ${PORT}
44g_docker_cmd=" ${SUDO_ALIAS} docker"
5+ g_rm_cmd=" ${SUDO_ALIAS} rm -rf"
56
67function 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+
3642precheck
3743stop_container
44+ rm_cachefile
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ g_container_name="memcached-"${PORT}
44g_start_args=" "
55g_docker_cmd=" ${SUDO_ALIAS} docker"
66g_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"
710g_volume_bind=" "
811g_status=" "
912g_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
7984create_container () {
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ g_start_args=""
55g_docker_cmd=" ${SUDO_ALIAS} docker"
66g_volume_bind=" "
77g_container_id=" "
8+ g_status=" running"
89
910function 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+
3846precheck
47+ show_ip_port
3948show_info_container
40- show_ip_port
49+ get_status_container
You can’t perform that action at this time.
0 commit comments