3

I have an application that writes and reads to an interactive terminal, and when I run it via the shell, it works as expected. However, when I run it as a systemd service, it seems as though the application isn't capturing the stdout or stderr.

I have tried modifying the StandardOutput and StandardError in the service definition to journal+console and tty.

The service section of my systemd file looks like this :

[Service] 
ExecStart=/bin/bash -c "cd /somedir && python3 myapp.py" 
ExecStop= 
Restart=always 
RestartSec=10
StandardOutput=tty 
StandardError=tty

I have also tried setting TTYPath=/dev/tty2, but no luck.

I am running Ubuntu 16.04.

Edit: More info

When I run this app, the interactive session that it creates does not get read from/written to in the terminal where I actually run the app. It emulates its own terminal.

See link here:

http://docs.paramiko.org/en/2.4/api/channel.html#paramiko.channel.Channel.get_pty

and here:

http://docs.paramiko.org/en/2.4/api/channel.html#paramiko.channel.Channel.invoke_shell

9
  • 1
    What does systemctl status -l (servicename) show? Commented Feb 11, 2018 at 6:18
  • @ErikF it shows that it's running, are you looking for something specific? Commented Feb 11, 2018 at 7:54
  • I wanted to know whether or not the service had died, so that's helpful. You indicated that the program reads input: does this program require input to start working? If so, are you supplying that input from somewhere? Commented Feb 11, 2018 at 8:09
  • 1
    Maybe you want to first test the tty output with something like ExecStart=/bin/echo "Hello" to exclude problems with the myapp.py application. Just tested on a Ubuntu 16.04 VM and TTYPath=tty2. Saw that the getty@tty2 service is only activated when you switch to it. So defined a dependency [email protected], now it seems to work but the first output of executing the service is not logged. Commented Feb 11, 2018 at 8:59
  • 3
    This answer is relevant: unix.stackexchange.com/questions/339638/… . It seems as though points 3 and 4 of the answer are relevant to this situation. Commented Feb 12, 2018 at 22:14

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.