bash - How to customize PATH for sensu client? -
i have sensu client, debugged path in 1 of check script, , shows:
/sbin:/usr/sbin:/bin:/usr/bin:/etc/sensu/plugins:/etc/sensu/handlers
how can customize path sensu, say: want add /usr/local/bin end of path, results in: /sbin:/usr/sbin:/bin:/usr/bin:/etc/sensu/plugins:/etc/sensu/handlers:/usr/local/bin
i've tried many ways didn't success, i've tried:
- set sensu user's shell /bin/bash (instead of default /bin/false), , add .bashrc|.profile under sensu user's home dir /opt/sensu, line:
export path=$path:/usr/local/bin
- edit /etc/default/sensu, add line
path=$path:/usr/local/bin
- by reading this: https://sensuapp.org/docs/latest/clients, set
user=ec2-user
in /etc/default/sensu, after restarting sensu client, see sensu client process running ec2-user, however, surprisingly, path not same ec2-user
all 1,2 , 3 above didn't work, in check script written in python, have 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 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 process has terminated. print(out) print(err) sys.exit(0)
the output was:
/sbin:/usr/sbin:/bin:/usr/bin:/etc/sensu/plugins:/etc/sensu/handlers /usr/bin/python 2.6.6 ec2-user
update, while wrote line in python check script:
proc = popen(['bash','--login', '-x'], stdout=pipe, stderr=pipe) out, err = proc.communicate() print(out) print(err)
i saw output:
path=/sbin:/usr/sbin:/bin:/usr/bin:/etc/sensu/plugins:/etc/sensu/handlers:/usr/local/sbin:/usr/local/bin
however, other output surprisingly.... "which python" -> /usr/bin/python, "python --version" -> 2.6.6
request help....
so try add path in /etc/default/sensu
path=$path:/usr/local/bin
https://github.com/sensu/sensu-build/blob/master/sensu_configs/upstart/sensu-client.conf#l30
. /etc/default/sensu
make work.
Comments
Post a Comment