I am having a bit of a problem here, I really hope some of you can point me in the right direction:
I made a python3 program running a loop and checking if the file /DATALOGGER/DATALOGUSB/SETUP.py exists, and if it does the program continues. The DATALOGUSB directory is the mount point for a specific USB drive set up in etc/fstab with the UUID of the USB drive.
This all works flawless when I execute the script directly from the terminal - the OS mounts the USB drive in the correct place, the script recognizes that the SETUP.py file suddenly exists, and continues execution.
My issue is that I require the program to run headless and stand-alone, i.e. I need the python3 program to start up upon reboot and just wait for the USB drive. Once the drive is mounted, the program should just continue exactly like when I run it in the terminal. I have tried to start the program during startup both from the crontab and from rc.local - and the program starts up fine (I can see that from the status LEDs the program controls). Unfortunately, when I then afterwards insert the USB drive, the program does not recognize that the file SETUP.py suddenly exists - so it is just stuck waiting for that file. If I check using the desktop GUI, I can see that the USB drive does indeed mount to the correct mount point, but for some reason the python3 program does not recognize it.
I really have no idea what to do now, as to me it seems strange that the program executes correctly from the terminal - but not if it is scheduled via crontab or startet from rc.local upon reboot.
If anyone has any idea as to what might be wrong, please do not hesitate to reply.
Best regards, Rasmus
Minimum example of my python3 script. The functionality lies in the if os.path.isfile('DATALOGUSB/SETUP.py') branch, but the execution never gets here if the script is started from crontab or rc.local:
# Package import
from multiprocessing import Process
shutdown_flag = False
# The core functionalities of the program
# Program functionality, but execution never gets
# here when started from crontab or rc.local
# Main loop
datalogger_thread = Process(target=datalogger)
shutdown_flag = False
My etc/fstab file. The last line is my USB-drive set up by its UUID to mount to the described mount point (it is in one line with a blankspace between vfat and rw - I don't know if the format is correctly showed here). It does mount here, but if the DATALOGGER.py program above is started from crontab or rc.local, the program does not recognize the file SETUP.py as existing.
proc /proc proc defaults 0 0
/dev/mmcblk0p6 /boot vfat defaults 0 2
/dev/mmcblk0p7 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, no line here
# use dphys-swapfile swap[on|off] for that
UUID=CCE1-5BCB /home/pi/Documents/DATALOGGER/DATALOGUSB vfat rw,uid=1000,gid=1000,umask=000,nofail 0 0
Finally my rc.local file:
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
sudo python3 /home/pi/Documents/DATALOGGER/DATALOGGER.py &