start process if it was in monitor_init and it has no pid

Issue #939 closed
Gianluca Cinci created an issue

If we want to delegate monit to start a service instead of a init scritpt at the first time monit start it send an unuseful alert mail of no-exist process instead of try to start it.

With this patch monit alert only on no_exist after it try to start.

---
 src/validate.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/validate.c b/src/validate.c
index 579e702..246bad6 100644
--- a/src/validate.c
+++ b/src/validate.c
@@ -1526,6 +1526,13 @@ State_Type check_process(Service_T s) {
         bool checkResources = false;
         pid_t pid = ProcessTree_findProcess(s);
         if (! pid) {
+       if(s->monitor == Monitor_Init) {
+                   s->doaction = Action_Start;
+                   if(_doScheduledAction(s)) {
+               Event_post(s, Event_NonExist, State_Succeeded, Action_Start, "process is running with pid %d", (int)pid);
+               return rv;
+           }
+       }
                 for (NonExist_T l = s->nonexistlist; l; l = l->next) {
                         rv = State_Failed;
                         Event_post(s, Event_NonExist, State_Failed, l->action, "process is not running");
--
2.17.1

Comments (6)

  1. Lutz Mader

    Hello Gianluca,
    nice idea, but from my point of view the monitor should report all application outages. The monitor send an alert and start the application in the defined way. And after the application is up again, you get a succeed alert.

    If the last recovery is able to start the application, the monitor will be disabled, this is a problem sometimes. But the alert before starting the recovery gives a good overview.

    Are you unsing M/Monit or Monit only?

    With regards,
    Lutz

  2. Gianluca Cinci reporter

    Hi Lutz,

    ok , if this is the wanted behavior i think this was a "bug" or something near here : (line 222 --- file : Control.c)

    Service_T parent = Util_getService(d->dependant);
    ASSERT(parent);
    if (parent->monitor != Monitor_Yes || parent->error) {
    if (_doStart(parent)) {

    This is the case:

    if you have a process that depends to others process (eg . P1,P2,P3) and this processes are not started , only the first parent process started rise an alert

    I use only Monit (without GUI o something)

    Best Regards

    Gianlu

  3. Lutz Mader

    Hello Gianluca,
    nice hint, thanks.

    if you have a process that depends to others process (eg . P1,P2,P3) and this processes are not started , only the first parent process started rise an alert

    I’ll check this, I thought I got a alert for all services.

    With regards,
    Lutz

  4. Lutz Mader

    Hello Gianluca,
    I done some more tests. The dependend services are in state "Initializing" until the parent service is in state "OK".
    You are right, as long as the service is in "Initializing" no alert will send.

    In M/Monit I see the state "Initializing" only also. But M/Monit gather the state of all services every minute, this is the reason you can not see this behaviour in M/Monit, I was not aware of this behavior in detail.

    But this is the current way/behavior of Monit.

    With regards,
    Lutz

  5. Gianluca Cinci reporter

    Hi Luz,

    that was the first step conduce me to develop the patch for my system.

    When I decided to delegate Monit for services start and alerts, in that pass I didn't understand why I received an alert message from

    a service and then , when I go to check in that machine all the services were started.

    In my case , with many machines in a single installation the patch give me a more clean system alerts vision.

    You think that this feature can be parametrized ?

    Thanks a lot and best regards

    Gianluca

  6. Log in to comment