请与SD_BU核实如果重新加载过程成功

发布于 2025-02-03 16:42:53 字数 443 浏览 4 评论 0原文

我正在尝试使用SD_BUS_GET_PROPERTY()检查(例如Nginx或PHP成功)。

为此,属性“激活”和“取代”很有趣。

但是,例如,如果我故意在nginx.conf中犯了一个错误,然后尝试重新加载nginx,我会得到以下状态:

...
Active_state:重新加载
sub_state:重新加载
Active_state:重新加载
sub_state:重新加载
Active_state:重新加载
sub_state:重新加载
Active_State:Active
sub_state:运行

因此,如果nginx处于活动状态并运行,则在失败的重新加载后,状态就可以回到“活动”和“运行”。

是否有一种方法可以安全检查,如果重新加载失败?

谢谢!

i'm trying to check with sd_bus_get_property() if reloading for example nginx or php was successfull.

For that the properties "ActiveState" and "SubState" are interesting.

But if i for example intentionally make a mistake in the nginx.conf and try to reload nginx, i get the following states:

...
ACTIVE_STATE: reloading
SUB_STATE: reload
ACTIVE_STATE: reloading
SUB_STATE: reload
ACTIVE_STATE: reloading
SUB_STATE: reload
ACTIVE_STATE: active
SUB_STATE: running

So if nginx is active and running, after the failed reload the states just get back to "active" and "running".

Is there a way to safely check, if the reload fails?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌味 2025-02-10 16:42:53

我最终以不同的方式管理这些过程:

作为NGINX和PHP-FPM的示例:

nginx:

  1. 从所有nginx-worker流程中获取PID(SystemD1.Manager => getUnitProcesses)。
  2. 重新加载nginx。
  3. 如果列表中有新的PID,请检查所有50ms
    工人处理。
  4. 如果在200-300ms之后仍然没有新的PID,那么很可能会重新加载
    失败的。

php-fpm:

php-fpm上似乎更容易,因为php-fpm将“ ActiveState”设置为“失败”,如果重新加载失败。
我以为我只是可以等待状态“重新加载”之后的“激活”更改,但是如果重新加载失败,则php-fpm将状态首先设置为“ Active”,然后将其恢复为“ Active”,然后快速到“失败”。

因此,我还等待PHP-FPM 200-300ms,然后检查状态。

如果有人有更好的主意,请告诉我...谢谢!

I ended up managing the processes differently:

As an example for Nginx and PHP-FPM:

Nginx:

  1. Get PID's from all Nginx-Worker Processes (systemd1.Manager => GetUnitProcesses).
  2. Reload Nginx.
  3. Check all 50ms if there is a new PID in the List of
    Worker-Processes.
  4. If after 200-300ms there is still no new PID, so reload most likely
    failed.

PHP-FPM:

On PHP-FPM it seems easier, as PHP-FPM sets the "ActiveState" to "failed" if reloading fails.
I thought i just could wait for a change of the "ActiveState" after the State is "reloading", but if reloading fails, php-fpm sets the State first back to "active" an then quickly to "failed".
Therefore i wait also for PHP-FPM 200-300ms and then check the State.

If someone has a better idea, please tell me... Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文