@@ -211,68 +211,66 @@ if [[ "${ENABLE_WEBRTC:-}" == "true" ]]; then
211211 echo " [wrapper] Port 8080 is open"
212212fi
213213
214- if [[ " ${WITH_KERNEL_IMAGES_API:- } " == " true" ]]; then
215- echo " [wrapper] ✨ Starting kernel-images API."
216-
217- API_PORT=" ${KERNEL_IMAGES_API_PORT:- 10001} "
218- API_FRAME_RATE=" ${KERNEL_IMAGES_API_FRAME_RATE:- 10} "
219- API_DISPLAY_NUM=" ${KERNEL_IMAGES_API_DISPLAY_NUM:- ${DISPLAY_NUM:- 1} } "
220- API_MAX_SIZE_MB=" ${KERNEL_IMAGES_API_MAX_SIZE_MB:- 500} "
221- API_OUTPUT_DIR=" ${KERNEL_IMAGES_API_OUTPUT_DIR:-/ recordings} "
222-
223- # Start via supervisord (env overrides are read by the service's command)
224- supervisorctl -c /etc/supervisor/supervisord.conf start kernel-images-api
225- # close the "--no-sandbox unsupported flag" warning when running as root
226- # in the unikernel runtime we haven't been able to get chromium to launch as non-root without cryptic crashpad errors
227- # and when running as root you must use the --no-sandbox flag, which generates a warning
228- if [[ " ${RUN_AS_ROOT:- } " == " true" ]]; then
229- echo " [wrapper] Running as root, attempting to dismiss the --no-sandbox unsupported flag warning"
230- if read -r WIDTH HEIGHT <<< " $(xdotool getdisplaygeometry 2>/dev/null)" ; then
231- # Work out an x-coordinate slightly inside the right-hand edge of the
232- OFFSET_X=$(( WIDTH - 30 ))
233- if (( OFFSET_X < 0 )) ; then
234- OFFSET_X=0
235- fi
214+ echo " [wrapper] ✨ Starting kernel-images API."
215+
216+ API_PORT=" ${KERNEL_IMAGES_API_PORT:- 10001} "
217+ API_FRAME_RATE=" ${KERNEL_IMAGES_API_FRAME_RATE:- 10} "
218+ API_DISPLAY_NUM=" ${KERNEL_IMAGES_API_DISPLAY_NUM:- ${DISPLAY_NUM:- 1} } "
219+ API_MAX_SIZE_MB=" ${KERNEL_IMAGES_API_MAX_SIZE_MB:- 500} "
220+ API_OUTPUT_DIR=" ${KERNEL_IMAGES_API_OUTPUT_DIR:-/ recordings} "
221+
222+ # Start via supervisord (env overrides are read by the service's command)
223+ supervisorctl -c /etc/supervisor/supervisord.conf start kernel-images-api
224+ # close the "--no-sandbox unsupported flag" warning when running as root
225+ # in the unikernel runtime we haven't been able to get chromium to launch as non-root without cryptic crashpad errors
226+ # and when running as root you must use the --no-sandbox flag, which generates a warning
227+ if [[ " ${RUN_AS_ROOT:- } " == " true" ]]; then
228+ echo " [wrapper] Running as root, attempting to dismiss the --no-sandbox unsupported flag warning"
229+ if read -r WIDTH HEIGHT <<< " $(xdotool getdisplaygeometry 2>/dev/null)" ; then
230+ # Work out an x-coordinate slightly inside the right-hand edge of the
231+ OFFSET_X=$(( WIDTH - 30 ))
232+ if (( OFFSET_X < 0 )) ; then
233+ OFFSET_X=0
234+ fi
236235
237- # Wait for kernel-images API port to be ready.
238- echo " [wrapper] Waiting for kernel-images API port 127.0.0.1:${API_PORT} ..."
239- while ! nc -z 127.0.0.1 " ${API_PORT} " 2> /dev/null; do
240- sleep 0.5
241- done
242- echo " [wrapper] Port ${API_PORT} is open"
243-
244- # Wait for Chromium window to open before dismissing the --no-sandbox warning.
245- target=' New Tab - Chromium'
246- echo " [wrapper] Waiting for Chromium window \" ${target} \" to appear and become active..."
247- while : ; do
248- win_id=$( xwininfo -root -tree 2> /dev/null | awk -v t=" $target " ' $0 ~ t {print $1; exit}' )
249- if [[ -n $win_id ]]; then
250- win_id=${win_id%: }
251- if xdotool windowactivate --sync " $win_id " ; then
252- echo " [wrapper] Focused window $win_id ($target ) on $DISPLAY "
253- break
254- fi
236+ # Wait for kernel-images API port to be ready.
237+ echo " [wrapper] Waiting for kernel-images API port 127.0.0.1:${API_PORT} ..."
238+ while ! nc -z 127.0.0.1 " ${API_PORT} " 2> /dev/null; do
239+ sleep 0.5
240+ done
241+ echo " [wrapper] Port ${API_PORT} is open"
242+
243+ # Wait for Chromium window to open before dismissing the --no-sandbox warning.
244+ target=' New Tab - Chromium'
245+ echo " [wrapper] Waiting for Chromium window \" ${target} \" to appear and become active..."
246+ while : ; do
247+ win_id=$( xwininfo -root -tree 2> /dev/null | awk -v t=" $target " ' $0 ~ t {print $1; exit}' )
248+ if [[ -n $win_id ]]; then
249+ win_id=${win_id%: }
250+ if xdotool windowactivate --sync " $win_id " ; then
251+ echo " [wrapper] Focused window $win_id ($target ) on $DISPLAY "
252+ break
255253 fi
256- sleep 0.5
257- done
258-
259- # wait... not sure but this just increases the likelihood of success
260- # without the sleep you often open the live view and see the mouse hovering over the "X" to dismiss the warning, suggesting that it clicked before the warning or chromium appeared
261- sleep 5
262-
263- # Attempt to click the warning's close button
264- echo " [wrapper] Clicking the warning's close button at x=$OFFSET_X y=115"
265- if curl -s -o /dev/null -X POST \
266- http://localhost:${API_PORT} /computer/click_mouse \
267- -H " Content-Type: application/json" \
268- -d " {\" x\" :${OFFSET_X} ,\" y\" :115}" ; then
269- echo " [wrapper] Successfully clicked the warning's close button"
270- else
271- echo " [wrapper] Failed to click the warning's close button" >&2
272254 fi
255+ sleep 0.5
256+ done
257+
258+ # wait... not sure but this just increases the likelihood of success
259+ # without the sleep you often open the live view and see the mouse hovering over the "X" to dismiss the warning, suggesting that it clicked before the warning or chromium appeared
260+ sleep 5
261+
262+ # Attempt to click the warning's close button
263+ echo " [wrapper] Clicking the warning's close button at x=$OFFSET_X y=115"
264+ if curl -s -o /dev/null -X POST \
265+ http://localhost:${API_PORT} /computer/click_mouse \
266+ -H " Content-Type: application/json" \
267+ -d " {\" x\" :${OFFSET_X} ,\" y\" :115}" ; then
268+ echo " [wrapper] Successfully clicked the warning's close button"
273269 else
274- echo " [wrapper] xdotool failed to obtain display geometry; skipping sandbox warning dismissal. " >&2
270+ echo " [wrapper] Failed to click the warning's close button " >&2
275271 fi
272+ else
273+ echo " [wrapper] xdotool failed to obtain display geometry; skipping sandbox warning dismissal." >&2
276274 fi
277275fi
278276
0 commit comments