Repository: ambari
Updated Branches:
  refs/heads/trunk 536bf049a -> 468764ea2


AMBARI-18360. ambari-agent check for unset variables (AMBARI-18317) (aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/468764ea
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/468764ea
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/468764ea

Branch: refs/heads/trunk
Commit: 468764ea289092f95d013a84496605a3a8fc10dc
Parents: 536bf04
Author: Andrew Onishuk <aonis...@hortonworks.com>
Authored: Mon Sep 19 19:40:19 2016 +0300
Committer: Andrew Onishuk <aonis...@hortonworks.com>
Committed: Mon Sep 19 19:40:19 2016 +0300

----------------------------------------------------------------------
 ambari-agent/conf/unix/ambari-agent | 36 ++++++++++++++++----------------
 ambari-server/sbin/ambari-server    | 16 +++++++-------
 2 files changed, 27 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/468764ea/ambari-agent/conf/unix/ambari-agent
----------------------------------------------------------------------
diff --git a/ambari-agent/conf/unix/ambari-agent 
b/ambari-agent/conf/unix/ambari-agent
index 978e5c6..ccb0b7a 100755
--- a/ambari-agent/conf/unix/ambari-agent
+++ b/ambari-agent/conf/unix/ambari-agent
@@ -18,11 +18,11 @@
 # processname: ambari-agent
 
 # /etc/init.d/ambari-agent
-
+set -u # fail on unset variables
 VERSION="${ambariVersion}"
 HASH="${buildNumber}"
 
-case "$1" in
+case "${1:-}" in
   --version)
         echo -e $VERSION
         exit 0
@@ -35,7 +35,7 @@ esac
 
 get_agent_property() {
   property_name="$1"
-  value=$(awk -F "=" "/$property_name/ {print \$2}" 
/etc/ambari-agent/conf/ambari-agent.ini)
+  value=$(awk -F "=" "/^$property_name/ {print \$2}" 
/etc/ambari-agent/conf/ambari-agent.ini)
   echo $value
 }
 
@@ -43,7 +43,7 @@ export PATH=/usr/sbin:/sbin:/usr/lib/ambari-server/*:$PATH
 export AMBARI_CONF_DIR=/etc/ambari-server/conf:$PATH
 
 # Because Ambari rpm unpacks modules here on all systems
-export PYTHONPATH=/usr/lib/python2.6/site-packages:$PYTHONPATH
+export PYTHONPATH=/usr/lib/python2.6/site-packages:${PYTHONPATH:-}
 
 export AMBARI_PID_DIR=`get_agent_property piddir`
 export AMBARI_AGENT_LOG_DIR=`get_agent_property logdir`
@@ -58,8 +58,8 @@ 
AGENT_SCRIPT=/usr/lib/python2.6/site-packages/ambari_agent/main.py
 AGENT_TMP_DIR=/var/lib/ambari-agent/tmp
 AGENT_WORKING_DIR=/var/lib/ambari-agent
 
AMBARI_AGENT_PY_SCRIPT=/usr/lib/python2.6/site-packages/ambari_agent/AmbariAgent.py
-OK=1
-NOTOK=0
+OK=0
+NOTOK=1
 
 current_user=`id -u -n`
 current_group=`id -g -n`
@@ -79,22 +79,22 @@ change_files_permissions() {
     if [ ! -z "$KEYSDIR" ]; then
         ambari-sudo.sh chown -R $current_user "$KEYSDIR"
     fi
-       ambari-sudo.sh mkdir -p "$AMBARI_PID_DIR"
-       ambari-sudo.sh chown -R $current_user "$AMBARI_PID_DIR/"
-       ambari-sudo.sh mkdir -p "$AMBARI_AGENT_LOG_DIR"
-       ambari-sudo.sh chown -R $current_user:$current_group 
"$AMBARI_AGENT_LOG_DIR/"
+       ambari-sudo.sh mkdir -p "${AMBARI_PID_DIR:?}"
+       ambari-sudo.sh chown -R $current_user "${AMBARI_PID_DIR:?}/"
+       ambari-sudo.sh mkdir -p "${AMBARI_AGENT_LOG_DIR:?}"
+       ambari-sudo.sh chown -R $current_user:$current_group 
"${AMBARI_AGENT_LOG_DIR:?}/"
        ambari-sudo.sh chown -R $current_user "/var/lib/ambari-agent/data/"
        ambari-sudo.sh chown -R $current_user "/var/lib/ambari-agent/cache/"
        ambari-sudo.sh chown    $current_user "/usr/lib/ambari-agent/"
 }
 
 
-if [ -z "$PYTHON" ] ; then
+if [ -z "${PYTHON:-}" ] ; then
   export PYTHON=`readlink $PYTHON_WRAP`
 fi
 
 # Trying to read the passphrase from an environment
-if [ ! -z $AMBARI_PASSPHRASE ]; then
+if [ ! -z ${AMBARI_PASSPHRASE:-} ]; then
   RESOLVED_AMBARI_PASSPHRASE=$AMBARI_PASSPHRASE
 fi
 
@@ -108,14 +108,14 @@ if [ ! -z $AMBARI_AGENT_LOG_DIR ]; then
   LOGFILE=$AMBARI_AGENT_LOG_DIR/ambari-agent.log
 fi
 
-if [ ! -z $AMBARI_AGENT_OUT_DIR ]; then
+if [ ! -z ${AMBARI_AGENT_OUT_DIR:-} ]; then
   OUTFILE=$AMBARI_AGENT_OUT_DIR/ambari-agent.out
 fi
 
-if [ -z $RESOLVED_AMBARI_PASSPHRASE ] &&  [ ! -z $AMBARI_PASSPHRASE ]; then
-  RESOLVED_AMBARI_PASSPHRASE=$AMBARI_PASSPHRASE
+if [ -z ${RESOLVED_AMBARI_PASSPHRASE:-} ] &&  [ ! -z ${AMBARI_PASSPHRASE:-} ]; 
then
+  RESOLVED_AMBARI_PASSPHRASE=${AMBARI_PASSPHRASE:-}
   # If the passphrase is not defined yet, use the value from the env file
-elif [ -z $RESOLVED_AMBARI_PASSPHRASE ]; then
+elif [ -z ${RESOLVED_AMBARI_PASSPHRASE:-} ]; then
   # Passphrase is not defined anywhere, set the default value
   RESOLVED_AMBARI_PASSPHRASE="DEV"
 fi
@@ -141,7 +141,7 @@ check_python_version ()
 
 retcode=0
 
-case "$1" in
+case "${1:-}" in
   start)
         check_python_version
         if [ "$?" -eq "$NOTOK" ]; then
@@ -165,7 +165,7 @@ case "$1" in
 
         echo "Starting ambari-agent"
 
-        if [ "$AMBARI_AGENT_RUN_IN_FOREGROUND" == true ] ; then
+        if [ "${AMBARI_AGENT_RUN_IN_FOREGROUND:-}" == true ] ; then
           $PYTHON $AMBARI_AGENT_PY_SCRIPT "$@" > $OUTFILE 2>&1
           exit $?
         fi

http://git-wip-us.apache.org/repos/asf/ambari/blob/468764ea/ambari-server/sbin/ambari-server
----------------------------------------------------------------------
diff --git a/ambari-server/sbin/ambari-server b/ambari-server/sbin/ambari-server
index f52a598..762ae19 100755
--- a/ambari-server/sbin/ambari-server
+++ b/ambari-server/sbin/ambari-server
@@ -28,11 +28,11 @@
 ### END INIT INFO
 
 # /etc/init.d/ambari-server
-
+set -u # fail on unset variables
 VERSION="${ambariFullVersion}"
 HASH="${buildNumber}"
 
-case "$1" in
+case "${1:-}" in
   --version)
         echo -e $VERSION
         exit 0
@@ -62,19 +62,21 @@ if [ "$?" != "0" ] && [ "$EUID" -ne 0 ] ; then
  exit -1
 fi
 
-if [ -z "$PYTHON" ] ; then
+if [ -z "${PYTHON:-}" ] ; then
   export PYTHON=`readlink $PYTHON_WRAP`
 fi
 
 if [ -a "$AMBARI_ENV" ]; then
+  set +u # temporary disable variables checking for env
   . "$AMBARI_ENV"
+  set -u
 fi
 
-if [ -z "$AMBARI_PASSPHRASE" ]; then
+if [ -z "${AMBARI_PASSPHRASE:-}" ]; then
   AMBARI_PASSPHRASE="DEV"
 fi
 
-if [ -n "$JAVA_HOME" ]; then
+if [ -n "${JAVA_HOME:-}" ]; then
   export JAVA_HOME=$JAVA_HOME
 fi
 
@@ -91,7 +93,7 @@ fi
 echo "Using python " $PYTHON
 
 ret=0
-case "$1" in
+case "${1:-}" in
   start)
         echo -e "Starting ambari-server"
         $PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
@@ -186,7 +188,7 @@ case "$1" in
         ;;
   *)
         echo "Usage: $AMBARI_EXECUTABLE
-        
{start|stop|restart|setup|setup-jce|upgrade|status|upgradestack|setup-ldap|sync-ldap|set-current|setup-security|setup-sso|refresh-stack-hash|backup|restore|update-host-names|enable-stack|check-database|db-cleanup|install-mpack|upgrade-mpack}
 [options]
+        
{start|stop|reset|restart|upgrade|status|upgradestack|setup|setup-jce|setup-ldap|sync-ldap|set-current|setup-security|refresh-stack-hash|backup|restore|update-host-names|check-database|enable-stack|setup-sso|db-cleanup|install-mpack|upgrade-mpack}
 [options]
         Use $AMBARI_PYTHON_EXECUTABLE <action> --help to get details on 
options available.
         Or, simply invoke ambari-server.py --help to print the options."
         exit 1

Reply via email to