Jetson nano auto run python code when power up

In my project. I want to run python3 code( especially AI code) when power up on jetson nano.
Can anyone help me how to do that. Tks a lot :)

Hi,

Jetson is a L4T (Linux for Tegra) system so you can setup the startup program similar to Linux system.
Here is a related topic for your reference:
https://devtalk.nvidia.com/default/topic/1029769/jetson-tx2/how-to-auto-run-shell-script-made-by-me-when-tx2-system-is-booted-/

Thanks.

Hi AastaLL
I have read this post. It make me so confused. Can you describe in detail how to use this ?
/etc/profile.d/bash_completion.sh
Thanks & BR.

How to make something run on boot with systemd systems:

  1. Create a file named “/usr/local/bin/mything.sh” with the commands you need to run on start:
$ sudo nano /usr/local/bin/mything.sh
...
$ sudo chmod +x /usr/local/bin/mything.sh
  1. Create a file called “/etc/systemd/system/mything.service”

  2. In this file, put this text:

[Unit]
Description=mything: do my own thing
After=multi-user.target

[Service]
ExecStart=/usr/local/bin/mything.sh
Restart=always
StartLimitInterval=10
RestartSec=10

[Install]
WantedBy=multi-user.target

(If your thing needs the X windows GUI to be running, change all “multi-user.target” to be “graphical.target” in the above file)

  1. Run these two commands in a shell:
$ sudo systemctl enable mything.service
$ sudo systemctl start mything.service
1 Like

Hi snarky.
so how I can interrup it when i want ?? Meaning I want to stop after it runs for a while to edit.

It may be desirable to mything.sh as a dedicated user (root:root is the default). Adding these lines to the [Service] section will accomplish that:

[Service]
...
User=foo
Group=foo
...

(where foo is some limited user created something like this):

useradd -md /var/foo-data -rUs /bin/false foo

If you need access to the GPU, the user will have to be in the video group:

usermod -a -G video foo

That will create a “foo” system user and group with a home in /var/foo-data where you can put files created by your app. Your app get this path with os.path.expanduser('~') in Python, or like this in C/C++.

so how I can interrup it when i want ?? Meaning I want to stop after it runs for a while to edit.

systemctl stop mything.service

Will send SIGINT to mything.sh (or whatever the ExecStart line is). Your process can handle that however you chose.

systemctl reload mything.service

Will send SIGHUP so you can use that to reload a configuration for example, without actually stopping your process.

it’s not working

How is it failing?

Hi snarky, I try to config follow you guide, but it’s still not working.
When i check status of mything.service file (via cmd: sudo systemctl status mything.service), the log is displayed:

swarmrobotic@swarmrobotic-desktop:~$ sudo systemctl status mything.service
● mything.service - mything: do my own thing
Loaded: loaded (/etc/systemd/system/mything.service; enabled; vendor preset:
Active: activating (auto-restart) (Result: exit-code) since Thu 2020-04-02 16
Process: 8036 ExecStart=/usr/local/bin/mything.sh (code=exited, status=203/EXE
Main PID: 8036 (code=exited, status=203/EXEC)

I see other .service file has Active is actived.
So how can I do anything?
Many thanks.

Hi Guys,

I am trying the same. Nevertheless I got code=exited, status=2.
My code needs runs under a virtual environment , So i had to specify the python path.
When I try the ExcStart line from my terminal it runs, so I discarded the path wasn’t accurate.
Next thought is the my python script requires OpenGL, So I am not sure if that is making this service exit.