0

My Python application needs to run on a Raspberry Pi 3 at startup and in a terminal.

What I did:

  1. I created a service screenscript.service in /etc/systemd/system
  2. a bash file in /home/pi/mydir/screen.sh
  3. a python application in /home/pi/mydir/code/hello.py

code 1, screenscript.service

Description=Terminal Service
After=network.target
[Service]
ExecStart=/home/pi/mydir/screen.sh
[Install]
WantedBy=multi-user.target

code 2, screen.sh

#!/bin/bash
cd home/pi/mydir/code
echo "work dir: '$(pwd)'" >> /tmp/log.log
/usr/bin/lxterminal -e "python /home/pi/mydir/code/hello.py"

code 3, hello.py

import threading

def printit():
  threading.Timer(5.0, printit).start()
  print "Hello, World!"

printit()

My issue:

I want to see 'hello world' continue display in a terminal, when I turn on the raspberry PI power. My service failed $systemctl status screenscript ---> shows loaded, enabled, active failed, code exited.

I can run this line $/usr/bin/lxterminal -e "python /home/pi/mydir/code/hello.py"

1

At a glance I see some errors. You missed the [Unit] statement before Description=Terminal Service in screenscript.service.

hello.py does not have any indention. This cannot work for a def.

With lxterminal you try to start a graphical program but your service is WantedBy=multi-user.target. This does not provide a graphical environment. You must use WantedBy=graphical.target.

If you want a graphical output you have to specify a display like Environment=DISPLAY=:0. Here is an example: How to make a service to run a python script which includes browser automation.

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.