monit-general
[Top][All Lists]
Advanced

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

RE: Environment variables with start program


From: Mehul Ved
Subject: RE: Environment variables with start program
Date: Fri, 21 Feb 2014 03:44:46 +0000

Hi Martin,

  Sorry, I should have shown my script. I handled both these things. Turns out the problem was in the way I loaded the variables from /etc/environment file. They were in form of 

KEY='value'

And I loaded the /etc/environment file using


# Set all the environment variables
OLDIFS=$IFS
IFS=$'\n' # We need to explicitly tell the shell to use new line as IFS else it will use spaces.
for LINE in $(cat /etc/environment)
do
    export $LINE
done
IFS=$OLDIFS

So the variable value had quotes in it thus weren't getting discarded by the type check in the library we used.
Adding this here in case somebody else runs into a similar issue.

My problem is solved.

Thank You.



From: monit-general-bounces+address@hidden <monit-general-bounces+address@hidden> on behalf of Weedy <address@hidden>
Sent: Friday, February 21, 2014 8:02 AM
To: This is the general mailing list for monit
Subject: RE: Environment variables with start program
 

If you need THAT many variables you should source them from the start function of your script.

On 20 Feb 2014 17:56, "Mehul Ved" <address@hidden> wrote:

Hi Martin,

  I did try this but it did not load the environment variables. Let me try it again though, if I did anything wrong back then.



From: monit-general-bounces+mehul.ved=address@hidden <monit-general-bounces+mehul.ved=address@hidden> on behalf of Martin Pala <address@hidden>
Sent: Thursday, February 20, 2014 6:33 PM
To: This is the general mailing list for monit
Subject: Re: Environment variables with start program
 
Hi,

you can wrap the script in shell like this:

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

The shell will load its profile (set environment variables).


Regards,
Martin



On 20 Feb 2014, at 12:38, Mehul Ved <address@hidden> wrote:

Hi,

I have a node.js services that I want to be monitored by monit. I have written a bash script to start and stop these services. The script works fine when run from my bash console. But, it fails when run through monit, as explained on FAQ page that monit uses execv and thus environment variables are not available.


One of the workarounds that people have been using is:

/usr/bin/env KEY=value myscript.sh

Unfortunately, I can't use that since I have a lot of variables, some of which are quite long and thus exceed the 127 character limit.


Is there any other way I can have my environment variable available to the start program script?

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general


--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general

reply via email to

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