【问题标题】:Upstart script not executing pre-start script when the process is respawned进程重新生成时,Upstart 脚本不执行预启动脚本
【发布时间】:2014-02-18 12:49:10
【问题描述】:

我正在尝试让 Upstart 在进程重新启动时向我发送电子邮件。 因此,在 upstart 节之后,这是我的 ntpd 服务的 upstart 脚本(仅作为示例):

/etc/init/ntpd.conf

### ntpd

script

mail -s "ntpd Service Respawned" my_email@gmail.com
control + D

end script

respawn

exec /etc/init.d/ntpd start

然后,我重新加载进程 (initctl reload ntpd) 以便让新贵重新加载 ntpd.conf 的配置。然后kill -9 进程强制其重生。 这里是/var/log/message.log

init: ntpd main process (12446) killed by KILL signal
init: ntpd main process ended, respawning

并且永远不会发送电子邮件。我已经尝试过 post-start 和 exec 但它也不起作用。

有什么建议吗?

【问题讨论】:

    标签: bash centos6 upstart


    【解决方案1】:

    刚刚解决了这个。

    我所做的是在我的 Upstart 脚本中添加以下内容:

    重生 预启动脚本 mail -s "ntpd 服务重生" my_address@gmail.com 控制 + D 结束脚本 执行 /etc/init.d/ntpd 启动

    这就像一个魅力。 我认为 Upstart 确实非常注重语句的顺序。

    谢谢!!!

    【讨论】:

    • 对于未来的读者来说,问题可能是 OP 在同一个 upstart 脚本中同时使用了 scriptexec。这是不允许的。修复(我相信)是使用pre-start 而不是script。订单在很大程度上并不重要。
    【解决方案2】:
    echo "ntpd Service Respawned" | mail -s "ntpd Service Respawned" my_email@gmail.com
    

    试试这个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      • 2016-03-28
      • 2021-08-15
      • 1970-01-01
      • 2020-09-28
      • 1970-01-01
      相关资源
      最近更新 更多