0

I have a python script that imports GPIO, json, smtplib, requests and threading.

The script POSTs JSON to an API, sends alerts via smtp server and logs data to a TXT file.

Program runs OK from terminal. I am trying to create a systemd unit to start on boot. I keep getting this error in my log file:

Connection Aborted, OSError(101, Network is unreachable)

Here is the file in /lib/systemd/system:

[Unit]
Description=My Service
Wants=basic.target local-fs.target network-online.target network.target
After=basic.target local-fs.target network-online.target network.target

[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/MyScripts/StartUps/MyStartUp.py

[Install]
WantedBy=basic.target local-fs.target network-online.target network.target

The file is the result of my trying different things attempting to solve the problem. I don't completely understand all the parts.

It appears the service I created is starting before the network service. I would like my service to start after everything else has started on the Pi.

Thx

  • Is the network up when the script runs? There is an option available from raspi-config to wait for the network. – Steve Robillard Feb 21 '17 at 0:17
  • Set the boot option to Wait for Network at Boot and it still gives the same error. Put a one-shot sleep(10.00) at start of program. It now works. I guess the 10 second delay allows the network to start. I'd like to start the program after the network is online during the boot instead of using an arbitrary time in the code. Using systemd unit file or another method. Any ideas? – Scott Clemons Feb 21 '17 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.