78 lines
1.8 KiB
Bash
Executable File
78 lines
1.8 KiB
Bash
Executable File
#!/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 Modifying server.properties ...
|
|
local kv=
|
|
local conf='config/server.properties'
|
|
while read kv; do
|
|
[ -z "$kv" ] && break
|
|
Print Modifying property: ${kv%%=*} ...
|
|
sed -i "/^${kv%%=*} *=/d" $conf
|
|
echo "$kv" >> $conf
|
|
done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')"
|
|
}
|
|
|
|
function StartProc {
|
|
Print Starting kafka ...
|
|
./bin/kafka-server-start.sh ./config/server.properties --override log.dirs=./data \
|
|
&>> logs/kafka.out &
|
|
PIDS="$PIDS $!"
|
|
Print Kafka started.
|
|
}
|
|
|
|
function Main {
|
|
local pid=
|
|
cd /opt/kafka
|
|
Usage
|
|
ModifyConf
|
|
StartProc
|
|
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
|
|
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
|
|
for pid in $PIDS; do
|
|
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
|
|
done
|
|
done
|
|
}
|
|
|
|
# Start here
|
|
Main
|
|
|