Permissions on /dev entries

I created two files, ecu.py and /etc/systemd/system/boo.service

ecu.py

#!/bin/env
print("hello world")

/etc/systemd/system/boo.service

[Unit]
Description=example systemd service unit file.

[Service]
Type=simple
User=user

StandardOutput=tty
TTYPath=/dev/pts/1

WorkingDirectory=/home/user
ExecStart=/usr/bin/python3 ecu.py

[Install]
WantedBy=multi-user.target

In my system, my login is user and my tty is pts/1

sudo systemctl start boo.service pops on my terminal hello world

maybe this can help you.

2 Likes

I have tried various combinations with your suggestion. Initially I started out by pasting exactly what you wrote to my boo.service. Initially the only change I made is to my home directory which is pi not user I then tried changing tty to pi. No effect on my system.

I do not understand the implications of TTYPath=/dev/pts/1 but based on the below I tried 0, 1, ptmx. None produced any output. Not even a new terminal was opened.

pi@bananapi:~$ ls -al /dev/pts/
total 0
drwxr-xr-x  2 root root      0 Jan  1  1970 .
drwxr-xr-x 15 root root   4940 Jul 11 15:28 ..
crw--w----  1 pi   tty  136, 0 Jul 11 15:29 0
crw--w----  1 pi   tty  136, 1 Jul 11 15:30 1
c---------  1 root root   5, 2 Jan  1  1970 ptmx
pi@bananapi:~$

user pi is logged on, ps will show the terminal associated with it. The idea is to tell systemd to output to that tty. In my case:

user@cw:~$ ps
    PID TTY          TIME CMD
2003339 pts/1    00:00:00 bash
2003353 pts/1    00:00:00 ps
user@cw:~$

user@cw:~$ ll /dev/pts/1
crw--w---- 1 user tty 136, 1 Jul 11 07:00 /dev/pts/1
user@cw:~$ 

show ps when logged on as pi@bananapi This will tell you the tty. Verify that tty exists in /dev with correct perms.

1 Like

From this link, systemd.exec

StandardOutput=

Controls where file descriptor 1 (stdout) of the executed processes is connected to. Takes one of inherit, null, tty, journal, kmsg, journal+console, kmsg+console, file:path, append:path, truncate:path, socket or fd:name.

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.

2 Likes

I will investigate the above later. In the meantime here is the response to the command!!!

sudo systemctl status boo.service
● boo.service - example systemd service unit file.
     Loaded: loaded (/etc/systemd/system/boo.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2024-07-11 17:40:45 CEST; 1min 18s ago
    Process: 2447 ExecStart=/bin/python3 /home/pi/ECU.py (code=exited, status=209/STDOUT)
   Main PID: 2447 (code=exited, status=209/STDOUT)

Jul 11 17:40:45 bananapi systemd[1]: Started example systemd service unit file..
Jul 11 17:40:45 bananapi systemd[2447]: boo.service: Failed to set up standard output: No such file or directory
Jul 11 17:40:45 bananapi systemd[2447]: boo.service: Failed at step STDOUT spawning /bin/python3: No such file or directory
Jul 11 17:40:45 bananapi systemd[1]: boo.service: Main process exited, code=exited, status=209/STDOUT
Jul 11 17:40:45 bananapi systemd[1]: boo.service: Failed with result 'exit-code'.

1 Like

Based on a suggestion from another forum the below worked fine for me:

[Service]
StandardOutput=tty
TTYPath=/dev/tty9

In order to see the effect of the print statement one just has to do Cntl+Alt+F9.

To return to the GUI , I had to use Cntl+Alt+F7. This may be different for other GUI's

This basically means that the earlier suggestion by @pavlos_kairis of using tty1 would have worked too as all I needed to do was press Cntl+Alt+F1.

Thanks for all the help.

1 Like