Skip to content

Commit

Permalink
Refactoring env vars to add SE_ prefix (#1603)
Browse files Browse the repository at this point in the history
In preparation for #1319, which makes it easier to collect the environment variables that matter to configure child containers.
  • Loading branch information
diemol authored Jun 16, 2022
1 parent 5d143a8 commit 3c74143
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Distributor/start-selenium-grid-distributor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if [ ! -z "$SE_DISTRIBUTOR_PORT" ]; then
fi


java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar distributor \
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar distributor \
--sessions-host "${SE_SESSIONS_MAP_HOST}" --sessions-port "${SE_SESSIONS_MAP_PORT}" \
--sessionqueue-host "${SE_SESSION_QUEUE_HOST}" --sessionqueue-port "${SE_SESSION_QUEUE_PORT}" \
--publish-events tcp://"${SE_EVENT_BUS_HOST}":"${SE_EVENT_BUS_PUBLISH_PORT}" \
Expand Down
2 changes: 1 addition & 1 deletion EventBus/start-selenium-grid-eventbus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [ ! -z "$SE_OPTS" ]; then
echo "Appending Selenium options: ${SE_OPTS}"
fi

java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar event-bus \
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar event-bus \
--bind-host ${SE_BIND_HOST} \
${HOST_CONFIG} \
${PORT_CONFIG} \
Expand Down
2 changes: 1 addition & 1 deletion Hub/start-selenium-grid-hub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if [ ! -z "$SE_HUB_PORT" ]; then
fi


java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar hub \
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar hub \
--session-request-timeout ${SE_SESSION_REQUEST_TIMEOUT} \
--session-retry-interval ${SE_SESSION_RETRY_INTERVAL} \
--relax-checks ${SE_RELAX_CHECKS} \
Expand Down
18 changes: 11 additions & 7 deletions NodeBase/Dockerfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,24 @@ COPY selenium_grid_logo.png /usr/share/images/fluxbox/ubuntu-light.png
#============================
# Some configuration options
#============================
ENV SCREEN_WIDTH 1360
ENV SCREEN_HEIGHT 1020
ENV SCREEN_DEPTH 24
ENV SCREEN_DPI 96
ENV SE_SCREEN_WIDTH 1360
ENV SE_SCREEN_HEIGHT 1020
ENV SE_SCREEN_DEPTH 24
ENV SE_SCREEN_DPI 96
ENV SE_START_XVFB true
ENV SE_START_NO_VNC true
ENV SE_NO_VNC_PORT 7900
ENV SE_VNC_PORT 5900
ENV DISPLAY :99.0
ENV DISPLAY_NUM 99
ENV START_XVFB true
ENV START_NO_VNC true
# Path to the Configfile
ENV CONFIG_FILE=/opt/selenium/config.toml
ENV GENERATE_CONFIG true
# Drain the Node after N sessions.
# A value higher than zero enables the feature
ENV DRAIN_AFTER_SESSION_COUNT 0
ENV SE_DRAIN_AFTER_SESSION_COUNT 0



#========================
# Selenium Configuration
Expand Down
2 changes: 1 addition & 1 deletion NodeBase/generate_config
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fi
echo "session-timeout = \"${SE_NODE_SESSION_TIMEOUT}\"" >> "$FILENAME"
echo "override-max-sessions = ${SE_NODE_OVERRIDE_MAX_SESSIONS}" >> "$FILENAME"
echo "detect-drivers = false" >> "$FILENAME"
echo "drain-after-session-count = ${DRAIN_AFTER_SESSION_COUNT}" >> "$FILENAME"
echo "drain-after-session-count = ${DRAIN_AFTER_SESSION_COUNT:-$SE_DRAIN_AFTER_SESSION_COUNT}" >> "$FILENAME"
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
" >> "$FILENAME"

Expand Down
8 changes: 4 additions & 4 deletions NodeBase/start-novnc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#
# IMPORTANT: Change this file only in directory NodeBase!

if [ "${START_XVFB}" = true ] ; then
if [ "${START_NO_VNC}" = true ] ; then
/opt/bin/noVNC/utils/launch.sh --listen ${NO_VNC_PORT:-7900} --vnc localhost:${VNC_PORT:-5900}
if [ "${START_XVFB:-$SE_START_XVFB}" = true ] ; then
if [ "${START_NO_VNC:-$SE_START_NO_VNC}" = true ] ; then
/opt/bin/noVNC/utils/launch.sh --listen ${NO_VNC_PORT:-$SE_NO_VNC_PORT} --vnc localhost:${VNC_PORT:-$SE_VNC_PORT}
else
echo "noVNC won't start because START_NO_VNC is false."
echo "noVNC won't start because SE_START_NO_VNC is false."
fi
else
echo "noVNC won't start because Xvfb is configured to not start."
Expand Down
2 changes: 1 addition & 1 deletion NodeBase/start-selenium-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fi
echo "Selenium Grid Node configuration: "
cat "$CONFIG_FILE"
echo "Starting Selenium Grid Node..."
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar node \
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar node \
--bind-host ${SE_BIND_HOST} \
--config "$CONFIG_FILE" \
${SE_OPTS}
6 changes: 4 additions & 2 deletions NodeBase/start-vnc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# IMPORTANT: Change this file only in directory NodeBase!

if [ "${START_XVFB}" = true ] ; then
if [ "${START_XVFB:-$SE_START_XVFB}" = true ] ; then
# Centering wallpaper
for i in $(seq 1 10)
do
Expand All @@ -14,13 +14,15 @@ if [ "${START_XVFB}" = true ] ; then
fi
done

VNC_NO_PASSWORD=${VNC_NO_PASSWORD:-$SE_VNC_NO_PASSWORD}
if [ ! -z $VNC_NO_PASSWORD ]; then
echo "Starting VNC server without password authentication"
X11VNC_OPTS=
else
X11VNC_OPTS=-usepw
fi

VNC_VIEW_ONLY=${VNC_VIEW_ONLY:-$SE_VNC_VIEW_ONLY}
if [ ! -z $VNC_VIEW_ONLY ]; then
echo "Starting VNC server with viewonly option"
X11VNC_OPTS="${X11VNC_OPTS} -viewonly"
Expand All @@ -36,7 +38,7 @@ if [ "${START_XVFB}" = true ] ; then
echo "Waiting for Xvfb..."
done

x11vnc ${X11VNC_OPTS} -forever -shared -rfbport ${VNC_PORT:-5900} -rfbportv6 ${VNC_PORT:-5900} -display ${DISPLAY}
x11vnc ${X11VNC_OPTS} -forever -shared -rfbport ${VNC_PORT:-$SE_VNC_PORT} -rfbportv6 ${VNC_PORT:-$SE_VNC_PORT} -display ${DISPLAY}
else
echo "Vnc won't start because Xvfb is configured to not start."
fi
7 changes: 6 additions & 1 deletion NodeBase/start-xvfb.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env bash

if [ "${START_XVFB}" = true ] ; then
SCREEN_WIDTH=${SCREEN_WIDTH:-$SE_SCREEN_WIDTH}
SCREEN_HEIGHT=${SCREEN_HEIGHT:-$SE_SCREEN_HEIGHT}
SCREEN_DEPTH=${SCREEN_DEPTH:-$SE_SCREEN_DEPTH}
SCREEN_DPI=${SCREEN_DPI:-$SE_SCREEN_DPI}

if [ "${START_XVFB:-$SE_START_XVFB}" = true ] ; then
export GEOMETRY="${SCREEN_WIDTH}""x""${SCREEN_HEIGHT}""x""${SCREEN_DEPTH}"

rm -f /tmp/.X*lock
Expand Down
2 changes: 1 addition & 1 deletion NodeDocker/start-selenium-grid-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if [ ! -z "$SE_NODE_GRID_URL" ]; then
SE_GRID_URL="--grid-url ${SE_NODE_GRID_URL}"
fi

java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar node \
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar node \
--publish-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_PUBLISH_PORT} \
--subscribe-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_SUBSCRIBE_PORT} \
--bind-host ${SE_BIND_HOST} \
Expand Down
62 changes: 47 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Talk to us at https://www.selenium.dev/support/
* [Kubernetes](#deploying-to-kubernetes)
* [Configuring the containers](#configuring-the-containers)
+ [SE_OPTS Selenium Configuration Options](#se_opts-selenium-configuration-options)
+ [JAVA_OPTS Java Environment Options](#java_opts-java-environment-options)
+ [SE_JAVA_OPTS Java Environment Options](#se_java_opts-java-environment-options)
+ [Node configuration options](#node-configuration-options)
+ [Setting Screen Resolution](#setting-screen-resolution)
+ [Grid Url and Session Timeout](#grid-url-and-session-timeout)
Expand Down Expand Up @@ -550,6 +550,38 @@ Here is an example using a Hub and a Node:
[`docker-compose-v3-dynamic-grid.yml`](docker-compose-v3-dynamic-grid.yml)


### Configuring the child containers

Containers can be further configured through environment variables, such as `SE_NODE_SESSION_TIMEOUT`
and `SE_OPTS`. When a child container is created, all environment variables prefixed with `SE_` will
be forwared and set in the container. You can set the desired environment variables in the
`standalone-docker` or `node-docker` containers. The following example sets the session timeout to
700 seconds for all sessions:

#### macOS/Linux

```bash
docker run --rm --name selenium-docker -p 4444:4444 \
-e SE_NODE_SESSION_TIMEOUT=700 \
-v ${PWD}/config.toml:/opt/bin/config.toml \
-v ${PWD}/assets:/opt/selenium/assets \
-v /var/run/docker.sock:/var/run/docker.sock \
selenium/standalone-docker:4.2.2-20220609
```

#### Windows PowerShell

```bash
docker run --rm --name selenium-docker -p 4444:4444 `
-e SE_NODE_SESSION_TIMEOUT=700 `
-v ${PWD}/config.toml:/opt/bin/config.toml `
-v ${PWD}/assets:/opt/selenium/assets `
-v /var/run/docker.sock:/var/run/docker.sock `
selenium/standalone-docker:4.2.2-20220609
```



### Video recording, screen resolution, and time zones in a Dynamic Grid
To record your WebDriver session, you need to add a `se:recordVideo`
field set to `true`. You can also set a time zone and a screen resolution,
Expand Down Expand Up @@ -586,12 +618,12 @@ You can pass `SE_OPTS` variable with additional commandline parameters for start
$ docker run -d -p 4444:4444 -e SE_OPTS="--log-level FINE" --name selenium-hub selenium/hub:4.2.2-20220609
```

### JAVA_OPTS Java Environment Options
### SE_JAVA_OPTS Java Environment Options

You can pass `JAVA_OPTS` environment variable to java process.
You can pass `SE_JAVA_OPTS` environment variable to java process.

``` bash
$ docker run -d -p 4444:4444 -e JAVA_OPTS=-Xmx512m --name selenium-hub selenium/hub:4.2.2-20220609
$ docker run -d -p 4444:4444 -e SE_JAVA_OPTS=-Xmx512m --name selenium-hub selenium/hub:4.2.2-20220609
```

### Node configuration options
Expand All @@ -614,11 +646,11 @@ $ docker run -d -e SE_EVENT_BUS_HOST=<event_bus_ip|event_bus_name> -e SE_EVENT_B
### Setting Screen Resolution

By default, nodes start with a screen resolution of 1360 x 1020 with a color depth of 24 bits and a dpi of 96.
These settings can be adjusted by specifying `SCREEN_WIDTH`, `SCREEN_HEIGHT`, `SCREEN_DEPTH`, and/or `SCREEN_DPI`
These settings can be adjusted by specifying `SE_SCREEN_WIDTH`, `SE_SCREEN_HEIGHT`, `SE_SCREEN_DEPTH`, and/or `SE_SCREEN_DPI`
environmental variables when starting the container.

``` bash
docker run -d -e SCREEN_WIDTH=1366 -e SCREEN_HEIGHT=768 -e SCREEN_DEPTH=24 -e SCREEN_DPI=74 selenium/standalone-firefox:4.2.2-20220609
docker run -d -e SE_SCREEN_WIDTH=1366 -e SE_SCREEN_HEIGHT=768 -e SE_SCREEN_DEPTH=24 -e SE_SCREEN_DPI=74 selenium/standalone-firefox:4.2.2-20220609
```

### Grid Url and Session Timeout
Expand Down Expand Up @@ -663,12 +695,12 @@ captured in the same video.
[Chrome](https://developers.google.com/web/updates/2017/04/headless-chrome),
When using headless mode, there's no need for the [Xvfb](https://en.wikipedia.org/wiki/Xvfb) server to be started.

To avoid starting the server you can set the `START_XVFB` environment variable to `false`
To avoid starting the server you can set the `SE_START_XVFB` environment variable to `false`
(or any other value than `true`), for example:

``` bash
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub -e SE_EVENT_BUS_PUBLISH_PORT=4442 \
-e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -e START_XVFB=false --shm-size="2g" selenium/node-chrome:4.2.2-20220609
-e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -e SE_START_XVFB=false --shm-size="2g" selenium/node-chrome:4.2.2-20220609
```

For more information, see this GitHub [issue](https://github.com/SeleniumHQ/docker-selenium/issues/567).
Expand All @@ -677,11 +709,11 @@ For more information, see this GitHub [issue](https://github.com/SeleniumHQ/dock

In some environments, like Docker Swarm or Kubernetes, it is useful to shut down the Node or Standalone
container after N tests have been executed. For example, this can be used in Kubernetes to terminate the
pod and then scale a new one after N sessions. Set the environment variable `DRAIN_AFTER_SESSION_COUNT` to
pod and then scale a new one after N sessions. Set the environment variable `SE_DRAIN_AFTER_SESSION_COUNT` to
a value higher than zero to enable this behaviour.

``` bash
$ docker run -e DRAIN_AFTER_SESSION_COUNT=5 --shm-size="2g" selenium/standalone-firefox:4.2.2-20220609
$ docker run -e SE_DRAIN_AFTER_SESSION_COUNT=5 --shm-size="2g" selenium/standalone-firefox:4.2.2-20220609
```

With the previous command, the Standalone container will shutdown after 5 sessions have been executed.
Expand Down Expand Up @@ -883,7 +915,7 @@ The VNC server is listening to port 5900, you can use a VNC client and connect t
any free external port that you wish.

The internal 5900 port remains the same because that is the configured port for the VNC server running inside the container.
You can override it with the `VNC_PORT` environment variable in case you want to use `--net=host`.
You can override it with the `SE_VNC_PORT` environment variable in case you want to use `--net=host`.

Here is an example with the standalone images, the same concept applies to the node images.
``` bash
Expand All @@ -910,9 +942,9 @@ the posted ones which reconfigures it:
RUN x11vnc -storepasswd <your-password-here> /home/seluser/.vnc/passwd
```

If you want to run VNC without password authentication you can set the environment variable `VNC_NO_PASSWORD=1`.
If you want to run VNC without password authentication you can set the environment variable `SE_VNC_NO_PASSWORD=1`.

If you want to run VNC in view-only mode you can set the environment variable `VNC_VIEW_ONLY=1`.
If you want to run VNC in view-only mode you can set the environment variable `SE_VNC_VIEW_ONLY=1`.

### Using your browser (no VNC client is needed)

Expand All @@ -921,7 +953,7 @@ their browser. This might come handy if you cannot install a VNC client on your
noVNC, so you will need to connect to that port with your browser.

Similarly to the previous section, feel free to map port 7900 to any free external port that you wish.
You can also override it with the `NO_VNC_PORT` environment variable in case you want to use `--net=host`.
You can also override it with the `SE_NO_VNC_PORT` environment variable in case you want to use `--net=host`.

Here is an example with the standalone images, the same concept applies to the node images.
``` bash
Expand Down Expand Up @@ -970,7 +1002,7 @@ or

`Message: unknown error: Chrome failed to start: exited abnormally`

The reason _might_ be that you've set the `START_XVFB` environment variable to "false", but forgot to
The reason _might_ be that you've set the `SE_START_XVFB` environment variable to "false", but forgot to
actually run Firefox, Chrome or Edge in headless mode.

### Mounting volumes to retrieve downloaded files
Expand Down
2 changes: 1 addition & 1 deletion Router/start-selenium-grid-router.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if [ ! -z "$SE_ROUTER_PORT" ]; then
PORT_CONFIG="--port ${SE_ROUTER_PORT}"
fi

java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar router \
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar router \
--sessions-host "${SE_SESSIONS_MAP_HOST}" --sessions-port "${SE_SESSIONS_MAP_PORT}" \
--distributor-host "${SE_DISTRIBUTOR_HOST}" --distributor-port "${SE_DISTRIBUTOR_PORT}" \
--sessionqueue-host "${SE_SESSION_QUEUE_HOST}" --sessionqueue-port "${SE_SESSION_QUEUE_PORT}" \
Expand Down
2 changes: 1 addition & 1 deletion SessionQueue/start-selenium-grid-session-queue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if [ ! -z "$SE_SESSION_QUEUE_PORT" ]; then
PORT_CONFIG="--port ${SE_SESSION_QUEUE_PORT}"
fi

java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar sessionqueue \
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar sessionqueue \
--publish-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_PUBLISH_PORT} \
--subscribe-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_SUBSCRIBE_PORT} \
--session-request-timeout ${SE_SESSION_REQUEST_TIMEOUT} \
Expand Down
2 changes: 1 addition & 1 deletion Sessions/start-selenium-grid-sessions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if [ ! -z "$SE_SESSIONS_PORT" ]; then
PORT_CONFIG="--port ${SE_SESSIONS_PORT}"
fi

java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar sessions \
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar sessions \
--publish-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_PUBLISH_PORT} \
--subscribe-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_SUBSCRIBE_PORT} \
--bind-host ${SE_BIND_HOST} \
Expand Down
2 changes: 1 addition & 1 deletion Standalone/generate_config
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fi
echo "session-timeout = \"${SE_NODE_SESSION_TIMEOUT}\"" >> "$FILENAME"
echo "override-max-sessions = ${SE_NODE_OVERRIDE_MAX_SESSIONS}" >> "$FILENAME"
echo "detect-drivers = false" >> "$FILENAME"
echo "drain-after-session-count = ${DRAIN_AFTER_SESSION_COUNT}" >> "$FILENAME"
echo "drain-after-session-count = ${DRAIN_AFTER_SESSION_COUNT:-$SE_DRAIN_AFTER_SESSION_COUNT}" >> "$FILENAME"
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
" >> "$FILENAME"

Expand Down
2 changes: 1 addition & 1 deletion Standalone/start-selenium-standalone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi
echo "Selenium Grid Standalone configuration: "
cat /opt/selenium/config.toml
echo "Starting Selenium Grid Standalone..."
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar standalone \
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar standalone \
--bind-host ${SE_BIND_HOST} \
--config /opt/selenium/config.toml \
${SE_OPTS}
2 changes: 1 addition & 1 deletion StandaloneDocker/start-selenium-grid-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ ! -z "$SE_NODE_GRID_URL" ]; then
SE_GRID_URL="--grid-url ${SE_NODE_GRID_URL}"
fi

java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar standalone \
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar standalone \
--relax-checks ${SE_RELAX_CHECKS} \
--detect-drivers false \
--bind-host ${SE_BIND_HOST} \
Expand Down
9 changes: 9 additions & 0 deletions Video/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ RUN mkdir -p /var/run/supervisor /var/log/supervisor /videos
ENTRYPOINT ["/opt/bin/entry_point.sh"]
CMD ["/opt/bin/entry_point.sh"]

ENV DISPLAY_NUM 99
ENV DISPLAY_CONTAINER_NAME selenium
ENV SE_SCREEN_WIDTH 1360
ENV SE_SCREEN_HEIGHT 1020
ENV SE_FRAME_RATE 15
ENV SE_CODEC libx264
ENV SE_PRESET "-preset ultrafast"
ENV FILE_NAME video.mp4

EXPOSE 9000
18 changes: 9 additions & 9 deletions Video/video.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/bin/sh

VIDEO_SIZE=${VIDEO_SIZE:-"1360x1020"}
DISPLAY_CONTAINER_NAME=${DISPLAY_CONTAINER_NAME:-"selenium"}
DISPLAY=${DISPLAY:-"99"}
FILE_NAME=${FILE_NAME:-"video.mp4"}
FRAME_RATE=${FRAME_RATE:-"15"}
CODEC=${CODEC:-"libx264"}
PRESET=${PRESET:-"-preset ultrafast"}
VIDEO_SIZE="${SE_SCREEN_WIDTH}""x""${SE_SCREEN_HEIGHT}"
DISPLAY_CONTAINER_NAME=${DISPLAY_CONTAINER_NAME}
DISPLAY_NUM=${DISPLAY_NUM}
FILE_NAME=${FILE_NAME}
FRAME_RATE=${FRAME_RATE:-$SE_FRAME_RATE}
CODEC=${CODEC:-$SE_CODEC}
PRESET=${PRESET:-$SE_PRESET}

return_code=1
max_attempts=50
attempts=0
echo 'Checking if the display is open...'
until [ $return_code -eq 0 -o $attempts -eq $max_attempts ]; do
xset -display ${DISPLAY_CONTAINER_NAME}:${DISPLAY} b off > /dev/null 2>&1
xset -display ${DISPLAY_CONTAINER_NAME}:${DISPLAY_NUM} b off > /dev/null 2>&1
return_code=$?
if [ $return_code -ne 0 ]; then
echo 'Waiting before next display check...'
Expand All @@ -23,5 +23,5 @@ until [ $return_code -eq 0 -o $attempts -eq $max_attempts ]; do
done

# exec replaces the video.sh process with ffmpeg, this makes easier to pass the process termination signal
exec ffmpeg -y -f x11grab -video_size ${VIDEO_SIZE} -r ${FRAME_RATE} -i ${DISPLAY_CONTAINER_NAME}:${DISPLAY}.0 -codec:v ${CODEC} ${PRESET} -pix_fmt yuv420p "/videos/$FILE_NAME"
exec ffmpeg -y -f x11grab -video_size ${VIDEO_SIZE} -r ${FRAME_RATE} -i ${DISPLAY_CONTAINER_NAME}:${DISPLAY_NUM}.0 -codec:v ${CODEC} ${PRESET} -pix_fmt yuv420p "/videos/$FILE_NAME"

Loading

0 comments on commit 3c74143

Please sign in to comment.