(Disclaimer, this is a crosspost from my Unix & Linux Overflow question, however I got no answers)
To introduce my problem, I'm running Raspbian Stretch on a RPi 3 model B+, and I have two scripts that I run in /etc/rc.local so that the pi can run completely headless and control a GoPro over wifi based on sensor/GPIO input.
The first script is a bash script that simply connects to the GoPro wireless AP using wpa_cli. I've had no problems there (save when the goPro auto turns off for battery...).
The second script is a python script that sends some commands to the goPro over the wifi socket. It uses the urllib.request.urlretrieve(...) method. However, this script fails to execute when running from /etc/rc.local, failing with:
[ 50.119390] rc.local[516]: Traceback (most recent call last):
[ 50.120173] rc.local[516]: File "/usr/lib/python3.7/urllib/request.py", line 1317, in do_open
[ 50.124119] rc.local[516]: encode_chunked=req.has_header('Transfer-encoding'))
[ 50.127993] rc.local[516]: File "/usr/lib/python3.7/http/client.py", line 1229, in request
[ 50.132015] rc.local[516]: self._send_request(method, url, body, headers, encode_chunked)
[ 50.136108] rc.local[516]: File "/usr/lib/python3.7/http/client.py", line 1275, in _send_request
[ 50.140314] rc.local[516]: self.endheaders(body, encode_chunked=encode_chunked)
[ 50.144462] rc.local[516]: File "/usr/lib/python3.7/http/client.py", line 1224, in endheaders
[ 50.148440] rc.local[516]: self._send_output(message_body, encode_chunked=encode_chunked)
[ 50.152573] rc.local[516]: File "/usr/lib/python3.7/http/client.py", line 1016, in _send_output
[ 50.156713] rc.local[516]: self.send(msg)
[ 50.160973] rc.local[516]: File "/usr/lib/python3.7/http/client.py", line 956, in send
[ 50.165078] rc.local[516]: self.connect()
[ 50.169443] rc.local[516]: File "/usr/lib/python3.7/http/client.py", line 928, in connect
[ 50.173764] rc.local[516]: (self.host,self.port), self.timeout, self.source_address)
[ 50.177933] rc.local[516]: File "/usr/lib/python3.7/socket.py", line 727, in create_connection
[ 50.182306] [FAILED] Failed to start /etc/rc.local Compatibility.
rc.local[516]: raise err
See 'systemctl status rc-local.service' for details.
[ 50.186404] rc.local[516]: File "/usr/lib/python3.7/socket.py", line 716, in create_connection
[ 50.190904] Starting Terminate Plymouth Boot Screen...
rc.local[516]: sock.connect(sa)
[ 50.198463] Starting Hold until boot process finishes up...
rc.local[516]: OSError: [Errno 101] Network is unreachable
[ 50.202947] rc.local[516]: During handling of the above exception, another exception occurred:
[ 50.208240] rc.local[516]: Traceback (most recent call last):
[ 50.212360] rc.local[516]: File "/home/pi/goPro/gpioControlledGoPro.py", line 154, in <module>
[ 50.216155] rc.local[516]: SendCmd(startRecording)
The script runs perfectly fine once I run as a user in the command line, so I instead ran the script using sudo -H -u pi /usr/bin/python3 [script]. This helped, as the GoPro started the recording, but the second urllib.request.urlretrieve(...) failed, and a very similar error to the one above popped up. I definitely gave the script ample sleep time to make sure there was no interference with the bootup process, and there still was a connection, as I was able to immediately run the script once I logged in as pi with no issues whatsoever
Am I missing something about how the bootup works? Should I follow a different method to autoexecute?
Thanks.