运行很长的脚本 - 如何让它们保持运行并在失败时重新启动它们?

发布于 2024-12-03 09:22:10 字数 335 浏览 3 评论 0原文

我需要在 CENTOS 服务器上运行一堆长时间运行的进程。

如果我让进程(python/php 脚本)继续运行,有时进程会因为一些小错误而停止运行,例如。字符串编码问题或有时因为该进程似乎被服务器终止

我尝试使用 nohup 并从 crontab 触发作业

有没有什么方法可以让这些进程以保存所有变量的方式运行,并且我可以从停止的地方重新启动脚本?

我知道我可以将其编程到代码中,但更喜欢通用的实用程序,它可以让这些东西保持运行,以便即使存在微不足道的错误也可以完成脚本。

也许我需要某种流程管理工具?

非常感谢您的任何建议

I need to run a bunch of long running processes on a CENTOS server.

If I leave the processes (python/php scripts) to run sometimes the processes will stop running because of trivial errors eg. string encoding issues or sometimes because the process seems to get killed by the server.

I try to use nohup and fire the jobs from the crontab

Is there any way to keep these processes running in such a way that all the variables are saved and I can restart the script from where it stopped?

I know I can program this into the code but would prefer a generalised utility which could just keep these things running so that the script completed even if there were trivial errors.

Perhaps I need some sort of process-management tool?

Many thanks for any suggestions

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

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

发布评论

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

评论(1

再浓的妆也掩不了殇 2024-12-10 09:22:10

有什么方法可以让这些进程以保存所有变量的方式保持运行,并且我可以从停止的地方重新启动脚本吗?

是的。这称为创建“检查点”或“纪念品”。

我知道我可以编程

很好。开始吧。每个问题都是独特的,因此您必须创建、保存和重新加载纪念品。

但更喜欢一个通用的实用程序,它可以让这些东西保持运行,以便即使存在微不足道的错误,脚本也能完成。

它不能很好地概括。并非所有变量都可以保存。只有您知道需要什么才能以有意义的方式重新启动您的流程。

也许我需要某种流程管理工具?

并不真地。

小错误,例如。字符串编码问题

通常,我们通过单元测试来发现这些问题。这样可以节省大量的编程时间来解决该错误。一分预防胜过一分愚蠢的变通办法。

有时是因为进程似乎被服务器杀死了。

什么?你最好找出原因。一分预防胜过一分愚蠢的变通办法。

is there any way to keep these processes running in such a way that all the variables are saved and i can restart the script from where it stopped?

Yes. It's called creating a "checkpoint" or "memento".

i know i can program this

Good. Get started. Each problem is unique, so you have to create, save, and reload the mementos.

but would prefer a generalised utility which could just keep these things running so that the script completed even if there were trivial errors.

It doesn't generalize well. Not all variables can be saved. Only you know what's required to restart your process in a meaningful way.

perhaps i need some sort of process-management tool?

Not really.

trivial errors eg. string encoding issues

Usually, we find these by unit testing. That saves a lot of programming to work around the error. An ounce of prevention is worth a pound of silly work-arounds.

sometimes because the process seems to get killed by the server.

What? You'd better find out why. An ounce of prevention is worth a pound of silly work-arounds.

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