Signed-off-by: Cao Xueliang caoxl78320@163.com --- container/etcd/Dockerfile | 6 ++++++ container/etcd/entry.sh | 8 ++++++++ container/etcd/etcd_compact.sh | 7 +++++++ container/etcd/start | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 container/etcd/entry.sh create mode 100755 container/etcd/etcd_compact.sh
diff --git a/container/etcd/Dockerfile b/container/etcd/Dockerfile index b3957e8..f4746ab 100644 --- a/container/etcd/Dockerfile +++ b/container/etcd/Dockerfile @@ -14,3 +14,9 @@ RUN sed -ri.origin 's|^https?://dl-cdn.alpinelinux.org|http://mirrors.huaweiclou rm -Rf etcd-${VERSION}-linux-arm64* /var/cache/apk/*
VOLUME /data + +COPY etcd_compact.sh / +COPY entry.sh / +RUN echo '* 0 * * * /test.sh > /etcd_compact.log 2>&1' >> /var/spool/cron/crontabs/root + +ENTRYPOINT ["/entry.sh"] diff --git a/container/etcd/entry.sh b/container/etcd/entry.sh new file mode 100755 index 0000000..4bfea1e --- /dev/null +++ b/container/etcd/entry.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +crond +/bin/etcd +exec "$@" + diff --git a/container/etcd/etcd_compact.sh b/container/etcd/etcd_compact.sh new file mode 100755 index 0000000..acc20d0 --- /dev/null +++ b/container/etcd/etcd_compact.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +rev=$(etcdctl endpoint status --write-out="json"|egrep -o '"revision":[0-9]*'|egrep -o '[0-9].*') +etcdctl compact $rev && etcdctl defrag + diff --git a/container/etcd/start b/container/etcd/start index db94833..6d32cd2 100755 --- a/container/etcd/start +++ b/container/etcd/start @@ -14,10 +14,10 @@ cmd=( -p 4001:4001 -p 7001:7001 -v /srv/etcd/dir:/data + -v /etc/localtime:/etc/localtime:ro -e ETCD_UNSUPPORTED_ARCH=arm64 --name etcd-server etcd-v3.4.15:alpine - /bin/etcd --name node-1 --data-dir /data --initial-cluster-state new