簡體   English   中英

如何為sensu客戶端自定義PATH?

[英]How to customize PATH for sensu client?

我有一個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 / sensu / plugins:/ etc / sensu / handlers:/ usr / local / bin

我嘗試了很多方法,但沒有成功,我嘗試了:

  1. 將sensu用戶的SHELL設置為/ bin / bash(而不是默認的/ bin / false),並在sensu用戶的主目錄/ opt / sensu下添加.bashrc | .profile,並使用以下行: export PATH=$PATH:/usr/local/bin
  2. 編輯/ etc / default / sensu,添加以下行PATH=$PATH:/usr/local/bin
  3. 通過閱讀以下內容: https : //sensuapp.org/docs/latest/clients ,我在/ etc / default / sensu中設置了USER=ec2-user ,重新啟動sensu客戶端后,我清楚地看到sensu客戶端進程正在由ec2-運行用戶,但是令人驚訝的是,該路徑與ec2-user不同

以上所有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”-> / usr / bin / python,“ python --version”-> 2.6.6

尋求幫助...。

那么,您是否嘗試在/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 . /etc/default/sensu將使其工作。

添加以下行

  • 導出PATH = $ PATH:/ usr / local / bin

在“ / etc / sysconfig / sensu-client ”中。 如果不存在,則創建文件。 重新啟動客戶端,您的路徑將被更新。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM