0

I have written a python script that displays the image from the URL.

def image_func(link_image):
    img_cmd = "feh -F %s" %(link_image)
    os.system(img_cmd)
    os.system("pkill feh")

If I run the python program directly using

python main.py

it runs without any issue.

But if I run from the .service file .. it throws this error.

feh ERROR: You have no HOME, cannot read themes

I am running this from the root terminal rather than the user terminal.

.service file

[Unit]
Description=My device boot script service
After=multi-user.target

[Service]
Type=idle
user=user1
Environment=DISPLAY=:0
Restart=always
ExecStart=/root/MediaPlayer/venv/Include/start.sh > /dev/null

[Install]
WantedBy=multi-user.target
  • Error message says you have o 'HOME' environment variable set. Is 'user1' a valid user? Several confusing elements here. You're running as 'user1', but running a script saved in 'root' user directory. You're starting a bash script, but your code is in a python script. What is the relation between the two? And it looks like you're using a virtual environment. Are you sure that is initialised when you start your python script? – Dirk Aug 29 '18 at 8:19
  • user1 is a valid user. the start.sh script executes the python program – ron123456 Aug 29 '18 at 9:04
  • I would add some debug code to your bash / python scripts to show / save the environment, since that seems to be the problem area – Dirk Aug 29 '18 at 9:19
0

I do not understand why do you use Type=idle. Man systemd.service says:

Note that this type is useful only to improve console output, it is not useful as a general unit ordering tool ...

As far as I know you do not have any console output so this option seems to be unnecessary. You want to output graphics as far as I understand to display an image. Usually you can do this only After=graphical.target. The service is missing a HOME variable. In respect of the comments from @Dirk you are running your python script (not a bash script) as root from the command line. You should do exactly the same within the unit. By default root is used for executing. There is also no suppressing of (error) messages with redirection to /dev/null so you can look with journalctl -b -e if there are some messages from the python script. I would configure your unit as follows:

[Unit]
Description=My device boot script service
After=graphical.target

[Service]
Environment=DISPLAY=:0
Restart=always
ExecStart=/usr/bin/python main.py

[Install]
WantedBy=graphical.target
  • Hi, I tried your solution .. but still the same issue. – ron123456 Aug 30 '18 at 4:47
  • @ron123456 I have updated my answer. Please give me feedback if it runs. – Ingo Aug 30 '18 at 10:05
  • @ron123456 Do you get some error messages with systemctl status deviceboot.service and journalctl -e --unit=deviceboot.service, or what the name of your device is? – Ingo Sep 3 '18 at 21:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.