70 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/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 Modifying $JAR.properties ...
 | 
						|
    while read kv; do
 | 
						|
        [ -z "$kv" ] && return 0
 | 
						|
        Print Modifying property: ${kv%%=*} ...
 | 
						|
        sed -i "/^${kv%%=*} *=/c$kv" $JAR.properties
 | 
						|
    done <<< "$(env | grep '^_CONF_' | sed 's/_CONF_//')"
 | 
						|
}
 | 
						|
 | 
						|
function StartProc {
 | 
						|
    Print Starting chromedriver ...
 | 
						|
    ./chromedriver  --allowed-ips $OPTS  \
 | 
						|
        >/dev/null \
 | 
						|
        2>>logs/chromedriver.out &
 | 
						|
    PIDS="$PIDS $!"
 | 
						|
    Print Chromedriver started.
 | 
						|
}
 | 
						|
 | 
						|
function Main {
 | 
						|
    local pid=
 | 
						|
    cd $(dirname $0)
 | 
						|
#    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
 | 
						|
 |