我有一个 systemd 服务(用于 heka),这让我有些头疼。
问题是即使 heka 守护进程在启动后不久死亡,“start”也会成功返回。如果配置文件有误,就会发生这种情况,例如:进程将启动,它将验证配置,如果对所发现的内容不满意,则会终止。在这种情况下,Systemd 成功返回。
有没有办法强制systemd在初始化后检查程序状态?也许在进程开始后睡眠 n 秒?
这是脚本:
[Unit]
Description=Heka event/metric/log collection and routing daemon
After=network.target auditd.service
ConditionPathExists=!/etc/heka/hekad_not_to_be_run
[Service]
EnvironmentFile=-/etc/default/heka
Type=simple
PIDFile=/var/run/hekad.pid
ExecStart=/usr/bin/hekad -config=/etc/heka
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
StandardError=inherit
[Install]
WantedBy=multi-user.target
Alias=heka.service
Run Code Online (Sandbox Code Playgroud)
您可以将多个 ExecPostStart 命令链接在一起。即使主 ExecStart 失败,您也可以通过添加-/ ( systemd.service: Type= )来运行它们。像这样的东西:
ExecStart=-/usr/bin/hekad -config=/etc/heka
ExecStartPost=/bin/sleep 3
ExecStartPost=/bin/kill -0 $MAINPID &>/dev/null
Run Code Online (Sandbox Code Playgroud)
例如,这可确保您MAINPID
在停止或重新启动服务时仍然可以使用。
归档时间: |
|
查看次数: |
7295 次 |
最近记录: |