Демон отказывает, но выскочка думает, что это все еще живо

Я настоятельно рекомендовал бы nagvis отсюда. Это - огромный инструмент для отображения nagios данных (от нескольких nagios экземпляров, если Вы хотите к) значимым способом. У нас также есть такое ТВ на стене, и у нас есть приблизительно 10 различных карт (это похоже на страницы со схемами и значками на нем), вращающийся каждые 15 секунд. Это абсолютно волшебно.

Вам будет требоваться некоторое время для конфигурирования его, но результаты являются ошеломляющими. Снимки экрана на сайте являются только небольшим примером того, что может быть сделано. Если Вы имеете какие-либо вопросы об этом, просто начинаете говорить. У нас есть приблизительно 200 хостов и 800 сервисов в nagios через 3 сайта, таким образом, существует очень мало, я не сделал с nagios/nagvis.

1
задан 25 July 2012 в 16:25
2 ответа

Почему ваше приложение должно запускаться с помощью сценария bash ? Upstart должен знать, сколько раз ваше приложение разветвляется. Вы сказали ему, что он не разветвляется (поскольку вы не указали строфу « expect »), но тем не менее, вы произвели разветвление (потому что вы указали « & » в раздел скрипта. Следовательно, Upstart не может отслеживать PID.

См.:

0
ответ дан 4 December 2019 в 01:02

This is what usually happens with daemon programs:

  1. Upstart runs the executable in the foreground
  2. The program loads it's configuration file, checks it, performs various setup operations (like opening a listening port).
  3. If the previous step fails, the program exits and upstart gets a non-zero exit code, thereby knowing that it failed
  4. If step 2 didn't fail, the program now forks, essentially creating two copies of it
  5. The process which Upstart initially executed now exits with a zero exit code, indicating that it was successful
  6. The forked process continues running and does the actual work of the application

The problem is that Java doesn't provide a mechanism to fork, and so this tried and tested pattern cannot be implemented properly. When executing Java daemons you are forced to background the process immediately (i.e. the & symbol in the script). Upstart essentially starts the process and then immediately forgets about it -- the process has no way of indicating to Upstart whether it successfully started up or not.

The only way around this is to start the process, background it, and then check whether it's still running in order to determine whether it was successful or not. The catch of course is determining when to check whether it's still running. The simple solution is something like this:

#!/bin/sh
java MyClass >/dev/null 2>&1 &
PID=$!
sleep 3
if kill -0 $PID; then
    exit 0
else
    exit 1
fi

There are more elaborate schemes to determine when to check the process, like making the program close stdout and stderr or create its PID file when it has finished its startup routine, and waiting for these events in the startup script.

The simplest solution for you is to modify your Upstart script to something like this:

script
    cd /usr/lib/app-dir
    nohup ./appStartScript.sh &> /dev/null &
    PID=$!
    sleep 3
    if kill -0 $PID; then
        emit app_running                         
        exit 0
    else
        exit 1
    fi
end script
1
ответ дан 4 December 2019 в 01:02

Теги

Похожие вопросы