update
This commit is contained in:
68
chromedriver/ADD/ccmd
Executable file
68
chromedriver/ADD/ccmd
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
##################################################
|
||||
# Mount dir #
|
||||
# - $ROOT/exports #
|
||||
# - $ROOT/logs #
|
||||
# ENV #
|
||||
# - OPTS #
|
||||
# - _CONF_* #
|
||||
##################################################
|
||||
|
||||
set -euo pipefail
|
||||
export LANG=en_US.UTF-8
|
||||
trap Quit EXIT
|
||||
|
||||
PIDS=
|
||||
GOT_SIGTERM=
|
||||
OPTS="${OPTS:-}"
|
||||
|
||||
function Print {
|
||||
local file=/dev/null
|
||||
[ '-f' = "$1" ] && file=$2 && shift && shift
|
||||
date +"[%F %T] $*" | tee -a $file
|
||||
}
|
||||
|
||||
function Quit {
|
||||
while :; do
|
||||
pkill -f chromedriver && Print killing chromedriver ... || break
|
||||
sleep 1
|
||||
done
|
||||
Print Container stopped.
|
||||
test -n "$GOT_SIGTERM"
|
||||
}
|
||||
|
||||
function ModifyConf {
|
||||
local kv=
|
||||
Print Modify $JAR.properties ...
|
||||
while read kv; do
|
||||
[ -z "$kv" ] && return 0
|
||||
Print Modify property: ${kv%%=*} ...
|
||||
sed -i "/^${kv%%=*} *=/c$kv" $JAR.properties
|
||||
done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')"
|
||||
}
|
||||
|
||||
function StartProc {
|
||||
Print Start chromedriver ...
|
||||
./chromedriver --allowed-ips $OPTS \
|
||||
>/dev/null \
|
||||
2>>logs/chromedriver.out &
|
||||
PIDS="$PIDS $!"
|
||||
}
|
||||
|
||||
function Main {
|
||||
local pid=
|
||||
cd $(dirname $0)
|
||||
# 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