[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [monit] Problem with monit starting one of my scripts

From: Stephen Adams
Subject: Re: [monit] Problem with monit starting one of my scripts
Date: Thu, 14 Aug 2008 12:18:07 +1200
User-agent: Thunderbird (X11/20080724)

Hey Martin,

I had #!/bin/sh at the start of my scripts...

I've changed it to #!/bin/bash and it's now working!! I'm not sure what's different between my sh and bash shells though.

Thanks for your help


Monit execs the start script ... it doesn't encapsulate the start script in shell. If the /etc/init.d/jira is not binary, it should either have the #!/bin/bash interpreter line in the beginning or you can encapsulate it this way in monit:

  start program "/bin/bash -c '/etc/init.d/jira start'"

Another point is, that as described in FAQ, monit strips *all* environment variables and adds very basic PATH only. The scripts thus should either set the PATH in the beginning or use absolute paths. It is also possible that some other variable is missing which may be required by the program to be started.


Stephen Adams wrote:
Hi Martin,

I'm starting to think it may not be specific to monit but something in my environment.

I do have PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" this may be overkill but it still doesn't work.

I added a logger command to log something to syslog in my script just after the PATH statement which is effectively the first thing my script does and nothing gets logged to syslog.

The command I run is => /usr/bin/logger -i -p $0 $1

To me this statement should always run no matter what parameter is passed to the script but I get nothing when monit.d/jira has /etc/init.d/jira start. It's almost like it's not even running the command. All i get is the following:

Aug 14 09:59:49 revolt monit[4407]: 'Jira' process is not running
Aug 14 09:59:49 revolt monit[4407]: 'Jira' trying to restart
Aug 14 09:59:49 revolt monit[4407]: 'Jira' start: /etc/init.d/jira
Aug 14 09:59:50 revolt monit[4407]: 'Jira' failed to start

But ... when I use /etc/init.d/jira-start it works and syslog has the following

Aug 14 10:00:05 revolt monit[4458]: 'Jira' process is not running
Aug 14 10:00:05 revolt monit[4458]: 'Jira' trying to restart
Aug 14 10:00:05 revolt monit[4458]: 'Jira' start: /etc/init.d/jira-start
Aug 14 10:00:05 revolt jira[4474]: /etc/init.d/jira start
Aug 14 10:00:05 revolt jira[4493]: Started Tomcat server...
Aug 14 10:02:05 revolt monit[4458]: Monit has not changed
Aug 14 10:02:05 revolt monit[4458]: 'Jira' process is running with pid 4492

So I'm a bit confused here.


Martin Pala wrote:
This is most probably caused by missing environment variable. Monit sets spartan environment/sandbox when starting services.

Here is FAQ item regarding short description from FAQ (

6. Q: I'm having trouble getting monit to execute any "start" or
      "stop" program commands.  The log file says that they're being
      executed, and I can't find anything wrong when I run monit in
      verbose mode.

   A: Monit did start the program but for some reason the service dies
      later. Before we go on and introduce you to the fine art of
      system debugging, it's worth to note that:

      For security reasons monit purges the environment and only set a
      spartan PATH variable that contains /bin, /usr/bin, /sbin and
      /usr/sbin. If your program or script dies, the reason could be
      that it expects certain environment variables or to find certain
      programs via the PATH. If this is the case you should set the
      environment variables you need directly in the start or stop
      script called by monit.

It's possible that your scripts need some environment variable which is missing ... simply add everything what is needed to your scripts.


Stephen Adams wrote:

I'm trying to get an application called JIRA to be monitored by monit.

I've created a /etc/init.d/jira script and also created a /etc/monit.d/jira file which I've shown below

check process jira with pidfile /var/run/jira/
group tomcat
start program "/etc/init.d/jira-start"
#start program "/etc/init.d/jira start"
stop program "/etc/init.d/jira-stop"
#stop program "/etc/init.d/jira stop"
if failed host port 8085 protocol http
       and request "/jira/"
       then restart
if 5 restarts within 5 cycles then timeout

The problem I have is I can't get monit to successfully restart JIRA if I use the command "/etc/init.d/jira start"

but if I write a script called /etc/init.d/jira-start

/etc/init.d/jira start

and use that inside monit it works?!?

It's almost as if monit is truncating my start program directive when it hits the first space.

Does anyone have any ideas here?


To unsubscribe:

To unsubscribe:

To unsubscribe:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]