如何确保应用程序在Linux上保持运行 [英] How to make sure an application keeps running on Linux

查看:185
本文介绍了如何确保应用程序在Linux上保持运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确保脚本仍在开发服务器上运行.它整理统计数据并提供Web服务,因此应该可以持续使用,但是一天几次,它会死于未知原因.当我们注意到我们只是再次启动它时,但是后部很痛苦,有些用户没有权限(或专有技术)来启动它.

I'm trying to ensure a script remains running on a development server. It collates stats and provides a web service so it's supposed to persist, yet a few times a day, it dies off for unknown reasons. When we notice we just launch it again, but it's a pain in the rear and some users don't have permission (or the knowhow) to launch it up.

我的程序员想花几个小时来解决问题的根源,但我的忙碌的人认为必须有一种简便的方法来检测应用程序是否未运行,然后重新启动.

The programmer in me wants to spend a few hours getting to the bottom of the problem but the busy person in me thinks there must be an easy way to detect if an app is not running, and launch it again.

我知道我可以通过grep cron-script ps:

I know I could cron-script ps through grep:

ps -A | grep appname

但是,这又是我生命中另一个小时的浪费,因为它需要做一些必须已经存在的事情……没有预制的应用程序可以传递可执行文件(可选地带有参数),并且可以使进程无限期地运行?

But again, that's another hour of my life wasted on doing something that must already exist... Is there not a pre-made app that I can pass an executable (optionally with arguments) and that will keep a process running indefinitely?

如果有什么不同,那就是Ubuntu.

In case it makes any difference, it's Ubuntu.

推荐答案

注意:新贵处于维护模式,并且由使用systemd的Ubuntu放弃.应该检查系统的手册,以了解如何编写的详细信息服务定义.

Notice: Upstart is in maintenance mode and was abandoned by Ubuntu which uses systemd. One should check the systemd' manual for details how to write service definition.

自从您使用Ubuntu以来,您可能会对 Upstart 感兴趣,它已取代了传统的 sysV初始化.一个主要功能是,如果服务意外终止,它可以重新启动服务. Fedora已步入新贵,而Debian处于试验阶段,因此可能值得研究.

Since you're using Ubuntu, you may be interested in Upstart, which has replaced the traditional sysV init. One key feature is that it can restart a service if it dies unexpectedly. Fedora has moved to upstart, and Debian is in experimental, so it may be worth looking into.

对于这种情况,这可能是过大的,因为 cron 脚本将需要2分钟实施.

This may be overkill for this situation though, as a cron script will take 2 minutes to implement.

#!/bin/bash
if [[ ! `pidof -s yourapp` ]]; then
    invoke-rc.d yourapp start
fi

这篇关于如何确保应用程序在Linux上保持运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆