Python Forum
Run script on startup in Debian with systemd?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run script on startup in Debian with systemd?
#1
I'm trying to run Peppy player on startup in Debian 10: https://github.com/project-owner/Peppy.doc/wiki/Expert

Since rc.local is deprecated I'm trying to do it with systemd.
In rc.local you normally start Peppy with:
Quote:su haegarthehorrible -c 'cd /home/haegarthehorrible/Peppy; openvt -s -- python3 peppy.py'

I did read it is better to install a custom version of Python so if the system Python gets update nothing breaks.
So i did:
Quote:~$ cd ~
~$ mkdir tmp
~$ cd tmp
~$ wget https://www.python.org/ftp/python/3....n-3.8.4rc1.tgz
~$ tar zxvf Python-3.8.4rc1.tgz
~$ cd Python-3.8.4rc1
~$ ./configure --prefix=$HOME/opt/python-3.8.4rc1
~$ make
~$ make install

~$ cd ~
~$ nano .profile

>> Add to .profile:
export PATH=$HOME/opt/python-3.8.4rc1/bin:$PATH

~$ . ~/.profile

For systemd i tried:
Quote:~$ mkdir -p ~/.local/share/systemd/user
~$ nano ~/.local/share/systemd/user/peppy.service

[Unit]
Description=Start Peppy
After=multi-user.target

[Service]
Type=idle
User=haegarthehorrible
WorkingDirectory=/home/haegarthehorrible/Peppy
ExecStart=/home/haegarthehorrible/opt/python-3.8.4rc1/bin '/home/haegarthehorrible/Peppy openvt -s -- peppy.py'
Restart=always
RemainAfterExit=no

[Install]
WantedBy=multi-user.target

~$ systemctl --user daemon-reload
~$ systemctl --user enable peppy.service

But no matter what i try in the peppy.service i get:
Quote:~$ systemctl --user status peppy.service
● peppy.service - Start Peppy
Loaded: loaded (/home/haegarthehorrible/.local/share/systemd/user/peppy.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-07-03 17:10:35 CEST; 3s ago
Process: 609 ExecStart=/home/haegarthehorrible/opt/python-3.8.4rc1/bin /home/haegarthehorrible/Peppy/peppy.py (code=exited, status=216/GROUP)
Main PID: 609 (code=exited, status=216/GROUP)

My user is in this groups: haegarthehorrible tty cdrom floppy sudo audio dip video plugdev netdev

Is that auto login part even needed when done right?:
Quote:~$ mkdir -p /etc/systemd/system/[email protected]
~$ sudo nano /etc/systemd/system/[email protected]/override.conf

[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin haegarthehorrible --noclear %I 38400 linux

So what is the right way to do it?
Reply
#2
Ok, if i do this in Putty over SSH on my workstation:
Quote:~$ cd /home/haegarthehorrible/Peppy
~/Peppy$ sudo python3 peppy.py
Peppy is showing up on the connected LCD.

But why do i need sudo? Without it i get:
Quote:Hello from the pygame community. Contribute - pygame wiki
Traceback (most recent call last):
File "peppy.py", line 2312, in <module>
main()
File "peppy.py", line 2308, in main
peppy = Peppy()
File "peppy.py", line 93, in __init__
self.util = Util(connected_to_internet)
File "/home/haegarthehorrible/Peppy/util/util.py", line 131, in __init__
self.config_class = Config()
File "/home/haegarthehorrible/Peppy/util/config.py", line 366, in __init__
self.pygame_screen = self.get_pygame_screen()
File "/home/haegarthehorrible/Peppy/util/config.py", line 1242, in get_pygame_screen
pygame.display.init()
pygame.error: Unable to open a console terminal
Reply
#3
Normally when you log in on the console, you are given access to the screen and keyboard. When you log in via SSH, you don't have that access. Other users shouldn't by default have access to those devices.

As root, you override that restriction.
Reply
#4
I tried many Python systemd examples i found with Google.
They are all different but nothing works :-(
Reply
#5
I'm closer now.

It seems like i need some kind of X.
I did install different things but I'm not sure what really is needed.
Quote:sudo apt install xserver-xorg-core
sudo apt install xserver-xorg-input-evdev
sudo apt install x11-xserver-utils
sudo apt install x11-xkb-utils
sudo apt install x11-utils
sudo apt install openbox
sudo apt install xauth
sudo apt install xinit

Then i did:
Quote:nano ~/.profile
#Startx Automatically
if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
. startx
logout
fi

nano ~/.xinitrc
#!/bin/sh
x-terminal-emulator

This starts X and the Terminal and then touch is working.
If i do:
~$ cd /home/haegarthehorrible/Peppy
~/Peppy$ python3 peppy.py
directly on the machine then Peppy starts and also the touchscreen works in Peppy.

Only thing i still can't figure out is how to start Peppy on boot.
Should also be possible with xinitrc.
But when i do:
Quote:#!/bin/sh
x-terminal-emulator &
exec python3 /home/haegarthehorrible/Peppy/peppy.py
it does not work. I have then some kind of loop and Peppy does not start.
Reply
#6
Ok, i have it working if i use X.

But how can it be done with systemd?
I'm searching since days for a solution and nothing really works.
I can't believe that there is no solution because rc.local is deprecated since a long time and a lot of people are using python or pygame.

Here is everything i tried to start pygame:
https://www.diyaudio.com/forums/pc-based...ost6272111

I guess the biggest problem is that Python can't find the pip packages.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using Autostart to run a GUI program at startup. Rpi Edward_ 1 577 Oct-28-2023, 03:19 PM
Last Post: SpongeB0B
  [SOLVED] [Debian] UnicodeEncodeError: 'ascii' codec Winfried 1 988 Nov-16-2022, 11:41 AM
Last Post: Winfried
  how to startup canbus interface on pi korenron 2 2,184 Oct-24-2021, 09:51 PM
Last Post: DeaD_EyE
  pexpect startup help korenron 2 3,433 Apr-27-2021, 07:23 AM
Last Post: korenron
  Error when running script on startup in Linux NoahTheNerd 0 1,926 Mar-07-2021, 04:54 PM
Last Post: NoahTheNerd
  Debian ... oops! millpond 6 3,082 Aug-22-2019, 04:09 AM
Last Post: millpond
  Python Script Spawned by Cron or Systemd doesn't write files..? johnnyrobot 2 2,536 May-24-2019, 07:04 PM
Last Post: Larz60+
  run python script on startup? korenron 1 3,106 May-06-2019, 09:18 PM
Last Post: snippsat
  Python script runs on startup but does not register keystrokes. mericanpi 3 3,381 Sep-07-2018, 02:58 PM
Last Post: mericanpi
  Complete Beginner Startup - Simply run github code for hpd20 Image_Engine 8 4,638 Apr-23-2018, 11:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020