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

systemctl start trafficserver wait for start

· 52CE 我爱测

I have a script that installs and sets up traffic server : yum install -y trafficserver systemctl start trafficserver traffic_line -s proxy.config.url_remap.remap_required -v 0 traffic_line -s proxy.config.reverse_proxy.enabled -…

问题原文

原帖链接 · BenMorel · CC BY-SA 4.0

I have a script that installs and sets up traffic server:

yum install -y trafficserver
systemctl start trafficserver

traffic_line -s proxy.config.url_remap.remap_required -v 0
traffic_line -s proxy.config.reverse_proxy.enabled -v 0

The problem is, traffic_line fails with:

[connect] ERROR (main_socket_fd 3): No such file or directory error: could not connect to management port, make sure traffic_manager is running

This is because systemctl start returns immediately, without waiting for traffic server to be actually started.

Is there a way to tell systemctl start to only return once the service is started?

If this is not possible, is there a command that I can run after systemctl start to actually wait for the service to be started?

已采纳解答

原帖链接 · Lucas Werkmeister · CC BY-SA 4.0

This is because systemctl start returns immediately, without waiting for traffic server to be actually started.

Is there a way to tell systemctl start to only return once the service is started?

systemctl start does wait for the service to be ready (except if invoked with --no-block), the service just needs to indicate that properly (i. e., not use Type=simple). If the service doesn’t tell systemd when it’s ready, no variation of systemctl is-active, systemctl show, etc. will help you.

The most elegant solution, as mentioned in the comments, would be a socket unit. systemd starts the socket, traffic_line connects to it, systemd starts the service, and traffic_line blocks until the service starts to accept connections on the file descriptor it inherited from systemd.

Alternatively, you can use either Type=forking (the service forks, and the main PID exits once the forked service is ready) or Type=notify (the service calls sd_notify(0, "READY=1") once it’s ready).

Unfortunately, all of these solutions require some support from trafficserver – use systemd’s socket instead of allocating its own, fork and wait appropriately in the main process, or call sd_notify. systemd can’t magically guess when the server is ready if the server doesn’t cooperate :)


After looking at trafficserver’s source code a bit, it looks like it might actually support Type=forking – the server is spawned by a dedicated traffic_cop command, which seems to wait until the server is up and perform some basic testing (at least the code looks like it). So if you change the service type, it might just work:

# /etc/systemd/system/trafficserver.service.d/type-forking.conf
[Service]
Type=forking

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

资料来源与适用范围

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

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

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