如何为sensu客户端自定义PATH?

时间:2015-09-29 22:26:15

标签: bash shell sensu

我有一个sensu客户端,我在我的一个检查脚本中调试了它的PATH,它显示:

/sbin:/usr/sbin:/bin:/usr/bin:/etc/sensu/plugins:/etc/sensu/handlers

如何为sensu自定义此PATH,例如:我想将/ usr / local / bin添加到PATH的末尾,这会导致:   / sbin目录:/ usr / sbin目录:/ bin中:在/ usr / bin中:在/ etc /意义上/插件:在/ etc /意义上/处理程序:在/ usr / local / bin中

我尝试了很多方法,但没有成功,我试过了:

  1. 将sensu用户的SHELL设置为/ bin / bash(而不是默认的/ bin / false),并在sensu用户的主目录/ opt / sensu下添加.bashrc | .profile,使用以下行:export PATH=$PATH:/usr/local/bin < / LI>
  2. 修改/ etc / default / sensu,添加此行PATH=$PATH:/usr/local/bin
  3. 通过阅读:https://sensuapp.org/docs/latest/clients,我在/ etc / default / sensu中设置USER=ec2-user,重新启动sensu客户端后,我清楚地看到ecu客户端进程正在由ec2-user运行,但是,令人惊讶的是,PATH与ec2-user
  4. 不同

    上面的1,2和3都没有用,在我用python编写的检查脚本中,我有那些lins:

    from subprocess import call, Popen, PIPE
    import os
    import sys
    import shlex
    
    import platform
    print os.environ["PATH"]
    
    proc = Popen(['which', 'python'],
            stdout=PIPE,
            stderr=PIPE)
    out, err = proc.communicate() #does not return until the process has terminated.
    print(out)
    print(err)
    #print(platform.__dict__)
    print(platform.python_version())
    
    proc = Popen(['whoami'],
            stdout=PIPE,
            stderr=PIPE)
    out, err = proc.communicate() #does not return until the process has terminated.
    print(out)
    print(err)
    sys.exit(0)
    

    输出结果为:

    /sbin:/usr/sbin:/bin:/usr/bin:/etc/sensu/plugins:/etc/sensu/handlers
    /usr/bin/python   
    2.6.6 
    ec2-user
    

    更新,我在我的python检查脚本中写了这一行:

    proc = Popen(['bash','--login', '-x'], stdout=PIPE, stderr=PIPE)
    out, err = proc.communicate()
    print(out)
    print(err)
    

    我看到了输出:

    PATH=/sbin:/usr/sbin:/bin:/usr/bin:/etc/sensu/plugins:/etc/sensu/handlers:/usr/local/sbin:/usr/local/bin
    

    但是,其他输出令人惊讶......“哪个python” - &gt; / usr / bin / python,“python --version” - &gt; 2.6.6

    请求帮助....

2 个答案:

答案 0 :(得分:0)

您是否尝试在/etc/default/sensu

中添加PATH
PATH=$PATH:/usr/local/bin

https://github.com/sensu/sensu-build/blob/master/sensu_configs/upstart/sensu-client.conf#L30

. /etc/default/sensu会让它发挥作用。

答案 1 :(得分:0)

添加以下行

  • export PATH = $ PATH:/ usr / local / bin

在&#34; / etc / sysconfig / sensu-client &#34;。如果不存在则创建文件。重新启动您的客户端,您的路径将会更新。

相关问题