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

How to allow for a slow-starting dependency service in systemd

· 52CE 我爱测

Sometimes a service will start and fork - giving systemd the illusion that it's ready - even though it hasn't finished "warming up". In this particular instance I'm using ApacheDS to provide LDAP services. When this unit is start…

问题原文

原帖链接 · Daniel Miller · CC BY-SA 3.0

Sometimes a service will start and fork - giving systemd the illusion that it's ready - even though it hasn't finished "warming up". In this particular instance I'm using ApacheDS to provide LDAP services. When this unit is started, checking "systemctl status apacheds" will show it's running, along with the single log line:

Apr 04 15:34:33 daisy systemd[1]: Started Apache Directory Server.

But...it's not serving yet. Until a port test (like "lsof -i :389" or "netstat -pan | grep :389 | grep LISTEN") reveals that there's an active listener there's no available LDAP.

Whether it should do so or not - this takes about 2 minutes to fully startup. My question isn't whether or not ApacheDS is broken or should be replaced - it's how to deal with slow initializing services in systemd.

Is there a way of putting such a test into systemd, either to tell it to wait until valid to show the apacheds service as started, or giving it as a pre-condition for dependent services, without having them simply fail and still refuse to start?

Here's a working test script:

#!/bin/bash
TRIES=30
WAIT=10

while /bin/netstat -an | /bin/grep \:10389 | /bin/grep LISTEN ; [ $? -ne 0 ]; do
    let TRIES-=1
    if [ $TRIES -gt 1 ]; then
            sleep $WAIT
    fi
done

已采纳解答

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

You can add an ExecStartPost=foo to the unit file where foo is a script that checks (and rechecks) until the service is available.

Edit: you may need to increase TimeoutStartSec as well. The default is 90s.

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

资料来源与适用范围

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

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

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