Support Questions
Find answers, ask questions, and share your expertise

How to start ambari-agent with python2.7

How to start ambari-agent with python2.7

Contributor

In the below configuration /usr/bin/python is accessing python2.6.

ps -ef | grep python
root      11947      1  0 Oct31 ?        00:00:00 /usr/bin/python /usr/lib/python2.6/site-packages/ambari_agent/AmbariAgent.py start
root      11955  11947 11 Oct31 ?        06:07:25 /usr/bin/python /usr/lib/python2.6/site-packages/ambari_agent/main.py start

How /usr/lib/python is using /usr/lib/python2.6/site-packages/ambari_agent/AmbariAgent.py start script. Is this because of any symlink or do we need to do any changes in the configuration file. If there is any configuration changes then in which file we need to change.

@Abdelkrim Hadjidj

2 REPLIES 2
Highlighted

Re: How to start ambari-agent with python2.7

Super Mentor

@shyam gurram

"main.py": is the main ambari agent script that runs the ambari agent process (main.py).

"AmbariAgent.py" : script is a helper script which does few things before starting the actual agent script "main.py". Like checking the "PID file of ambari agent" and determining the PYTHON environment variable on the OS. More information about AmbariAgent.py can be found at: [1]

"/usr/sbin/ambari-agent": The "AmbariAgent.py" script is actually executed by the most important script which is "/usr/sbin/ambari-agent" script, which does most of the things, like setting the PATH, determining ambari agent PID file, OUTFILE, LOGFILE, AMBARI_AGENT_PY_SCRIPT, COMMON_DIR, COMMON_DIR_AGENT, ...etc

. Please see for more details [3]

The "/usr/sbin/ambari-agent" script determines the initial "PYTHON" as following:

if [ -z "${PYTHON:-}" ] ; then
  export PYTHON=`readlink $PYTHON_WRAP`
fi

Here $PYTHON_WRAP is a wrapper script as following:

PYTHON_WRAP=/usr/bin/ambari-python-wrap


[1] https://github.com/apache/ambari/blob/trunk/ambari-agent/src/main/python/ambari_agent/AmbariAgent.py...
[2] https://github.com/apache/ambari/blob/trunk/ambari-agent/conf/unix/ambari-agent
[3] https://github.com/apache/ambari/blob/trunk/ambari-agent/conf/unix/ambari-agent#L120-L122

.

Highlighted

Re: How to start ambari-agent with python2.7

Super Mentor

@shyam gurram

So in order to use Python 2.7 binary you can use the following approach. Export the PYTHON variable in the Shell or set it globally like inside the "/etc/profile" or "~/.bash_profile" file.

# export PYTHON=/usr/bin/python2.7
# ambari-agent restart

.

Like how the following script is doing: \https://github.com/apache/ambari/blob/release-2.5.2/ambari-shell/ambari-python-shell/conf/unix/ambari-shell#L24-L36

.