-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathstart-selenium-node.sh
executable file
·205 lines (170 loc) · 6.64 KB
/
start-selenium-node.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
# Start the pulseaudio server
pulseaudio -D --exit-idle-time=-1
# Load the virtual sink and set it as default
pacmd load-module module-virtual-sink sink_name=v1
pacmd set-default-sink v1
# set the monitor of v1 sink to be the default source
pacmd set-default-source v1.monitor
rm -f /tmp/.X*lock
# set -e: exit asap if a command exits with a non-zero status
set -e
function append_se_opts() {
local option="${1}"
local value="${2:-""}"
local log_message="${3:-true}"
if [[ "${SE_OPTS}" != *"${option}"* ]]; then
if [ "${log_message}" = "true" ]; then
echo "Appending Selenium option: ${option} ${value}"
else
echo "Appending Selenium option: ${option} $(mask ${value})"
fi
SE_OPTS="${SE_OPTS} ${option}"
if [ ! -z "${value}" ]; then
SE_OPTS="${SE_OPTS} ${value}"
fi
else
echo "Selenium option: ${option} already set in env variable SE_OPTS. Ignore new option: ${option} ${value}"
fi
}
if [ ! -z "$SE_OPTS" ]; then
echo "Appending Selenium options: ${SE_OPTS}"
fi
if [[ -z "${SE_EVENT_BUS_HOST}" ]]; then
echo "SE_EVENT_BUS_HOST not set, exiting!" 1>&2
exit 1
fi
if [[ -z "${SE_EVENT_BUS_PUBLISH_PORT}" ]]; then
echo "SE_EVENT_BUS_PUBLISH_PORT not set, exiting!" 1>&2
exit 1
fi
if [[ -z "${SE_EVENT_BUS_SUBSCRIBE_PORT}" ]]; then
echo "SE_EVENT_BUS_SUBSCRIBE_PORT not set, exiting!" 1>&2
exit 1
fi
if [ ! -z "$SE_NODE_ENABLE_MANAGED_DOWNLOADS" ]; then
append_se_opts "--enable-managed-downloads" "${SE_NODE_ENABLE_MANAGED_DOWNLOADS}"
fi
if [ ! -z "$SE_NODE_ENABLE_CDP" ]; then
append_se_opts "--enable-cdp" "${SE_NODE_ENABLE_CDP}"
fi
if [ ! -z "$SE_NODE_REGISTER_PERIOD" ]; then
append_se_opts "--register-period" "${SE_NODE_REGISTER_PERIOD}"
fi
if [ ! -z "$SE_NODE_REGISTER_CYCLE" ]; then
append_se_opts "--register-cycle" "${SE_NODE_REGISTER_CYCLE}"
fi
if [ "$SE_NODE_REGISTER_SHUTDOWN_ON_FAILURE" = "true" ]; then
append_se_opts "--register-shutdown-on-failure"
fi
if [ ! -z "$SE_NODE_HEARTBEAT_PERIOD" ]; then
append_se_opts "--heartbeat-period" "${SE_NODE_HEARTBEAT_PERIOD}"
fi
if [ ! -z "$SE_LOG_LEVEL" ]; then
append_se_opts "--log-level" "${SE_LOG_LEVEL}"
fi
if [ ! -z "$SE_HTTP_LOGS" ]; then
append_se_opts "--http-logs" "${SE_HTTP_LOGS}"
fi
if [ ! -z "$SE_STRUCTURED_LOGS" ]; then
append_se_opts "--structured-logs" "${SE_STRUCTURED_LOGS}"
fi
if [ ! -z "$SE_EXTERNAL_URL" ]; then
append_se_opts "--external-url" "${SE_EXTERNAL_URL}"
fi
if [ "${SE_ENABLE_TLS}" = "true" ]; then
# Configure truststore for the server
if [ ! -z "$SE_JAVA_SSL_TRUST_STORE" ]; then
echo "Appending Java options: -Djavax.net.ssl.trustStore=${SE_JAVA_SSL_TRUST_STORE}"
SE_JAVA_OPTS="$SE_JAVA_OPTS -Djavax.net.ssl.trustStore=${SE_JAVA_SSL_TRUST_STORE}"
fi
if [ -f "${SE_JAVA_SSL_TRUST_STORE_PASSWORD}" ]; then
echo "Getting Truststore password from ${SE_JAVA_SSL_TRUST_STORE_PASSWORD} to set Java options: -Djavax.net.ssl.trustStorePassword"
SE_JAVA_SSL_TRUST_STORE_PASSWORD="$(cat ${SE_JAVA_SSL_TRUST_STORE_PASSWORD})"
fi
if [ ! -z "${SE_JAVA_SSL_TRUST_STORE_PASSWORD}" ]; then
echo "Appending Java options: -Djavax.net.ssl.trustStorePassword=$(mask ${SE_JAVA_SSL_TRUST_STORE_PASSWORD})"
SE_JAVA_OPTS="$SE_JAVA_OPTS -Djavax.net.ssl.trustStorePassword=${SE_JAVA_SSL_TRUST_STORE_PASSWORD}"
fi
echo "Appending Java options: -Djdk.internal.httpclient.disableHostnameVerification=${SE_JAVA_DISABLE_HOSTNAME_VERIFICATION}"
SE_JAVA_OPTS="$SE_JAVA_OPTS -Djdk.internal.httpclient.disableHostnameVerification=${SE_JAVA_DISABLE_HOSTNAME_VERIFICATION}"
# Configure certificate and private key for component communication
if [ ! -z "$SE_HTTPS_CERTIFICATE" ]; then
append_se_opts "--https-certificate" "${SE_HTTPS_CERTIFICATE}"
fi
if [ ! -z "$SE_HTTPS_PRIVATE_KEY" ]; then
append_se_opts "--https-private-key" "${SE_HTTPS_PRIVATE_KEY}"
fi
fi
if [ ! -z "$SE_REGISTRATION_SECRET" ]; then
append_se_opts "--registration-secret" "${SE_REGISTRATION_SECRET}" "false"
fi
if [ "$GENERATE_CONFIG" = true ]; then
echo "Generating Selenium Config"
/opt/bin/generate_config
/opt/bin/generate_relay_config
fi
EXTRA_LIBS=""
if [ "${SE_ENABLE_TRACING}" = "true" ] && [ -n "${SE_OTEL_EXPORTER_ENDPOINT}" ]; then
EXTERNAL_JARS=$(</external_jars/.classpath.txt)
[ -n "$EXTRA_LIBS" ] && [ -n "${EXTERNAL_JARS}" ] && EXTRA_LIBS=${EXTRA_LIBS}:
EXTRA_LIBS="--ext "${EXTRA_LIBS}${EXTERNAL_JARS}
echo "Tracing is enabled"
echo "Classpath will be enriched with these external jars : " ${EXTRA_LIBS}
if [ -n "$SE_OTEL_SERVICE_NAME" ]; then
SE_OTEL_JVM_ARGS="$SE_OTEL_JVM_ARGS -Dotel.resource.attributes=service.name=${SE_OTEL_SERVICE_NAME}"
fi
if [ -n "$SE_OTEL_TRACES_EXPORTER" ]; then
SE_OTEL_JVM_ARGS="$SE_OTEL_JVM_ARGS -Dotel.traces.exporter=${SE_OTEL_TRACES_EXPORTER}"
fi
if [ -n "$SE_OTEL_EXPORTER_ENDPOINT" ]; then
SE_OTEL_JVM_ARGS="$SE_OTEL_JVM_ARGS -Dotel.exporter.otlp.endpoint=$(envsubst < <(echo ${SE_OTEL_EXPORTER_ENDPOINT}))"
fi
if [ -n "$SE_OTEL_JAVA_GLOBAL_AUTOCONFIGURE_ENABLED" ]; then
SE_OTEL_JVM_ARGS="$SE_OTEL_JVM_ARGS -Dotel.java.global-autoconfigure.enabled=${SE_OTEL_JAVA_GLOBAL_AUTOCONFIGURE_ENABLED}"
fi
if [ -n "$SE_OTEL_JVM_ARGS" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS ${SE_OTEL_JVM_ARGS}"
fi
else
append_se_opts "--tracing" "false"
SE_JAVA_OPTS="$SE_JAVA_OPTS -Dwebdriver.remote.enableTracing=false"
echo "Tracing is disabled"
fi
if [ ! -z "${SE_BIND_HOST}" ]; then
append_se_opts "--bind-host" "${SE_BIND_HOST}"
fi
if [ ! -z "${CONFIG_FILE}" ]; then
append_se_opts "--config" "${CONFIG_FILE}"
fi
echo "Selenium Grid Node configuration: "
cat "$CONFIG_FILE"
echo "Starting Selenium Grid Node..."
CHROME_DRIVER_PATH_PROPERTY=-Dwebdriver.chrome.driver=/usr/bin/chromedriver
EDGE_DRIVER_PATH_PROPERTY=-Dwebdriver.edge.driver=/usr/bin/msedgedriver
GECKO_DRIVER_PATH_PROPERTY=-Dwebdriver.gecko.driver=/usr/bin/geckodriver
if [ -n "${SE_JAVA_HTTPCLIENT_VERSION}" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS -Dwebdriver.httpclient.version=${SE_JAVA_HTTPCLIENT_VERSION}"
fi
if [ -n "${SE_JAVA_OPTS_DEFAULT}" ]; then
SE_JAVA_OPTS="${SE_JAVA_OPTS_DEFAULT} $SE_JAVA_OPTS"
fi
function handle_heap_dump() {
/opt/bin/handle_heap_dump.sh /opt/selenium/logs
}
if [ "${SE_JAVA_HEAP_DUMP}" = "true" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/selenium/logs"
trap handle_heap_dump ERR SIGTERM SIGINT
fi
if [ -n "${JAVA_OPTS}" ]; then
SE_JAVA_OPTS="$SE_JAVA_OPTS ${JAVA_OPTS}"
fi
echo "Using JAVA_OPTS: ${SE_JAVA_OPTS}"
java ${SE_JAVA_OPTS} \
${CHROME_DRIVER_PATH_PROPERTY} \
${EDGE_DRIVER_PATH_PROPERTY} \
${GECKO_DRIVER_PATH_PROPERTY} \
-jar /opt/selenium/selenium-server.jar \
${EXTRA_LIBS} \
node \
${SE_OPTS}