Refactor error logging

It is hard to grep errors in current log. so in this patch,
I'm updating die function which also writes log for
screen_log_dir/error.log.
In future, we may categolize negative fault by using
this error.log.

Change-Id: I70a8cfe67ed408284f5c88c762c6bb8acb8ecdb2
diff --git a/lib/glance b/lib/glance
index 80d3902..cbe47fc 100644
--- a/lib/glance
+++ b/lib/glance
@@ -187,8 +187,7 @@
     screen_it g-api "cd $GLANCE_DIR; $GLANCE_BIN_DIR/glance-api --config-file=$GLANCE_CONF_DIR/glance-api.conf"
     echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..."
     if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$GLANCE_HOSTPORT; do sleep 1; done"; then
-      echo "g-api did not start"
-      exit 1
+      die $LINENO "g-api did not start"
     fi
 }
 
diff --git a/lib/keystone b/lib/keystone
index a1a57f8..2580351 100644
--- a/lib/keystone
+++ b/lib/keystone
@@ -323,8 +323,7 @@
     screen_it key "cd $KEYSTONE_DIR && $KEYSTONE_DIR/bin/keystone-all --config-file $KEYSTONE_CONF $KEYSTONE_LOG_CONFIG -d --debug"
     echo "Waiting for keystone to start..."
     if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= curl -s http://$SERVICE_HOST:$service_port/v2.0/ >/dev/null; do sleep 1; done"; then
-      echo "keystone did not start"
-      exit 1
+      die $LINENO "keystone did not start"
     fi
 
     # Start proxies if enabled
diff --git a/lib/nova b/lib/nova
index 849ec57..3749790 100644
--- a/lib/nova
+++ b/lib/nova
@@ -542,8 +542,7 @@
     screen_it n-api "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-api"
     echo "Waiting for nova-api to start..."
     if ! wait_for_service $SERVICE_TIMEOUT http://$SERVICE_HOST:$service_port; then
-      echo "nova-api did not start"
-      exit 1
+      die $LINENO "nova-api did not start"
     fi
 
     # Start proxies if enabled
diff --git a/lib/quantum b/lib/quantum
index 0fef1ae..9068f62 100644
--- a/lib/quantum
+++ b/lib/quantum
@@ -351,8 +351,7 @@
     screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
     echo "Waiting for Quantum to start..."
     if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then
-      echo "Quantum did not start"
-      exit 1
+      die $LINENO "Quantum did not start"
     fi
 }
 
@@ -396,8 +395,7 @@
     quantum_plugin_configure_common
 
     if [[ $Q_PLUGIN_CONF_PATH == '' || $Q_PLUGIN_CONF_FILENAME == '' || $Q_PLUGIN_CLASS == '' ]]; then
-        echo "Quantum plugin not set.. exiting"
-        exit 1
+        die $LINENO "Quantum plugin not set.. exiting"
     fi
 
     # If needed, move config file from ``$QUANTUM_DIR/etc/quantum`` to ``QUANTUM_CONF_DIR``
@@ -511,8 +509,7 @@
     if is_service_enabled $DATABASE_BACKENDS; then
         recreate_database $Q_DB_NAME utf8
     else
-        echo "A database must be enabled in order to use the $Q_PLUGIN Quantum plugin."
-        exit 1
+        die $LINENO "A database must be enabled in order to use the $Q_PLUGIN Quantum plugin."
     fi
 
     # Update either configuration file with plugin
@@ -661,11 +658,10 @@
     fi
     if ! timeout $timeout_sec sh -c "$check_command"; then
         if [[ "$expected" = "True" ]]; then
-            echo "[Fail] Couldn't ping server"
+            die $LINENO "[Fail] Couldn't ping server"
         else
-            echo "[Fail] Could ping server"
+            die $LINENO "[Fail] Could ping server"
         fi
-        exit 1
     fi
 }
 
@@ -679,8 +675,7 @@
     local probe_cmd = ""
     probe_cmd=`_get_probe_cmd_prefix $from_net`
     if ! timeout $timeout_sec sh -c "while ! $probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success ; do sleep 1; done"; then
-        echo "server didn't become ssh-able!"
-        exit 1
+        die $LINENO "server didn't become ssh-able!"
     fi
 }
 
diff --git a/lib/quantum_plugins/nicira b/lib/quantum_plugins/nicira
index bc9a36f..8c150b1 100644
--- a/lib/quantum_plugins/nicira
+++ b/lib/quantum_plugins/nicira
@@ -19,8 +19,7 @@
         conn=(${NVP_CONTROLLER_CONNECTION//\:/ })
         OVS_MGR_IP=${conn[0]}
     else
-        echo "Error - No controller specified. Unable to set a manager for OVS"
-        exit 1
+        die $LINENO "Error - No controller specified. Unable to set a manager for OVS"
     fi
     sudo ovs-vsctl set-manager ssl:$OVS_MGR_IP
 }
@@ -63,14 +62,12 @@
 
 function quantum_plugin_configure_l3_agent() {
    # Nicira plugin does not run L3 agent
-   echo "ERROR - q-l3 should must not be executed with Nicira plugin!"
-   exit 1
+   die $LINENO "q-l3 should must not be executed with Nicira plugin!"
 }
 
 function quantum_plugin_configure_plugin_agent() {
    # Nicira plugin does not run L2 agent
-   echo "ERROR - q-agt must not be executed with Nicira plugin!"
-   exit 1
+   die $LINENO "q-agt must not be executed with Nicira plugin!"
 }
 
 function quantum_plugin_configure_service() {
@@ -93,8 +90,7 @@
         if [[ "$DEFAULT_TZ_UUID" != "" ]]; then
             iniset /$Q_PLUGIN_CONF_FILE "CLUSTER:$DC" default_tz_uuid $DEFAULT_TZ_UUID
         else
-            echo "ERROR - The nicira plugin won't work without a default transport zone."
-            exit 1
+            die $LINENO "The nicira plugin won't work without a default transport zone."
         fi
         if [[ "$DEFAULT_L3_GW_SVC_UUID" != "" ]]; then
             iniset /$Q_PLUGIN_CONF_FILE "CLUSTER:$DC" default_l3_gw_service_uuid $DEFAULT_L3_GW_SVC_UUID
@@ -114,8 +110,7 @@
             # Only 1 controller can be specified in this case
             iniset /$Q_PLUGIN_CONF_FILE "CLUSTER:$DC" nvp_controller_connection $NVP_CONTROLLER_CONNECTION
         else
-            echo "ERROR - The nicira plugin needs at least an NVP controller."
-            exit 1
+            die $LINENO "The nicira plugin needs at least an NVP controller."
         fi
         if [[ "$NVP_USER" != "" ]]; then
             iniset /$Q_PLUGIN_CONF_FILE "CLUSTER:$DC" nvp_user $NVP_USER
diff --git a/lib/quantum_plugins/openvswitch b/lib/quantum_plugins/openvswitch
index 726c6c3..288fa69 100644
--- a/lib/quantum_plugins/openvswitch
+++ b/lib/quantum_plugins/openvswitch
@@ -49,9 +49,7 @@
         # REVISIT - also check kernel module support for GRE and patch ports
         OVS_VERSION=`ovs-vsctl --version | head -n 1 | awk '{print $4;}'`
         if [ $OVS_VERSION \< "1.4" ] && ! is_service_enabled q-svc ; then
-            echo "You are running OVS version $OVS_VERSION."
-            echo "OVS 1.4+ is required for tunneling between multiple hosts."
-            exit 1
+            die $LINENO "You are running OVS version $OVS_VERSION. OVS 1.4+ is required for tunneling between multiple hosts."
         fi
         iniset /$Q_PLUGIN_CONF_FILE OVS enable_tunneling True
         iniset /$Q_PLUGIN_CONF_FILE OVS local_ip $HOST_IP
diff --git a/lib/rpc_backend b/lib/rpc_backend
index f35f9db..7ea71ee 100644
--- a/lib/rpc_backend
+++ b/lib/rpc_backend
@@ -39,8 +39,7 @@
     fi
 
     if is_service_enabled qpid && ! qpid_is_supported; then
-        echo "Qpid support is not available for this version of your distribution."
-        exit 1
+        die $LINENO "Qpid support is not available for this version of your distribution."
     fi
 }