Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Better way the change Logging directories for Ambari-Server and Ambari-Agent?

avatar

For Ambari-Server, I currently make adjustments to:

/etc/ambari-server/conf/log4j.properties

And for the Agent, I have to create a symlink to redirect /var/log/ambari-agent.

Is there a better method?

1 ACCEPTED SOLUTION

avatar
Contributor

For ambari-agent, use the $AMBARI_AGENT_LOG_DIR environment variable. There is a typo in /usr/sbin/ambari-agent shell script though:

Just change $AMBARI_LOG_DIR to $AMBARI_AGENT_LOG_DIR in /usr/sbin/ambari-agent. Now set $AMBARI_AGENT_LOG_DIR to the desired location.

The bug has been fixed in trunk: https://reviews.apache.org/r/37990/

For ambari-server, there is no such environment variable. I'll file a bug for this and have it triaged.

View solution in original post

4 REPLIES 4

avatar
Guru

@dstreever@hortonworks.com David for ambari-agent the "LOGFILE" directory is hardcoded in the /usr/sbin/ambari-agent which is called directly from the ambari-agent start script. It isn't possible right now to paramatize this value. You could change the value of "LOGFILE" in /usr/sbin/ambari-agent but using a symlink is the probably the best option. "LOGFILE" is located on line 45.

LOGFILE=/var/log/ambari-agent/ambari-agent.log

avatar
Guru
@dstreever@hortonworks.com

David after looking a little more closely I was wrong. You can specify the ambari-agent logging directory (but not file name) using the environment variable "AMBARI_AGENT_LOG_DIR". Hope that helps

avatar

If you feel like hacking, I think you can also do this via AmbariConfig.py:

ambari-agent.log:

/usr/lib/python2.6/site-packages/ambari_agent/AmbariConfig.py:

  @staticmethod
  def getLogFile():
    if 'AMBARI_AGENT_LOG_DIR' in os.environ:
      return os.path.join(os.environ['AMBARI_AGENT_LOG_DIR'], "ambari-agent.log")
    else:
#      return os.path.join(os.sep, "var", "log", "ambari-agent", "ambari-agent.log")
      return "/new_log_dir/ambari-agent.log" 

ambari-agent.out:

/usr/lib/python2.6/site-packages/ambari_agent/AmbariConfig.py:

  @staticmethod
  def getOutFile():
    if 'AMBARI_AGENT_OUT_DIR' in os.environ:
      return os.path.join(os.environ['AMBARI_AGENT_OUT_DIR'], "ambari-agent.out")
    else:
#      return os.path.join(os.sep, "var", "log", "ambari-agent", "ambari-agent.out")
      return "/new_log_dir/ambari-agent.out"      

ambari-server.out:

/usr/lib/python2.6/site-packages/ambari_server/serverConfiguration.py:

class ServerConfigDefaults(object):
  def __init__(self):
    self.JAVA_SHARE_PATH = "/usr/share/java"
#    self.OUT_DIR = os.sep + os.path.join("var", "log", "ambari-server")
    self.OUT_DIR = os.sep + os.path.join("new_log_dir", "ambari-server")
    self.SERVER_OUT_FILE = os.path.join(self.OUT_DIR, "ambari-server.out")
    self.SERVER_LOG_FILE = os.path.join(self.OUT_DIR, "ambari-server.log")
    self.ROOT_FS_PATH = os.sep

ambari-server.log:

vi /etc/ambari-server/conf/log4j.properties:

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
#log4j.appender.file.File=/var/log/ambari-server/ambari-server.log
log4j.appender.file.File=/new_log_dir/ambari-server.log
log4j.appender.file.MaxFileSize=80MB
log4j.appender.file.MaxBackupIndex=60
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{DATE} %5p [%t] %c{1}:%L - %m%n

avatar
Contributor

For ambari-agent, use the $AMBARI_AGENT_LOG_DIR environment variable. There is a typo in /usr/sbin/ambari-agent shell script though:

Just change $AMBARI_LOG_DIR to $AMBARI_AGENT_LOG_DIR in /usr/sbin/ambari-agent. Now set $AMBARI_AGENT_LOG_DIR to the desired location.

The bug has been fixed in trunk: https://reviews.apache.org/r/37990/

For ambari-server, there is no such environment variable. I'll file a bug for this and have it triaged.