Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GPhoto and Systemd Issue

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help!
View previous topic :: View next topic  
Author Message
philm36



Joined: Wed Aug 21, 2013 8:47 pm
Posts: 4

PostPosted: Sat Aug 24, 2013 9:43 am    Post subject: GPhoto and Systemd Issue Reply with quote

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
Back to top
View user's profile Send private message
philm36



Joined: Wed Aug 21, 2013 8:47 pm
Posts: 4

PostPosted: Mon Nov 25, 2013 9:00 pm    Post subject: Update Reply with quote

This was also submitted to the magazine and a solution printed in LXF178.

“This is not an issue with systemd but with the environment in which the script is being run.There is a difference between running a script or program from a daemon such as systemd and from a shell. When you open a shell session, a specific environment is set up - that environment is not present when running from a daemon, even though it is running as the same user. The issue here is not that you are running the script from systemd, but that you are not running it from a shell session.”

The recommendation is to run the Python script within the correct environment by using a wrapper script:
#!/bin/bash
source /root/.bash_profile
/home/pi/timelapse.py

I’ve now resorted to trying to fix this on my laptop before committing it to the Pi. I have Arch on a laptop and on a PC, and /root/.bash_profile did not exist on either. I have tried calling /home/user/.bash_profile within the wrapper, calling /etc/skel/.bash_profile, and creating /root/.bash_profile by copying from both /home/user, and from /etc/skel. In all cases, running the wrapper script in a terminal session causes the script to run correctly and store images on the SD card. If it is run through systemd, the script runs OK but fails to save the images to the SD card.

So I’m currently trawling through anything I can find on bash environment settings. And that’s where I am with this now.
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8450
Location: Warrington, UK

PostPosted: Mon Nov 25, 2013 10:42 pm    Post subject: Reply with quote

Do you have no profile files at all in your home directory? What about /etc/profile?
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
philm36



Joined: Wed Aug 21, 2013 8:47 pm
Posts: 4

PostPosted: Sat Dec 14, 2013 12:16 pm    Post subject: Reply with quote

Sorry for not replying sooner

I have been trying to get my head around sessions and profiles and, after reading through various webpages, including the Arch wiki pages, have tried the following:

1. copying the .bash_profile file from /etc/skel to /root and sourcing it;
2. sourcing the .bash_profile in /home/pi;
3. sourcing /etc/profile

All have the same result - the script executes and triggers the camera to take the required number of shots, but fails to set the config value to save the images on the SD card
Back to top
View user's profile Send private message
philm36



Joined: Wed Aug 21, 2013 8:47 pm
Posts: 4

PostPosted: Tue Jul 08, 2014 11:04 am    Post subject: Solution Reply with quote

Finally came back to this and have solved the issue.

The command “gphoto2 –set-config-value” does not change the settings in the camera, but writes them to file .gphoto2/settings in the home directory. When run under systemd, this HOME environment variable was not set (even when using the /root/.bash_profile). I could probably have set this in the profile, but opted to replace the "source /root/.bash_profile" line with "export HOME=/home/pi".
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help! All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast