Sample Header Ad - 728x90

Interact with Linux service via SSH

0 votes
1 answer
585 views
I've rented a server which I access using the Terminus SSH terminal. I've created a program that has prompts and takes input and works as intended when started normally. But I've created a service to automatically launch it at startup, or when it crashes, but when it's launched from the service it doesn't print any output to the terminal or take any input. If I leave the Standardinput and Standardoutput blank in the unit file, and use the systemctl status command, I can see the prompts that the program is supposed to print when it's started, but I still cant give it any commands. I've tried setting the Standardinput and Standardoutput to tty and also tty-force and the TTYPath to /dev/pts/0, because it says thats the tty I'm using. When I do that though it still doesn't give any output or take any input, and also doesn't even give any of the starting output when I use the systemctl status command, same when I use the /dev/console as the TTYPath, which I read is supposed to be the default. So I don't know why it would display those prompts in the systemd status when no standardinput or ouput are set but not display them when they're set to /dev/console, if that's the default. I've also tried several other ttys like ptyp0, ptyp1, tty0, tty2, and stdin/stdout, but still can't get it to work. Any suggestions? I've realised there may be issues if it tries to connect to the SSH terminal when I'm not connected to it, if that's the case is there a way to setup a virtual terminal that stays open and use that for the input and output, then just connect to that terminal whenever I log in via SSH? How would I go about creating the virtual terminal via SSH, and also connecting to it? I've tried chvt 0 and chvt 1 but got "Couldn't get a file descriptor referring to the console.", also tried it using sudo su -, but still the same response. Here's the unit code
[Unit]
Description= Makes sure server stays running

[Service]
Type=simple

TTYPath=/dev/pts/0
StandardInput=tty
StandardOutput=tty

ExecStart=/usr/lib/jvm/jdk-19/bin/java  -cp /apps/server/lib/*:/apps/server/src packages/Server

Restart=always
RestartSec= 30

[Install]
WantedBy=default.target
Asked by Michael (1 rep)
Jan 9, 2023, 02:32 AM
Last activity: Jan 9, 2023, 06:50 PM