Hello everyone. I am using a Jetson nano and I want to run a sh file that runs a docker container after the jetson is power on automatically. I was looking and some web pages advice use a service in/etc/systemd/system/windrobo.service after create the service I run the commands:
I already fix that error but I am still with others. when I run my file with bash run.sh everything runs well, the problem when is running as a service.
this is my run.sh file:
#!/usr/bin/env bash
# pass-through commands to 'docker run' with some defaults
# https://docs.docker.com/engine/reference/commandline/run/
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# check for V4L2 devices
V4L2_DEVICES=""
for i in {0..9}
do
if [ -a "/dev/video$i" ]; then
V4L2_DEVICES="$V4L2_DEVICES --device /dev/video$i "
fi
done
# check for display
DISPLAY_DEVICE=""
if [ -n "$DISPLAY" ]; then
# give docker root user X11 permissions
sudo xhost +si:localuser:root
# enable SSH X11 forwarding inside container (https://stackoverflow.com/q/48235040)
XAUTH=/home/windrobo/Documents/docker_xauth/.docker.xauth
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
chmod 777 $XAUTH
DISPLAY_DEVICE="-e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix -v $XAUTH:$XAUTH -e XAUTHORITY=$XAUTH"
fi
# check if sudo is needed
if id -nG "$(whoami)" | grep -qw "docker"; then
SUDO=""
else
SUDO="sudo"
fi
# run the container
ARCH=$(uname -i)
if [ $ARCH = "aarch64" ]; then
# this file shows what Jetson board is running
# /proc or /sys files aren't mountable into docker
cat /proc/device-tree/model > /tmp/nv_jetson_model
set -x
$SUDO docker run --runtime nvidia -it --rm --name windrobo2 --network host \
--privileged \
--device-cgroup-rule='c 189:* rmw' \
--volume /tmp/argus_socket:/tmp/argus_socket \
--volume /etc/enctune.conf:/etc/enctune.conf \
--volume /etc/nv_tegra_release:/etc/nv_tegra_release \
--volume $ROOT/data:/data \
--volume $ROOT/ros2_ws/src:/root/ros2_ws/src \
--volume /dev:/dev \
--device /dev/snd \
--device /dev/bus/usb:/dev/bus/usb \
$DATA_VOLUME $DISPLAY_DEVICE $V4L2_DEVICES \
"$@"
elif [ $ARCH = "x86_64" ]; then
set -x
$SUDO docker run --gpus all -it --network=host \
--shm-size=8g \
--ulimit memlock=-1 \
--ulimit stack=67108864 \
--env NVIDIA_DRIVER_CAPABILITIES=all \
--volume $ROOT/data:/data \
$DATA_VOLUME $DISPLAY_DEVICE $V4L2_DEVICES \
"$@"
fi
It comes from the jetson-containers. I fiexed the problem with the id changing the variable from $USER to $(whoami) but I am still with some problems:
● windrobo.service - Custom Startup Script
Loaded: loaded (/etc/systemd/system/windrobo.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2023-09-08 12:59:46 -05; 5min ago
Process: 7540 ExecStart=/bin/bash /home/windrobo/Desktop/dev_docker/run.sh windrobo:v9 (code=exited, status=1/FAILURE)
Main PID: 7540 (code=exited, status=1/FAILURE)
sep 08 12:59:46 windrobo-desktop systemd[1]: Started Custom Startup Script.
sep 08 12:59:46 windrobo-desktop bash[7540]: + sudo docker run --runtime nvidia -it --rm --name windrobo2 --network host --privileged '--device-cgroup-rule=c 189:* rmw' --volume /tmp/argus_socket:/tmp/argus_sock
sep 08 12:59:46 windrobo-desktop sudo[7549]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/docker run --runtime nvidia -it --rm --name windrobo2 --network host --privileged --device-cgroup-rule=c
sep 08 12:59:46 windrobo-desktop sudo[7549]: pam_unix(sudo:session): session opened for user root by (uid=0)
sep 08 12:59:46 windrobo-desktop bash[7540]: the input device is not a TTY
sep 08 12:59:46 windrobo-desktop sudo[7549]: pam_unix(sudo:session): session closed for user root
sep 08 12:59:46 windrobo-desktop systemd[1]: windrobo.service: Main process exited, code=exited, status=1/FAILURE
sep 08 12:59:46 windrobo-desktop systemd[1]: windrobo.service: Failed with result 'exit-code'.
Do you know what to do in this case ? thank you in advance for you time and consideration.
Due to the fact this is an especific problem. Does anyone run a container in a Jetson nano at startup ? I just wanted to run a container when my jetson is power on. In the commet below I was trying to use a service. However that is not working well.
Hello everyone. To fix this issue I add the flag --restart unless-stopped in the run docker command. After run once this start the container on startup every time.