update
This commit is contained in:
83
zookeeper/ADD/ccmd
Executable file
83
zookeeper/ADD/ccmd
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
##################################################
|
||||
# Mount dir #
|
||||
# - /opt/zk/data #
|
||||
# - /opt/zk/dataLog #
|
||||
# - /opt/zk/logs #
|
||||
# ENV #
|
||||
# - MYID #
|
||||
# - JVMFLAGS #
|
||||
# - _CONF_* #
|
||||
##################################################
|
||||
|
||||
set -euo pipefail
|
||||
export LANG=en_US.UTF-8
|
||||
trap Quit EXIT
|
||||
|
||||
PIDS=
|
||||
GOT_SIGTERM=
|
||||
|
||||
function Print {
|
||||
local file=/dev/null
|
||||
[ '-f' = "$1" ] && file=$2 && shift && shift
|
||||
date +"[%F %T] $*" | tee -a $file
|
||||
}
|
||||
|
||||
function Quit {
|
||||
while :; do
|
||||
pkill -f java && Print killing java ... || break
|
||||
sleep 1
|
||||
done
|
||||
Print Container stopped.
|
||||
test -n "$GOT_SIGTERM"
|
||||
}
|
||||
|
||||
function Usage {
|
||||
Print 'This container should run with
|
||||
**root user**
|
||||
**/opt/zk/{data,dataLog,logs} mounted from host**
|
||||
'
|
||||
}
|
||||
|
||||
function ModifyConf {
|
||||
Print Modify server.properties ...
|
||||
local kv=
|
||||
local conf='conf/zoo.cfg'
|
||||
while read kv; do
|
||||
[ -z "$kv" ] && break
|
||||
Print Modify property: ${kv%%=*} ...
|
||||
sed -i "/^${kv%%=*} *=/d" $conf
|
||||
echo "$kv" >> $conf
|
||||
done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')"
|
||||
sed -i -e '/^dataDir/d' -e '/^dataLogDir/d' $conf
|
||||
echo -e 'dataDir=/opt/zk/data\ndataLogDir=/opt/zk/dataLog' >> $conf
|
||||
if [ ! -e data/myid ]; then
|
||||
Print Generate myid ...
|
||||
echo $MYID > data/myid
|
||||
fi
|
||||
}
|
||||
|
||||
function StartProc {
|
||||
Print Start zookeeper ...
|
||||
./bin/zkServer.sh start-foreground &>> logs/zk.out &
|
||||
PIDS="$PIDS $!"
|
||||
}
|
||||
|
||||
function Main {
|
||||
local pid=
|
||||
cd /opt/zk
|
||||
Usage
|
||||
ModifyConf
|
||||
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
|
||||
|
Reference in New Issue
Block a user