Xymon Mailing List Archive search

Starting Xymon via init script no environment variables

6 messages in this thread

list Michael Beatty · Tue, 15 Jan 2013 14:44:54 -0500 ·
I've got an init script that is starting up the xymon client. It starts, and runs, however it doesn't appear to have any access to any environment variables.  If I restart the client from a shell, it takes off and runs fine.  I've got echo statements in the init script to display some of the environment variables I need, and they are displaying fine at boot time.  It just seems that xymon doesn't have access to them when it is running.  What has me really confused is that I'm even exporting the variable from a file directly from the xymon script.

For example, in the init script, I 'echo $HOST'  The host name shows up in the log
I have a perl script that clientlaunch calls, I have a variable "my $host = $ENV{"HOST"}.

I am printing the "HOST" variable out to the log file when the script runs.  If I start the xymon client from a shell, the HOST variable prints out.  However, it doesn't print out (just a blank) if the xymon client starts via the init script.


-- 
Michael Beatty
list Jeremy Laidman · Wed, 16 Jan 2013 12:03:06 +1100 ·
What OS?  Can you show the init script?
quoted from Michael Beatty


On 16 January 2013 06:44, Michael Beatty <user-4aea7c115850@xymon.invalid> wrote:
I've got an init script that is starting up the xymon client. It starts,
and runs, however it doesn't appear to have any access to any environment
variables.  If I restart the client from a shell, it takes off and runs
fine.  I've got echo statements in the init script to display some of the
environment variables I need, and they are displaying fine at boot time.
 It just seems that xymon doesn't have access to them when it is running.
 What has me really confused is that I'm even exporting the variable from a
file directly from the xymon script.

For example, in the init script, I 'echo $HOST'  The host name shows up in
the log
I have a perl script that clientlaunch calls, I have a variable "my $host
= $ENV{"HOST"}.

I am printing the "HOST" variable out to the log file when the script
runs.  If I start the xymon client from a shell, the HOST variable prints
out.  However, it doesn't print out (just a blank) if the xymon client
starts via the init script.


--
Michael Beatty

______________________________**

Xymon at xymon.com<
list Michael Beatty · Wed, 16 Jan 2013 08:15:28 -0500 ·
Linux SuSE.


#!/bin/bash
#
# xymon      This starts and stops xymon stuff
#
# Author:  Michael Beatty
#
# description: starts/stops Xymon
#
# /etc/init.d/xymon
#
### BEGIN INIT INFO
# Provides:       xymon
# Required-Start: $local_fs network
# Should-Start: mqm
# Required-Stop:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Description:    Xymon client custom startup
### END INIT INFO

# Store variables
. /etc/sysconfig/posvars
# Source SuSE config
. /etc/sysconfig/boot

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num><num>
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
. /etc/rc.status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
#
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.


RETVAL=0


case "$1" in
     start)
         echo "Staring Xymon Client QMGR = $QMGR"
          /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh start
         rc_status
         ;;
     stop)
         echo "Stopping Xymon Client QMGR = $QMGR"
         /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh stop
               rc_status
         ;;
     restart)
         /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh restart
         rc_status -v
         ;;
     status)
         /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh status
         rc_status
         ;;
     *)
         echo $"Usage: $0 {start|stop|restart|status}"
         exit 1
         ;;
esac
rc_exit 0


Michael Beatty
quoted from Jeremy Laidman

On 01/15/2013 08:03 PM, Jeremy Laidman wrote:
What OS?  Can you show the init script?


On 16 January 2013 06:44, Michael Beatty <user-4aea7c115850@xymon.invalid 
<mailto:user-4aea7c115850@xymon.invalid>> wrote:

    I've got an init script that is starting up the xymon client. It
    starts, and runs, however it doesn't appear to have any access to
    any environment variables.  If I restart the client from a shell,
    it takes off and runs fine.  I've got echo statements in the init
    script to display some of the environment variables I need, and
    they are displaying fine at boot time.  It just seems that xymon
    doesn't have access to them when it is running.  What has me
    really confused is that I'm even exporting the variable from a
    file directly from the xymon script.

    For example, in the init script, I 'echo $HOST'  The host name
    shows up in the log
    I have a perl script that clientlaunch calls, I have a variable
    "my $host = $ENV{"HOST"}.

    I am printing the "HOST" variable out to the log file when the
    script runs.  If I start the xymon client from a shell, the HOST
    variable prints out.  However, it doesn't print out (just a blank)
    if the xymon client starts via the init script.


    -- 
    Michael Beatty

    
list Michael Beatty · Wed, 16 Jan 2013 10:44:47 -0500 ·
Well... I figured out it has to do with how sudo invokes the 
environment.  I'm pretty sure there is a parameter I could supply to 
sudo to bring in the environment, but it was just as easy to switch from 
sudo to su.

I changed my commands to:
su - xymon -c "/home/xymon/client/runclient.sh start"
and it works now.

If anyone who understands this better than me understands why, I would 
appreciate an explanation.

Michael Beatty
Sherwin-Williams
IT Analyst/Developer
user-4aea7c115850@xymon.invalid
XXX-XXX-XXXX
quoted from Michael Beatty

On 01/16/2013 08:15 AM, Michael Beatty wrote:
Linux SuSE.


#!/bin/bash
#
# xymon      This starts and stops xymon stuff
#
# Author:  Michael Beatty
#
# description: starts/stops Xymon
#
# /etc/init.d/xymon
#
### BEGIN INIT INFO
# Provides:       xymon
# Required-Start: $local_fs network
# Should-Start: mqm
# Required-Stop:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Description:    Xymon client custom startup
### END INIT INFO

# Store variables
. /etc/sysconfig/posvars
# Source SuSE config
. /etc/sysconfig/boot

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num><num>
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
. /etc/rc.status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
#
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.


RETVAL=0


case "$1" in
    start)
        echo "Staring Xymon Client QMGR = $QMGR"
         /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh start
        rc_status
        ;;
    stop)
        echo "Stopping Xymon Client QMGR = $QMGR"
        /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh stop
              rc_status
        ;;
    restart)
        /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh restart
        rc_status -v
        ;;
    status)
        /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh status
        rc_status
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac
rc_exit 0


Michael Beatty

On 01/15/2013 08:03 PM, Jeremy Laidman wrote:
What OS?  Can you show the init script?


On 16 January 2013 06:44, Michael Beatty <user-4aea7c115850@xymon.invalid 
<mailto:user-4aea7c115850@xymon.invalid>> wrote:

    I've got an init script that is starting up the xymon client. It
    starts, and runs, however it doesn't appear to have any access to
    any environment variables.  If I restart the client from a shell,
    it takes off and runs fine.  I've got echo statements in the init
    script to display some of the environment variables I need, and
    they are displaying fine at boot time.  It just seems that xymon
    doesn't have access to them when it is running.  What has me
    really confused is that I'm even exporting the variable from a
    file directly from the xymon script.

    For example, in the init script, I 'echo $HOST'  The host name
    shows up in the log
    I have a perl script that clientlaunch calls, I have a variable
    "my $host = $ENV{"HOST"}.

    I am printing the "HOST" variable out to the log file when the
    script runs.  If I start the xymon client from a shell, the HOST
    variable prints out.  However, it doesn't print out (just a
    blank) if the xymon client starts via the init script.


    -- 
    Michael Beatty

    
list Ryan Novosielski · Wed, 16 Jan 2013 10:49:33 -0500 ·
See the sudoers file or the man pages for an explanation. There are things that sudo passes by default and things that need to be manually added. I assume a security reason. Basically in sudoers, you can add environment variables to pass through in different cases.
quoted from Michael Beatty


From: Michael Beatty [mailto:user-4aea7c115850@xymon.invalid]
Sent: Wednesday, January 16, 2013 10:44 AM
To: xymon at xymon.com <xymon at xymon.com>
Subject: Re: [Xymon] Starting Xymon via init script no environment variables

Well... I figured out it has to do with how sudo invokes the environment.  I'm pretty sure there is a parameter I could supply to sudo to bring in the environment, but it was just as easy to switch from sudo to su.

I changed my commands to:
su - xymon -c "/home/xymon/client/runclient.sh start"
and it works now.

If anyone who understands this better than me understands why, I would appreciate an explanation.


Michael Beatty
Sherwin-Williams
IT Analyst/Developer

user-4aea7c115850@xymon.invalid<mailto:user-4aea7c115850@xymon.invalid>
quoted from Michael Beatty
XXX-XXX-XXXX


On 01/16/2013 08:15 AM, Michael Beatty wrote:
Linux SuSE.


#!/bin/bash
#
# xymon      This starts and stops xymon stuff
#
# Author:  Michael Beatty
#
# description: starts/stops Xymon
#
# /etc/init.d/xymon
#
### BEGIN INIT INFO
# Provides:       xymon
# Required-Start: $local_fs network
# Should-Start: mqm
# Required-Stop:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Description:    Xymon client custom startup
### END INIT INFO

# Store variables
. /etc/sysconfig/posvars
# Source SuSE config
. /etc/sysconfig/boot

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num><num>
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
. /etc/rc.status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
#
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.


RETVAL=0


case "$1" in
    start)
        echo "Staring Xymon Client QMGR = $QMGR"
         /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh start
        rc_status
        ;;
    stop)
        echo "Stopping Xymon Client QMGR = $QMGR"
        /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh stop
              rc_status
        ;;
    restart)
        /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh restart
        rc_status -v
        ;;
    status)
        /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh status
        rc_status
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac
rc_exit 0


Michael Beatty


On 01/15/2013 08:03 PM, Jeremy Laidman wrote:
What OS?  Can you show the init script?


On 16 January 2013 06:44, Michael Beatty <user-4aea7c115850@xymon.invalid<mailto:user-4aea7c115850@xymon.invalid>> wrote:
I've got an init script that is starting up the xymon client. It starts, and runs, however it doesn't appear to have any access to any environment variables.  If I restart the client from a shell, it takes off and runs fine.  I've got echo statements in the init script to display some of the environment variables I need, and they are displaying fine at boot time.  It just seems that xymon doesn't have access to them when it is running.  What has me really confused is that I'm even exporting the variable from a file directly from the xymon script.

For example, in the init script, I 'echo $HOST'  The host name shows up in the log
I have a perl script that clientlaunch calls, I have a variable "my $host = $ENV{"HOST"}.

I am printing the "HOST" variable out to the log file when the script runs.  If I start the xymon client from a shell, the HOST variable prints out.  However, it doesn't print out (just a blank) if the xymon client starts via the init script.


--
Michael Beatty
list Andrey Chervonets · Fri, 18 Jan 2013 19:05:48 +0200 ·
I see there is " /usr/bin/sudo -u xymon /home/xymon/client/runclient.sh 
start"

Try, instead, to use jus "su - ":
#
/usr/bin/su - xymon -c "/home/xymon/client/runclient.sh start"
#
su  - username - starts the new session under user account with required 
user variables.
auto-start script is run with root anyway - so You need to use sudo.


Best regards,

Andrey Chervonets
CoMinder Ltd.
http://www.cominder.eu/
Mobile: +XXX XXXXXXXX
Fax: +XXX XXXXXXXX

On 17.01.2013 13:00, xymon-request at xymon.com wrote:
  /usr/bin/sudo -u