Failing to have a python code run on startup on Ubuntu 18.04 (running on Jetson TX2). Help?

Hi,

I have a Python code on NVIDIA Jetson TX@ (running Ubuntu 18.04) that records videos upon receiving commands (via serial communication with another hardware). The recording is done by the IP camera connected to the Ethernet Port of NVIDIA Jetson TX2. The video files are saved at the same path where the Python code is.

I would like to have the python code run on startup as soon as the board is booted.

So far I have used crontab @ reboot and adding rc.local service. Both did not work for me. Sometimes the video files would get saved but would not have any footage. They are saved as 0s duration video files with black screen, as if the code failed to access the camera stream.

Sometimes, the code stops running after the first serial command is sent. So if I want to send another command, it won’t work because the code isn’t running anymore upon checking ps -ax|grep python3.

I used these steps for rc.local method. I then added the script path to the rc.local file.

I have also tried adding the code in Startup Applications. Did not work.

It works perfectly fine if run the script manually etc. I run the code and the board is ready to receive serial commands and record videos.

I don’t know what I am doing wrong in executing these startup techniques but I think it’s something just very small that I am missing. I would like to know what I could be doing wrong.

Also, is there anything else I could use to achieve this that might work?

Thanks.

Try to put the script to /etc/network/if-up.d/

This looks like a duplicate of:
https://forums.developer.nvidia.com/t/running-python-code-on-startup-using-systemd-code-does-start-at-boot-up-but-stops-and-service-ends/159417

I will suggest testing if the camera command works when there is no GUI session running. It is possible that if you use camera software which requires the X GUI desktop to be running, then the python will run, but the camera won’t record anything.

Also, any rc.local content should be in the form of bash scripting since Jetsons do not run this with systemd:

# systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: inactive (dead)
     Docs: man:systemd-rc-local-generator(8)