运行很长的脚本 - 如何让它们保持运行并在失败时重新启动它们?
我需要在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。这称为创建“检查点”或“纪念品”。
很好。开始吧。每个问题都是独特的,因此您必须创建、保存和重新加载纪念品。
它不能很好地概括。并非所有变量都可以保存。只有您知道需要什么才能以有意义的方式重新启动您的流程。
并不真地。
通常,我们通过单元测试来发现这些问题。这样可以节省大量的编程时间来解决该错误。一分预防胜过一分愚蠢的变通办法。
什么?你最好找出原因。一分预防胜过一分愚蠢的变通办法。
Yes. It's called creating a "checkpoint" or "memento".
Good. Get started. Each problem is unique, so you have to create, save, and reload the mementos.
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.
Not really.
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.
What? You'd better find out why. An ounce of prevention is worth a pound of silly work-arounds.