update
This commit is contained in:
76
kafka/ADD/ccmd
Executable file
76
kafka/ADD/ccmd
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
|
||||
##################################################
|
||||
# Mount dir #
|
||||
# - /opt/kafka/data #
|
||||
# - /opt/kafka/logs #
|
||||
# ENV #
|
||||
# - KAFKA_OPTS #
|
||||
# - _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/kafka/{data,logs} mounted from host**
|
||||
'
|
||||
}
|
||||
|
||||
function ModifyConf {
|
||||
Print Modify server.properties ...
|
||||
local kv=
|
||||
local conf='config/server.properties'
|
||||
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_//')"
|
||||
}
|
||||
|
||||
function StartProc {
|
||||
Print Start kafka ...
|
||||
./bin/kafka-server-start.sh ./config/server.properties --override log.dirs=./data \
|
||||
&>> logs/kafka.out &
|
||||
PIDS="$PIDS $!"
|
||||
}
|
||||
|
||||
function Main {
|
||||
local pid=
|
||||
cd /opt/kafka
|
||||
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