-
Notifications
You must be signed in to change notification settings - Fork 44
/
start.sh
executable file
·73 lines (60 loc) · 1.76 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
set -e
echo "Starting Xvfb..."
rm -f /tmp/.X0-lock
/usr/bin/Xvfb "$DISPLAY" -ac -screen 0 1024x768x16 +extension RANDR >&1 &
echo "Waiting for Xvfb to be ready..."
XVFB_TIMEOUT=120
XVFB_WAITING_TIME=0
while ! xdpyinfo -display "$DISPLAY"; do
echo -n ''
sleep 1
XVFB_WAITING_TIME=$(($XVFB_WAITING_TIME+1))
echo "WAITING TIME: $XVFB_WAITING_TIME"
if [ "$XVFB_WAITING_TIME" -gt "$XVFB_TIMEOUT" ]; then
echo "Xvfb TIMED OUT"
exit 1
fi
done
echo "Xvfb is ready"
echo "Setup port forwarding..."
socat TCP-LISTEN:$IBGW_PORT,fork TCP:localhost:4001,forever >&1 &
echo "*****************************"
# python /root/bootstrap.py
# echo "IB gateway is ready."
#Define cleanup procedure
cleanup() {
pkill java
pkill Xvfb
pkill socat
echo "Container stopped, performing cleanup..."
}
#Trap TERM
trap 'cleanup' INT TERM
echo "IB gateway starting..."
IB_GATEWAY_VERSION=$(ls $TWS_PATH/ibgateway)
set_java_heap() {
# set java heap size in vm options
if [ -n "${JAVA_HEAP_SIZE}" ]; then
_vmpath="${TWS_PATH}/ibgateway/${IB_GATEWAY_VERSION}"
_string="s/-Xmx([0-9]+)m/-Xmx${JAVA_HEAP_SIZE}m/g"
sed -i -E "${_string}" "${_vmpath}/ibgateway.vmoptions"
echo "Java heap size set to ${JAVA_HEAP_SIZE}m"
else
echo "Usign default Java heap size."
fi
}
# Java heap size
set_java_heap
# start rest api for healthcheck
if [ "$HEALTHCHECK_API_ENABLE" = true ] ; then
echo "starting healthcheck api..."
healthcheck-rest >&1 &
else
echo "Skip starting healthcheck api"
fi
echo "detect IB gateway version: $IBGW_VERSION"
${IBC_PATH}/scripts/ibcstart.sh "$IB_GATEWAY_VERSION" -g \
"--ibc-path=${IBC_PATH}" "--ibc-ini=${IBC_INI}" \
"--user=${IB_ACCOUNT}" "--pw=${IB_PASSWORD}" "--mode=${TRADING_MODE}" \
"--on2fatimeout=${TWOFA_TIMEOUT_ACTION}"