Start jetson-inference container on boot up

Dear all,
I would like to run the jetson-inference container when my jetson nano is started(on boot).
So, I created a bash shell script which contains:

gnome-terminal --window -t "jetson session" --working-directory="/home/$username/jetson-inference" -- bash -c '{ echo "Session started successfully..." || echo "Session failed to start.See log file.";docker/run.sh -v /root/scripts:/custom_scripts > '${log_custom_scripts}' ;}  '

where

log_custom_scripts = "log_custom_scripts.txt" 
username = localuser

Then, I created myservice.service as following:


[Unit]
Description=Execute this on boot
After=multi-user.target

[Service]
Environment=XAUTHORITY=/home/localuser/.Xauthority   # Get the stored credentials of localuser to be authenticated
Environment=DISPLAY=:0           # This needs to enable GUI X session, right?
ExecStartPre=/bin/sleep 20       # Delay it just in case
ExecStart=/root/scripts/myscript.sh  

[Install]
WantedBy=multi-user.target

and I put it into the /etc/systemd/system.

I tested the service before enabling to start on boot:
sudo systemctl start myservice.service

and get the status in another terminal by
sudo systemctl status myservice.service

Unfortunately, I received:
the input device is not a TTY

I tried to start the container without the gnome-terminal but without success. More specific,
execute it in background

cd /home/$username/jetson-inference 
docker/run.sh -v /root/scripts:/custom_scripts > $log_custom_scripts &

or in foreground

cd /home/$username/jetson-inference 
docker/run.sh -v /root/scripts:/custom_scripts > $log_custom_scripts

I also tried


startx docker/run.sh -v /root/scripts:/custom_scripts > $log_custom_scripts

but I received

(==) Log file: "/var/log/Xorg.1.log", Time: Thu Apr 18 14:47:05 2024
(==) Using config file: "/etc/X11/xorg.conf"
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
/usr/bin/xterm: No absolute path found for shell: docker/run.sh
xinit: connection to X server lost

waiting for X server to shut down (II) Server terminated successfully (0). Closing log file.

For your information, I have followed these forum discussions:

I understand that jeston-inference container needs a GUI X session.
Is it possible to start the container in a GUI session?

I would really appreciate any help.

Regards,

Hi @konstantinos.kalogirou, I haven’t done this myself so YMMV, but you could try removing the -it (interactive terminal) part of the docker run command that jetson-inference/docker/run.sh makes

It doesn’t need display or X11, but if one is connected it will try to create a window by default (but should fail gracefully if it can’t)

Hi.

I removed the interactive terminal (-it) in the run.sh but without any success.
The docker starts and stops after a second. Specifically, I tried the followings:

cd /home/$localuser/jetson-inference && exec docker/run_play.sh -v /root/scripts:/custom_script
cd /home/$localuser/jetson-inference 
docker/run_play.sh -v /root/scripts:/custom_scripts &
cd /home/$localuser/jetson-inference 
docker/run_play.sh -v /root/scripts:/custom_scripts 
gnome-terminal --window -t "Monitoring session" --working-directory="/home/$localuser/jetson-inference" -- bash -c '{ echo "Session started successfully..." || echo "Session failed to start.See log file.";docker/run_play.sh -v /root/scripts:/custom_scripts > '${log_custom_scripts}' ;}  '

where run_play.sh is the run.sh without the -it.

I would like to run my shell script not from the /home/localuser/jetson-inference.

Regards,

Recommend that you try just using docker run directly or try running another basic container just for testing to figure out your start-up procedure.

My guess is that it is not actually running any command in the container, and without -it there is no interactive terminal attached, so it just exits.

Hello again.
I tried:

  1. Run as root user , create a new container to host it:
root@kalogirouk-desktop:~/scripts# docker run --name test_container -v /root/scripts:/home/kalogirouk/jetson-inference/ bash -c "docker/run.sh -v root/scripts"

**bash: line 1: docker/run.sh: No such file or directory**
  1. Run as root user or as local user (the same result)
kalogirouk@kalogirouk-desktop:~$ /home/$username/jetson-inference/docker/run.sh --volume /root/scripts:/custom_scripts

/home/kalogirouk/jetson-inference/docker/run.sh: line 156: docker/tag.sh: No such file or directory
localuser:root being added to access control list
DATA_VOLUME:      --volume /home/kalogirouk/data:/jetson-inference/data --volume /home/kalogirouk/python/training/classification/data:/jetson-inference/python/training/classification/data --volume /home/kalogirouk/python/training/classification/models:/jetson-inference/python/training/classification/models --volume /home/kalogirouk/python/training/detection/ssd/data:/jetson-inference/python/training/detection/ssd/data --volume /home/kalogirouk/python/training/detection/ssd/models:/jetson-inference/python/training/detection/ssd/models --volume /home/kalogirouk/python/www/recognizer/data:/jetson-inference/python/www/recognizer/data 
USER_VOLUME:      --volume /root/scripts:/custom_scripts 
V4L2_DEVICES:     --device /dev/video0 
DISPLAY_DEVICE:   -e DISPLAY=:0 -v /tmp/.X11-unix/:/tmp/.X11-unix
  1. Run as root or as local user,the same result either run.sh contains -it or it does not contain -it
root@kalogirouk-desktop:~/scripts# /home/kalogirouk/jetson-inference/docker/run.sh -v /root/scripts:/custom_scripts
/home/kalogirouk/jetson-inference/docker/run.sh: line 156: docker/tag.sh:No such file or directory
kalogirouk:root being added to access control list
DATA_VOLUME:      --volume /root/scripts/data:/jetson-inference/data --volume /root/scripts/python/training/classification/data:/jetson-inference/python/training/classification/data --volume /root/scripts/python/training/classification/models:/jetson-inference/python/training/classification/models --volume /root/scripts/python/training/detection/ssd/data:/jetson-inference/python/training/detection/ssd/data --volume /root/scripts/python/training/detection/ssd/models:/jetson-inference/python/training/detection/ssd/models --volume /root/scripts/python/www/recognizer/data:/jetson-inference/python/www/recognizer/data 
USER_VOLUME:      --volume /root/scripts:/custom_scripts 
V4L2_DEVICES:     --device /dev/video0 
DISPLAY_DEVICE:   -e DISPLAY=:0 -v /tmp/.X11-unix/:/tmp/.X11-unix 
**/home/kalogirouk/jetson-inference/docker/run_play.sh: line 198: [: =: unary operator expected**
**/home/kalogirouk/jetson-inference/docker/run_play.sh: line 213: [: =: unary operator expected**

I modified the lines 198 and 213 to
[[ $ARCH = “aarch64” ]] and
[[ $ARCH = “x86_64” ]] respectively.

I received the same error without the unary operators:

root@kalogirouk-desktop:~/scripts# /home/kalogirouk/jetson-inference/docker/run.sh -v /root/scripts:/custom_scripts
/home/kalogirouk/jetson-inference/docker/run.sh: line 156: docker/tag.sh: No such file or directory
kalogirouk:root being added to access control list
DATA_VOLUME:      --volume /root/scripts/data:/jetson-inference/data --volume /root/scripts/python/training/classification/data:/jetson-inference/python/training/classification/data --volume /root/scripts/python/training/classification/models:/jetson-inference/python/training/classification/models --volume /root/scripts/python/training/detection/ssd/data:/jetson-inference/python/training/detection/ssd/data --volume /root/scripts/python/training/detection/ssd/models:/jetson-inference/python/training/detection/ssd/models --volume /root/scripts/python/www/recognizer/data:/jetson-inference/python/www/recognizer/data 
USER_VOLUME:      --volume /root/scripts:/custom_scripts 
V4L2_DEVICES:     --device /dev/video0 
DISPLAY_DEVICE:   -e DISPLAY=:0 -v /tmp/.X11-unix/:/tmp/.X11-unix 

Regards,

@konstantinos.kalogirou see if you can get a different container to startup a boot like this as a test, then just take the docker run command that the jetson-inference script produces and substitute that instead. I don’t believe those scripts are independent of working directory, but the tools in jetson-containers are (which is what I use for building jetson-inference docker now)

I did some tests and I can start up a container.

Can you pleaes make more clear how to take the “docker run” command that the jetson inferenece produces?

Hi @konstantinos.kalogirou, you can find it here:

You can also add set +x to this script, and it will print out the exact commands as it runs those, and then you can just take them and run them yourself as desired.

After many tests, I realised that any docker container needs a TTY cannot start up on boot.

When I run my script service in the /etc/systed/system (systemctl enable my_script.service, systemctl start)

my_script.service), I receive the following reasonable messages:
my_script.sh[10426]: the input device is not a TTY
systemd[1]: my_script.service: Main process exited, code=exited, status=1/FAILU
systemd[1]: my_script.service: Failed with result 'exit-code'.

Here is the my_script.service:

[Unit]
Description=Execute this on boot
After=multi-user.target

[Service]
Environment=XAUTHORITY=/home/kalogirouk/.Xauthority
Environment=DISPLAY=:0
ExecStartPre=/bin/sleep 20
ExecStart=/root/scripts/my_script.sh 
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target

Unfortuantely, the other docker container I used to run does not need TTY(the -it options were not considered at all). So, my previous answer to you is not correct.

Futermore, I tested running docker in detach mode (-d parameter) but with the same result.

I do not know if it is feasible to start a docker container that needs a TTY in general in Ubuntu OS boot up but I will focus to start the jetson-infernece container in a more indirect way.

jetson-inference container doesn’t need TTY, it just starts it that way by default for ease-of-use for users during development. You should just be able to remove -it from the docker run command and it won’t use TTY anymore.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.