ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From v..@apache.org
Subject incubator-ranger git commit: RANGER-1026 : Ranger service to generate PID
Date Tue, 21 Jun 2016 17:27:59 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master 6e07ed2c9 -> e488e8df5


RANGER-1026 : Ranger service to generate PID

Signed-off-by: Velmurugan Periasamy <vel@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/e488e8df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/e488e8df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/e488e8df

Branch: refs/heads/master
Commit: e488e8df57e44ece1a672218eba91223d63b0f87
Parents: 6e07ed2
Author: Mehul Parikh <mehul.parikh@freestoneinfotech.com>
Authored: Mon Jun 20 10:37:20 2016 +0530
Committer: Velmurugan Periasamy <vel@apache.org>
Committed: Tue Jun 21 13:27:31 2016 -0400

----------------------------------------------------------------------
 .../scripts/ranger-admin-services.sh            | 60 +++++++++++++---
 kms/scripts/ranger-kms                          | 74 ++++++++++++++++----
 kms/scripts/ranger-kms-initd                    | 10 ++-
 kms/scripts/setup.sh                            |  4 ++
 security-admin/scripts/setup.sh                 |  3 +-
 5 files changed, 122 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/e488e8df/embeddedwebserver/scripts/ranger-admin-services.sh
----------------------------------------------------------------------
diff --git a/embeddedwebserver/scripts/ranger-admin-services.sh b/embeddedwebserver/scripts/ranger-admin-services.sh
index bd913af..ea77308 100755
--- a/embeddedwebserver/scripts/ranger-admin-services.sh
+++ b/embeddedwebserver/scripts/ranger-admin-services.sh
@@ -29,7 +29,7 @@ XAPOLICYMGR_DIR=`(cd $realScriptDir/..; pwd)`
 XAPOLICYMGR_EWS_DIR=${XAPOLICYMGR_DIR}/ews
 RANGER_JAAS_LIB_DIR="${XAPOLICYMGR_EWS_DIR}/ranger_jaas"
 RANGER_JAAS_CONF_DIR="${XAPOLICYMGR_EWS_DIR}/webapp/WEB-INF/classes/conf/ranger_jaas"
-
+pidf=/var/run/ranger/rangeradmin.pid
 JAVA_OPTS=" ${JAVA_OPTS} -XX:MaxPermSize=256m -Xmx1024m -Xms1024m "
 
 if [ -f ${XAPOLICYMGR_DIR}/ews/webapp/WEB-INF/classes/conf/java_home.sh ]; then
@@ -53,26 +53,66 @@ then
 fi
 
 start() {
-	java -Dproc_rangeradmin ${JAVA_OPTS} -Dlogdir=${RANGER_ADMIN_LOG_DIR} -Dcatalina.base=${XAPOLICYMGR_EWS_DIR}
-cp "${XAPOLICYMGR_EWS_DIR}/webapp/WEB-INF/classes/conf:${XAPOLICYMGR_EWS_DIR}/lib/*:${RANGER_JAAS_LIB_DIR}/*:${RANGER_JAAS_CONF_DIR}:${JAVA_HOME}/lib/*:${RANGER_HADOOP_CONF_DIR}/*:$CLASSPATH"
org.apache.ranger.server.tomcat.EmbeddedServer > ${RANGER_ADMIN_LOG_DIR}/catalina.out 2>&1
&
-	echo "Apache Ranger Admin has started."
+	SLEEP_TIME_AFTER_START=5
+	nohup  java -Dproc_rangeradmin ${JAVA_OPTS} -Dlogdir=${RANGER_ADMIN_LOG_DIR} -Dcatalina.base=${XAPOLICYMGR_EWS_DIR}
-cp "${XAPOLICYMGR_EWS_DIR}/webapp/WEB-INF/classes/conf:${XAPOLICYMGR_EWS_DIR}/lib/*:${RANGER_JAAS_LIB_DIR}/*:${RANGER_JAAS_CONF_DIR}:${JAVA_HOME}/lib/*:${RANGER_HADOOP_CONF_DIR}/*:$CLASSPATH"
org.apache.ranger.server.tomcat.EmbeddedServer > ${RANGER_ADMIN_LOG_DIR}/catalina.out 2>&1
&
+	VALUE_OF_PID=$!
+	echo "Starting Apache Ranger Admin Service"
+	sleep $SLEEP_TIME_AFTER_START
+	if ps -p $VALUE_OF_PID > /dev/null
+	then
+		echo $VALUE_OF_PID > ${pidf}
+		chown ranger ${pidf}
+		chmod 660 ${pidf}
+		pid=`cat $pidf`
+		echo "Apache Ranger Admin Service with pid ${pid} has started."
+	else
+		echo "Apache Ranger Admin Service failed to start!"
+		exit 1
+	fi
 }
 
 stop(){
-	java ${JAVA_OPTS} -Dlogdir=${RANGER_ADMIN_LOG_DIR} -Dcatalina.base=${XAPOLICYMGR_EWS_DIR}
-cp "${XAPOLICYMGR_EWS_DIR}/webapp/WEB-INF/classes/conf:${XAPOLICYMGR_EWS_DIR}/lib/*:${RANGER_JAAS_LIB_DIR}/*:${RANGER_JAAS_CONF_DIR}:${RANGER_HADOOP_CONF_DIR}/*:$CLASSPATH"
org.apache.ranger.server.tomcat.StopEmbeddedServer > ${RANGER_ADMIN_LOG_DIR}/catalina.out
2>&1
-	echo "Apache Ranger Admin has been stopped."
-
+	SLEEP_TIME_AFTER_KILL=5
+	if [ -f "$pidf" ] ; then
+		nohup java ${JAVA_OPTS} -Dlogdir=${RANGER_ADMIN_LOG_DIR} -Dcatalina.base=${XAPOLICYMGR_EWS_DIR}
-cp "${XAPOLICYMGR_EWS_DIR}/webapp/WEB-INF/classes/conf:${XAPOLICYMGR_EWS_DIR}/lib/*:${RANGER_JAAS_LIB_DIR}/*:${RANGER_JAAS_CONF_DIR}:${RANGER_HADOOP_CONF_DIR}/*:$CLASSPATH"
org.apache.ranger.server.tomcat.StopEmbeddedServer > ${RANGER_ADMIN_LOG_DIR}/catalina.out
2>&1
+		pid=`cat $pidf` > /dev/null 2>&1
+		echo "Found Apache Ranger Admin Service with pid $pid, killing..."
+		kill $pid
+		sleep $SLEEP_TIME_AFTER_KILL
+		# if process is still around, use kill -9
+		if ps -p $pid > /dev/null ; then
+			echo "Initial kill failed, getting serious now..."
+			kill -9 $pid
+		fi
+		if ps -p $pid > /dev/null ; then
+			echo "Wow, even kill -9 failed, giving up! Sorry.."
+			exit 1
+		else
+			rm -rf $pidf
+			echo "Apache Ranger Admin Service with pid ${pid} has been stopped."
+		fi
+	else
+		echo "Apache Ranger Admin Service is not running"
+	fi
 }
-
 if [ "${action}" == "START" ]; then
-	start;
-	exit;
+	if [ -f "$pidf" ] ; then
+		pid=`cat $pidf`
+		if [ "${pid}" != "" ]
+		then
+			echo "Apache Ranger Admin Service is already running [pid={$pid}]"
+			exit 1
+		fi
+        else
+		start;
+		exit;
+	fi
 elif [ "${action}" == "STOP" ]; then
 	stop;
 	exit;
 elif [ "${action}" == "RESTART" ]; then
 	echo "Restarting Apache Ranger Admin"
 	stop;
-	sleep 2
 	start;
 	exit;
 elif [ "${action}" == "VERSION" ]; then

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/e488e8df/kms/scripts/ranger-kms
----------------------------------------------------------------------
diff --git a/kms/scripts/ranger-kms b/kms/scripts/ranger-kms
index 0e29d7f..b51e051 100755
--- a/kms/scripts/ranger-kms
+++ b/kms/scripts/ranger-kms
@@ -75,30 +75,74 @@ then
 fi
 
 KMS_CONF_DIR=${RANGER_KMS_EWS_DIR}/webapp/WEB-INF/classes/conf
-
+pidf="/var/run/ranger/rangerkms.pid"
 JAVA_OPTS="${JAVA_OPTS} -Dcatalina.base=${RANGER_KMS_EWS_DIR} -Dkms.config.dir=${KMS_CONF_DIR}
-Dkms.log.dir=${TOMCAT_LOG_DIR} -cp ${RANGER_KMS_EWS_CONF_DIR}:${RANGER_KMS_EWS_LIB_DIR}/*:${RANGER_KMS_EWS_DIR}/webapp/lib/*:${JAVA_HOME}/lib/*:${RANGER_HADOOP_CONF_DIR}/*:$CLASSPATH
"
-
+createRangerKMSPid () {
+	SLEEP_TIME_AFTER_START=5
+	nohup java -D${PROC_NAME} ${JAVA_OPTS} ${START_CLASS_NAME} ${KMS_CONFIG_FILENAME} > ${TOMCAT_LOG_FILE}
2>&1 &
+	VALUE_OF_PID=$!
+	echo "Starting Apache Ranger KMS Service"
+	sleep $SLEEP_TIME_AFTER_START
+	if ps -p $VALUE_OF_PID > /dev/null
+	then
+		echo $VALUE_OF_PID > ${pidf}
+		chown ranger ${pidf}
+		chmod 660 ${pidf}
+		pid=`cat $pidf`
+		echo "Apache Ranger KMS Service with pid ${pid} has started."
+	else
+		echo "Apache Ranger KMS Service failed to start"
+		exit 1
+	fi
+}
+killRangerKMSPid () {
+	SLEEP_TIME_AFTER_KILL=5
+	if [ -f "$pidf" ] ; then
+		nohup java ${JAVA_OPTS} ${STOP_CLASS_NAME} ${KMS_CONFIG_FILENAME} > ${TOMCAT_STOP_LOG_FILE}
2>&1
+		pid=`cat $pidf` > /dev/null 2>&1
+		echo "Found Apache Ranger KMS Service with pid $pid, killing..."
+		kill $pid
+		sleep $SLEEP_TIME_AFTER_KILL
+		# if process is still around, use kill -9
+		if ps -p $pid > /dev/null ; then
+			echo "Initial kill failed, getting serious now..."
+			kill -9 $pid
+		fi
+		if ps -p $pid > /dev/null ; then
+			echo "Wow, even kill -9 failed, giving up! Sorry.."
+			exit 1
+		else
+			rm -rf $pidf
+			echo "Apache Ranger KMS Service with pid ${pid} has been stopped."
+		fi
+	else
+		echo "Apache Ranger KMS Service is not running"
+	fi
+}
 if [ "${action}" == "START" ]; then
-	echo "+ java -D${PROC_NAME} ${JAVA_OPTS} ${START_CLASS_NAME} ${KMS_CONFIG_FILENAME} "
-	java -D${PROC_NAME} ${JAVA_OPTS} ${START_CLASS_NAME} ${KMS_CONFIG_FILENAME} > ${TOMCAT_LOG_FILE}
2>&1 &
-	echo "Apache Ranger KMS has started."
-	exit
+	if [ -f "$pidf" ] ; then
+		pid=`cat $pidf`
+		if [ "${pid}" != "" ]
+		then
+			echo "Apache Ranger KMS Service is already running [pid={$pid}]"
+			exit 1
+		fi
+	else
+		createRangerKMSPid
+		exit
+	fi
 elif [ "${action}" == "STOP" ]; then
-	java ${JAVA_OPTS} ${STOP_CLASS_NAME} ${KMS_CONFIG_FILENAME} > ${TOMCAT_STOP_LOG_FILE}
2>&1
-	echo "Apache Ranger KMS has been stopped."
+	killRangerKMSPid
 	exit
 elif [ "${action}" == "RESTART" ]; then
-	echo "Restarting Apache Ranger KMS"
-	java ${JAVA_OPTS} ${STOP_CLASS_NAME} ${KMS_CONFIG_FILENAME} > ${TOMCAT_STOP_LOG_FILE}
2>&1
-	echo "Apache Ranger KMS has been stopped."
-	echo "Starting Apache Ranger KMS."
-	java -D${PROC_NAME} ${JAVA_OPTS} ${START_CLASS_NAME} ${KMS_CONFIG_FILENAME} > ${TOMCAT_LOG_FILE}
2>&1 &
-	echo "Apache Ranger KMS has started successfully."
+	echo "Restarting Apache Ranger KMS Service"
+	killRangerKMSPid
+	createRangerKMSPid
 	exit
 elif [ "${action}" == "VERSION" ]; then
 	( cd ${RANGER_KMS_LIB_DIR} ; java -cp ranger-util-*.jar org.apache.ranger.common.RangerVersionInfo
)
 	exit
-else 
+else
         echo "Invalid argument [$1];"
         echo "Usage: Only start | stop | restart | version, are supported."
         exit;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/e488e8df/kms/scripts/ranger-kms-initd
----------------------------------------------------------------------
diff --git a/kms/scripts/ranger-kms-initd b/kms/scripts/ranger-kms-initd
index f3a79f5..c96988f 100755
--- a/kms/scripts/ranger-kms-initd
+++ b/kms/scripts/ranger-kms-initd
@@ -24,11 +24,15 @@
 # Short-Description: Start/Stop Ranger kms
 ### END INIT INFO
 
-LINUX_USER=kms
+#LINUX_USER=kms
 BIN_PATH=/usr/bin
 MOD_NAME=ranger-kms
-
-pid=`ps -ef | grep java | grep -- '-Dproc_rangerkms' | grep -v grep | awk '{ print $2 }'`
+pidf=/var/run/ranger/rangerkms.pid
+if [ -f $pidf ]; then
+	pid=`cat $pidf`
+else
+    pid=`ps -ef | grep java | grep -- '-Dproc_rangerkms' | grep -v grep | awk '{ print $2
}'`
+fi
 
 case $1 in
 start)

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/e488e8df/kms/scripts/setup.sh
----------------------------------------------------------------------
diff --git a/kms/scripts/setup.sh b/kms/scripts/setup.sh
index 031c4f3..b44f6ba 100755
--- a/kms/scripts/setup.sh
+++ b/kms/scripts/setup.sh
@@ -24,6 +24,10 @@ propertyValue=''
 
 CONF_FILE=$PWD/ews/webapp/WEB-INF/classes/conf
 ETC_CONF_FILE=/etc/ranger/kms/conf
+pidFolderName='/var/run/ranger'
+if [ ! -d "${pidFolderName}" ]; then
+    mkdir -p "${pidFolderName}"
+fi
 
 if [ ! -f ${PROPFILE} ]
 then

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/e488e8df/security-admin/scripts/setup.sh
----------------------------------------------------------------------
diff --git a/security-admin/scripts/setup.sh b/security-admin/scripts/setup.sh
index bb79592..40c8584 100755
--- a/security-admin/scripts/setup.sh
+++ b/security-admin/scripts/setup.sh
@@ -21,7 +21,8 @@
 
 PROPFILE=$PWD/install.properties
 propertyValue=''
-
+pidFolderName='/var/run/ranger'
+mkdir -p ${pidFolderName}
 if [ ! $? = "0" ];then
 	log "$PROPFILE file not found....!!";
 	exit 1;


Mime
View raw message