send stdout/stderr to console for a systemd service
I wanted to do something similar, and setting StandardOutput=journal+console
worked for me. FWIW this is the relevant systemd documentation https://www.freedesktop.org/software/systemd/man/systemd.exec.html.
In your case you want want to look at the TTYPath
option, specifically the default value of systemd vs the default on your system. HTH.
Related videos on Youtube
Sasha
Inveterate settings-tweaker and knob-twiddler. "In app design, beauty derives from function, and every interface element has to be focused on helping your users do what they're there to do." ~ Josh Clark, Tapworthy "The three chief virtues of a programmer are: Laziness, Impatience and Hubris" ~ Larry Wall
Updated on June 04, 2022Comments
-
Sasha 6 months
I have an application that we're converting from using initd to systemd. The initd scripts used to run "myscript.bash start", but the user could also run "myscript.bash start". Now when the user runs "myscript.bash start", it runs systemctl (which itself launches "myscript.bash startup") to start the service. (This is obtuse, I know - the idea is to keep the version history of the contents of myscript.bash, but also to allow users to start the system the way they are used to, the switch to systemctl should be invisible).
Previously, if the user ran myscript.bash, they got a bunch of updates to the console on how the startup was going. Now that information is not going to the console. I've tried a couple of things, the most promising seemed to be setting StandardOutput & StandardError to tty:
StandardOutput=tty StandardError=tty ExecStart=/bin/bash -c './myscript.bash startup &' ExecStop=/bin/bash -c './myscript.bash shutdown'
But I get this error:
systemd[20694]: Failed at step STDOUT spawning /bin/bash: Inappropriate ioctl for device
I've looked at this: How to Pipe Output to a File When Running as a Systemd Service? (which gave me the idea to try StandardOutput=), but the goal there is to write to a file and I'm trying to get output to the user's console.
Is this because we have a script running systemctl, instead of it being launched directly by the user? Is there a way to do this?
-
Roman Marusyk almost 6 yearsWhile this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
-
papercrane almost 5 yearsI'm not getting the desired result with journal+console. Does "console" mean the system console, i.e. the monitor attached to the machine, or does it mean the user session that ran systemd? In my case I'm sshed into a machine and am running systemd --user start on a unit that forke. I want to see the ExecStart output in realtime in my ssh session.
-
xloto over 4 yearsFrom the link in the answer: "Journal+console, syslog+console and kmsg+console work in a similar way as the three options above but copy the output to the system console as well." See this answer for more info about system console: unix.stackexchange.com/questions/60641/…