Hallo,
anläßlich der Diskussion über systemd:
Mein Problem Python-Pygame-Skripte laufen nur mit root-Rechten.
Starte ich ein Skript unter Benutzer 'pi', kommt die Fehlermeldung: "pygame.error: Unable to open a console terminal".
Es gibt ein Rezept, das Skript als Service mit Benutzer 'pi' zu starten.
EDIT 04.05.2018 (Rechte) -->
Benutzer 'pi muß in folgenden Gruppen sein
pi@pipaos4:~/Peppy$ id
uid=1001(pi) gid=1001(pi) groups=1001(pi),5(tty),27(sudo),29(audio),44(video),101(input)
Rezept für den pygame-test service:
<-- EDIT 04.05.2018 (Rechte)
[Unit]
Description=Python3 pygame test service
Wants=network-online.target
After=rsyslog.service
After=network-online.target
[Service]
Restart=no
ExecStart=/usr/local/bin/start_pygame_script.sh # <-- von mir angepasst
ExecStop=/bin/kill -INT $MAINPID
OOMScoreAdjust=-100
TimeoutStopSec=10s
User=pi
WorkingDirectory=<directory-of-pygame-script> # <-- von mir angepasst
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty2 # I also tried /dev/tty1 and that didn't work for me
[Install]
WantedBy=multi-user.target
Alles anzeigen
Das funktioniert auch.
Da frage ich mich nach dem Unterschied.
Auffällig sind mir die Parameter StandardInput, StandardOutput und TTYPath.
Das man sagt dazu
Spoiler anzeigen
StandardInput=<br>
- Controls where file descriptor 0 (STDIN) of the executed processes is connected to. Takes one of
null
,tty
,tty-force
,tty-fail
,data
,file:path
,socket
orfd:name
. - If
tty
is selected, standard input is connected to a TTY (as configured byTTYPath=
, see below) and the executed process becomes the controlling process of the terminal. If the terminal is already being controlled by another process, the executed process waits until the current controlling process releases the terminal.
StandardOutput=
-
Controls where file descriptor 1 (STDOUT) of the executed processes is connected to. Takes one of inherit
,null
,tty
,journal
,syslog
,kmsg
,journal+console
,syslog+console
,kmsg+console
,file: path
,socket
orfd:name
. -
tty
connects standard output to a tty (as configured viaTTYPath=
, see below). If the TTY is used for output only, the executed process will not become the controlling process of the terminal, and will not fail or wait for other processes to release the terminal.
TTYPath=
- Sets the terminal device node to use if standard input, output, or error are connected to a TTY (see above). Defaults to
/dev/console
Meine Frage: kann ich die Service-Definition in ein Shell-Skript umwandeln?
Schönen Gruß, kle
EDIT:
PS: probiert habe ich schon: python3 my-pygame-script.py </dev/tty2 >/dev/tty2
gleicher Fehler: Unable to open a console terminal".
In diesem Zusammenhang fiel mit noch auf "TTYPath= ...Defaults to /dev/console
"
EDIT 03.05.2018: Problem gelöst mit Manuls Beitrag #13 und #16