1

I need to setup a Jetson Nano device so that a Python script is launched everytime an Internet connection is available.

So, referring to this question, I did the following:

  • I created the 'run_when_connection_available' script:
#!/bin/sh

# create a dummy folder to check script execution
mkdir /home /user_name/dummy_folder_00

# kill previous instances of the system
pkill python3

# move to folder with python script and launch it
cd /home/user_name/projects/folder
/usr/bin/python3 launcher.py --arg01 --arg02 ...

# create another dummy folder to check script execution
mkdir /home /user_name/dummy_folder_01

  • I made this script executable and I copied it to /etc/network/if-up.d

Now, everytime I plug the ethernet cable out and in again, I can see the dummy folders are created in /home/user_name, but the python script isn't launched (at least, it doesn't appear in the system monitor). I tried running the command in the script from the terminal, and everything works fine, the python program starts as expected. Am I doing something wrong?

Carlo
  • 1,321
  • 12
  • 37

2 Answers2

1

I'm trying to figure out something similar to you, but not quite the same..

This solution got my script python script running upon internet connection, I can check the logs and everything is working fine:

Raspbian - Running A Script After An Internet Connection Is Established

However, my script uses notify-send to send notifications to my window manager which I can't seem to get working with systemd - the script works when run inside of the user space so I assume it's something to do with systemd and Xorg. Hopefully that shouldn't be a problem for you, I hope this solves your issue.

You shouldn't need a bash script in the middle, I got systemd service to run my python script with chmod u+x <file>.py and putting #!/usr/bin/env python3 at the top of the python file so that it's executable directly under the .service file like so:

ExecStart=/path/to/file/file.py

1

Ok, I guess it was a matter of permissions, I solved it by running everything as user_name, so I modified the script as

sudo -user user_name /usr/bin/python3 launcher.py --arg01 --arg02 ...
Carlo
  • 1,321
  • 12
  • 37