update
This commit is contained in:
56
keepalived/ADD/ccmd
Executable file
56
keepalived/ADD/ccmd
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
|
||||
##################################################
|
||||
# Docker #
|
||||
# - --privileged #
|
||||
# - --net host #
|
||||
# Mount dir #
|
||||
# - /etc/keepalived/ #
|
||||
# - LOG_DIR #
|
||||
##################################################
|
||||
|
||||
set -euo pipefail
|
||||
export LANG=en_US.UTF-8
|
||||
trap Quit EXIT
|
||||
|
||||
PIDS=
|
||||
GOT_SIGTERM=
|
||||
LOG_DIR='/var/log/keepalived'
|
||||
|
||||
function Print {
|
||||
local file=/dev/null
|
||||
[ '-f' = "$1" ] && file=$2 && shift && shift
|
||||
date +"[%F %T] $*" | tee -a $file
|
||||
}
|
||||
|
||||
function Quit {
|
||||
Print killing keepalived ...
|
||||
while :; do
|
||||
pkill -f keepalived && Print killing keepalived ... || break
|
||||
sleep 1
|
||||
done
|
||||
Print Container stopped.
|
||||
test -n "$GOT_SIGTERM"
|
||||
}
|
||||
|
||||
function StartProc {
|
||||
Print Start keeplived ...
|
||||
rm -rf /var/run/keepalived
|
||||
keepalived -f /etc/keepalived/keepalived.conf -lDGn &>> $LOG_DIR/keepalived.log &
|
||||
PIDS="$PIDS $!"
|
||||
}
|
||||
|
||||
function Main {
|
||||
local pid=
|
||||
StartProc
|
||||
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
|
||||
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
|
||||
for pid in $PIDS; do
|
||||
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Start here
|
||||
Main
|
||||
|
11
keepalived/Dockerfile
Normal file
11
keepalived/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
ARG ARCH
|
||||
FROM harbor.colben.cn/general/alpine$ARCH
|
||||
MAINTAINER Colben colbenlee@gmail.com
|
||||
ADD --chown=root:root /ADD/ /opt/
|
||||
RUN apk update \
|
||||
&& apk add --no-cache keepalived \
|
||||
&& mkdir -p /var/log/keepalived \
|
||||
&& rm -f /etc/keepalived/keepalived.conf \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
CMD ["/opt/ccmd"]
|
||||
|
13
keepalived/README.md
Normal file
13
keepalived/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# 构建 keepalived 镜像
|
||||
|
||||
## 定制
|
||||
- 安装 keepalived
|
||||
- docker 参数: --privileged --net host
|
||||
|
||||
## 外挂目录和文件
|
||||
- /etc/keepalived: keepalived 配置目录
|
||||
- /var/log/keepalived: keepalived 日志目录
|
||||
|
||||
## 案例
|
||||
- [/OPS/GeneralDocker/mysql/Demo/TowMasterNodes/](/OPS/GeneralDocker/mysql/Demo/TowMasterNodes/): 两台 mysql 高可用,不抢占模式
|
||||
|
67
keepalived/keepalived.sh
Executable file
67
keepalived/keepalived.sh
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
#=========================================
|
||||
# Author : colben
|
||||
#=========================================
|
||||
|
||||
set -euo pipefail
|
||||
export LANG=en_US.UTF-8
|
||||
trap Quit EXIT
|
||||
|
||||
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
|
||||
ROOT_DIR="$(cd $(dirname $0) && pwd)"
|
||||
IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:latest"
|
||||
|
||||
if [ -t 0 ]; then
|
||||
function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; }
|
||||
function Warn { echo -e "\033[36;1m$(date +'[%F %T]')\033[33;1m $*\033[0m"; }
|
||||
function Error { echo -e "\033[36;1m$(date +'[%F %T]')\033[31;1m $*\033[0m"; exit 1; }
|
||||
else
|
||||
function Print { echo -e "$(date +'[%F %T INFO]') $*"; }
|
||||
function Warn { echo -e "$(date +'[%F %T WARN]') $*"; }
|
||||
function Error { echo -e "$(date +'[%F %T ERROR]') $*"; exit 1; }
|
||||
fi
|
||||
|
||||
function Quit {
|
||||
local exitCode=$?
|
||||
[ 0 -ne $exitCode ] && Error Failed to build or push image!
|
||||
[ -z "${END:-}" ] && echo && Error Interrupted manually!
|
||||
Print Succeeded to build and push image.
|
||||
}
|
||||
|
||||
function YesOrNo {
|
||||
Warn $*
|
||||
local sw=
|
||||
while :; do
|
||||
read -p '(Yes/No/Quit) ' -n1 sw
|
||||
[[ "$sw" =~ ^Y|y$ ]] && echo && return 0
|
||||
[[ "$sw" =~ ^N|n$ ]] && echo && return 1
|
||||
[[ "$sw" =~ ^Q|q$ ]] && echo && exit 0
|
||||
[ -n "$sw" ] && echo
|
||||
done
|
||||
}
|
||||
|
||||
function Update {
|
||||
:
|
||||
}
|
||||
|
||||
function Build {
|
||||
local yn
|
||||
cd $ROOT_DIR
|
||||
docker images --format='{{.Repository}}:{{.Tag}}' | grep "^$IMAGE$" \
|
||||
&& Warn Removing image $IMAGE ... \
|
||||
&& docker rmi $IMAGE
|
||||
Warn Building image: $IMAGE ...
|
||||
docker build --force-rm --build-arg ARCH="$ARCH" -t $IMAGE .
|
||||
YesOrNo Push image: $IMAGE? && docker push $IMAGE
|
||||
}
|
||||
|
||||
function Main {
|
||||
Update
|
||||
Build
|
||||
END=1
|
||||
}
|
||||
|
||||
# Start here
|
||||
Main
|
||||
|
Reference in New Issue
Block a user