大网数据广告活动
服务器运维问答

Interacting with a program running as part of a systemd service

· 52CE 我爱测

I've got a systemd service set up with the following configuration (in /etc/systemd/system/my-service.service ): [Unit] Description=My service [Service] WorkingDirectory=/path/to/my/service User=some-user Group=some-group Restart…

问题原文

原帖链接 · Sean · CC BY-SA 3.0

I've got a systemd service set up with the following configuration (in /etc/systemd/system/my-service.service):

[Unit]
Description=My service

[Service]
WorkingDirectory=/path/to/my/service
User=some-user
Group=some-group
Restart=on-failure
RestartSec=20 5
ExecStart=my-service-binary

[Install]
WantedBy=multi-user.target

When the program is started, it provides a command line interface to allow interaction. However, as this program is run by systemd, I can't immediately see a way to interact with the program directly. Is there some way to "connect" to the stream the program provides, while running it as a service within systemd?

已采纳解答

原帖链接 · Mark Stosberg · CC BY-SA 3.0

In man systemd.exec, you'll find that you can set StandardInput= to a value of tty, and then set TTYPath= to set a particularly TTY to connect to.

It's fairly unconventional to use systemd to run CLI apps though.

Some services may appear to run via systemd and offer a CLI, but they are really using a client/server model. For example, database servers are typically run via systemd, but you connect to them via CLI when they are running.

How the client/server interaction works is specific to each server. Usually they are communicating over a local port or socket.

You should first confirm if the service you running is designed to connect directly to a TTY or whether it actually listening a local port or socket that a CLI-based client connects to.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-03-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。