Jetson nano auto run python code when power up

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
3 Likes