[Xymon] Starting Xymon via init script no environment variables

Novosielski, Ryan novosirj at umdnj.edu
Wed Jan 16 16:49:33 CET 2013


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.



From: Michael Beatty [mailto:Michael.Beatty at sherwin.com]
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
michael.beatty at sherwin.com<mailto:michael.beatty at sherwin.com>
216-515-7374


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 <Michael.Beatty at sherwin.com<mailto:Michael.Beatty at sherwin.com>> 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 mailing list
Xymon at xymon.com<mailto:Xymon at xymon.com>
http://lists.xymon.com/mailman/listinfo/xymon






_______________________________________________
Xymon mailing list
Xymon at xymon.com<mailto:Xymon at xymon.com>
http://lists.xymon.com/mailman/listinfo/xymon



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20130116/02310e7e/attachment.html>


More information about the Xymon mailing list