I have a Raspberry Pi with a really useful Adafruit LCD display fitted, which is set up to run Arch. I’ve written a Python script to run at boot which uses gphoto2 to control a digital camera in order to take timelapse photographs. The script allows user to set the number of images to take, and the time lapse between each shot, using the LCD plate.
The script uses the command “gphoto2 –set-config-value” to instruct the camera to save the images on the SD card in the camera. If I run the script under Python (which has to be done with sudo to run the Adafruit modules), it runs correctly and saves the images on the camera. If I run it through systemd with a service script linking to the exact same file, either at boot or starting it with “sudo systemcontrol start gphoto.service”, it executes the command to set the config value, but then appears to ignore it. The script executes without error but the images are not saved. I have added logging to the script which shows the command being executed as below.
Under Python, it shows:
INFO:root:Executing --set-config-value /main/settings/capturetarget=1
INFO:root:Executing --get-config=capturetarget
INFO:root: Label: Capture Target
Type: RADIO
Current: Memory card
Choice: 0 Internal RAM
Choice: 1 Memory card
Under systemd, it shows:
INFO:root:Executing --set-config-value /main/settings/capturetarget=1
INFO:root:Executing --get-config=capturetarget
INFO:root: Label: Capture Target
Type: RADIO
Current: Internal RAM
Choice: 0 Internal RAM
Choice: 1 Memory card
I’ve run a stripped down version on a laptop running Arch, and the same issue occurs. I have also run it under openSUSE on a laptop also using systemd and the same thing happened, so I suspect this is an issue with systemd (or my use of it) rather than the Pi. I would add that I have run the same script under Raspbian (using init script) and this worked correctly both run as a Python script, and at boot as an init script (with the addition of a usbreset code to prevent it from hanging between shots; this code has also been added to the Arch version and the scripts on the two different OS are identical). Below is my service file. Does my problem lie with the (rather basic) service file, or is it elsewhere?
[Unit]
Description=GPhoto Python Timelapse script
[Service]
ExecStart=/home/pi/timelapse.py
[Install]
WantedBy=multi-user.target