Repository: incubator-ranger Updated Branches: refs/heads/master bbf4d3426 -> 1bd72ed39
RANGER-1068 : Issue with ranger admin restart and pid generation Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/1bd72ed3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/1bd72ed3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/1bd72ed3 Branch: refs/heads/master Commit: 1bd72ed39cc12a45986e270236b0b2f7b49975a6 Parents: bbf4d34 Author: Gautam Borad <[email protected]> Authored: Tue Jun 28 15:06:27 2016 +0530 Committer: Gautam Borad <[email protected]> Committed: Wed Jun 29 10:52:41 2016 +0530 ---------------------------------------------------------------------- .../scripts/ranger-admin-services.sh | 31 +++++--- kms/scripts/ranger-kms | 29 ++++--- tagsync/scripts/ranger-tagsync-services.sh | 72 ++++++++--------- .../scripts/ranger-usersync-services.sh | 82 ++++++++++---------- 4 files changed, 121 insertions(+), 93 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1bd72ed3/embeddedwebserver/scripts/ranger-admin-services.sh ---------------------------------------------------------------------- diff --git a/embeddedwebserver/scripts/ranger-admin-services.sh b/embeddedwebserver/scripts/ranger-admin-services.sh index ea77308..95caacd 100755 --- a/embeddedwebserver/scripts/ranger-admin-services.sh +++ b/embeddedwebserver/scripts/ranger-admin-services.sh @@ -67,23 +67,33 @@ start() { echo "Apache Ranger Admin Service with pid ${pid} has started." else echo "Apache Ranger Admin Service failed to start!" - exit 1 fi + exit; } stop(){ - SLEEP_TIME_AFTER_KILL=5 + WAIT_TIME_FOR_SHUTDOWN=2 + NR_ITER_FOR_SHUTDOWN_CHECK=15 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 + echo "Found Apache Ranger Admin Service with pid $pid, Stopping it..." + 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 + for ((i=0; i<$NR_ITER_FOR_SHUTDOWN_CHECK; i++)) + do + sleep $WAIT_TIME_FOR_SHUTDOWN + if ps -p $pid > /dev/null ; then + echo "Shutdown in progress. Will check after $WAIT_TIME_FOR_SHUTDOWN secs again.." + continue; + else + break; + fi + done # 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 + sleep 1 #give kill -9 sometime to "kill" if ps -p $pid > /dev/null ; then echo "Wow, even kill -9 failed, giving up! Sorry.." exit 1 @@ -98,14 +108,16 @@ stop(){ if [ "${action}" == "START" ]; then if [ -f "$pidf" ] ; then pid=`cat $pidf` - if [ "${pid}" != "" ] + if ps -p $pid > /dev/null then echo "Apache Ranger Admin Service is already running [pid={$pid}]" exit 1 + else + rm -rf $pidf + start; fi - else + else start; - exit; fi elif [ "${action}" == "STOP" ]; then stop; @@ -114,7 +126,6 @@ elif [ "${action}" == "RESTART" ]; then echo "Restarting Apache Ranger Admin" stop; start; - exit; elif [ "${action}" == "VERSION" ]; then cd ${XAPOLICYMGR_EWS_DIR}/webapp/WEB-INF/lib java -cp ranger-util-*.jar org.apache.ranger.common.RangerVersionInfo http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1bd72ed3/kms/scripts/ranger-kms ---------------------------------------------------------------------- diff --git a/kms/scripts/ranger-kms b/kms/scripts/ranger-kms index b5a3b67..d2937aa 100755 --- a/kms/scripts/ranger-kms +++ b/kms/scripts/ranger-kms @@ -92,25 +92,34 @@ createRangerKMSPid () { echo "Apache Ranger KMS Service with pid ${pid} has started." else echo "Apache Ranger KMS Service failed to start" - exit 1 fi + exit ; } killRangerKMSPid () { - SLEEP_TIME_AFTER_KILL=5 + WAIT_TIME_FOR_SHUTDOWN=2 + NR_ITER_FOR_SHUTDOWN_CHECK=15 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 + echo "Found Apache Ranger KMS Service with pid $pid, Stopping..." + nohup java ${JAVA_OPTS} ${STOP_CLASS_NAME} ${KMS_CONFIG_FILENAME} > ${TOMCAT_STOP_LOG_FILE} 2>&1 + for ((i=0; i<$NR_ITER_FOR_SHUTDOWN_CHECK; i++)) + do + sleep $WAIT_TIME_FOR_SHUTDOWN + if ps -p $pid > /dev/null ; then + echo "Shutdown in progress. Will check after $WAIT_TIME_FOR_SHUTDOWN secs again.." + continue; + else + break; + fi + done # 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 + sleep 1 # Give kill -9 sometime to "kill" 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." @@ -122,14 +131,16 @@ killRangerKMSPid () { if [ "${action}" == "START" ]; then if [ -f "$pidf" ] ; then pid=`cat $pidf` - if [ "${pid}" != "" ] + if ps -p $pid > /dev/null then echo "Apache Ranger KMS Service is already running [pid={$pid}]" exit 1 + else + rm -rf $pidf + createRangerKMSPid fi else createRangerKMSPid - exit fi elif [ "${action}" == "STOP" ]; then killRangerKMSPid http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1bd72ed3/tagsync/scripts/ranger-tagsync-services.sh ---------------------------------------------------------------------- diff --git a/tagsync/scripts/ranger-tagsync-services.sh b/tagsync/scripts/ranger-tagsync-services.sh index 1235e86..e81a6b2 100755 --- a/tagsync/scripts/ranger-tagsync-services.sh +++ b/tagsync/scripts/ranger-tagsync-services.sh @@ -61,56 +61,58 @@ if [ "${action}" == "START" ]; then cp="${cdir}/conf:${cdir}/dist/*:${cdir}/lib/*:${RANGER_TAGSYNC_HADOOP_CONF_DIR}/*" - if [ -f $pidf ]; then - PID=`cat $pidf` - if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then - rm -f ${pidf} - else - kill -9 ${PID} > /dev/null 2>&1 - rm -f ${pidf} - echo "Ranger Tagsync Service [pid = ${PID}] has been stopped." - fi - fi + if [ -f "$pidf" ] ; then + pid=`cat $pidf` + if ps -p $pid > /dev/null + then + echo "Apache Ranger Tagsync Service is already running [pid={$pid}]" + exit 1 + else + rm -rf $pidf + fi + fi cd ${cdir} umask 0077 + SLEEP_TIME_AFTER_START=5 nohup java -Dproc_rangertagsync ${JAVA_OPTS} -Dlogdir="${logdir}" -Dlog4j.configuration=file:/etc/ranger/tagsync/conf/log4j.properties -cp "${cp}" org.apache.ranger.tagsync.process.TagSynchronizer > ${logdir}/tagsync.out 2>&1 & - echo $! > ${pidf} - chown ranger ${pidf} - sleep 5 - pid=`cat $pidf` - - if [ "${pid}" != "" ] + VALUE_OF_PID=$! + echo "Starting Apache Ranger Tagsync Service" + sleep $SLEEP_TIME_AFTER_START + if ps -p $VALUE_OF_PID > /dev/null then - if [ -z "`ps axf | grep ${pid} | grep -v grep`" ]; then - rm -f ${pidf} - echo "Ranger Tagsync Service failed to start. Please refer to log files under ${logdir} for further details." - else - echo "Ranger Tagsync Service has started successfully." - fi + echo $VALUE_OF_PID > ${pidf} + chown ranger ${pidf} + chmod 660 ${pidf} + pid=`cat $pidf` + echo "Apache Ranger Tagsync Service with pid ${pid} has started." else - echo "Ranger Tagsync Service failed to start. Please refer to log files under ${logdir} for further details." + echo "Apache Ranger Tagsync Service failed to start!" fi - exit; elif [ "${action}" == "STOP" ]; then - - if [ -f $pidf ]; then - PID=`cat $pidf` > /dev/null 2>&1 - kill -9 $PID > /dev/null 2>&1 - rm -f $pidf - echo "Ranger Tagsync Service [pid = ${PID}] has been stopped." - else + WAIT_TIME_FOR_SHUTDOWN=2 + NR_ITER_FOR_SHUTDOWN_CHECK=15 + if [ -f "$pidf" ] ; then + pid=`cat $pidf` > /dev/null 2>&1 + echo "Found Apache Ranger TagSync Service with pid $pid, Stopping..." + kill -9 $pid > /dev/null 2>&1 + sleep 1 #Give kill -9 sometime to "kill" + if ps -p $pid > /dev/null; then + echo "Wow, even kill -9 failed, giving up! Sorry.." + else + rm -f $pidf + echo "Apache Ranger Tagsync Service pid = ${pid} has been stopped." + fi + else echo "Ranger Tagsync Service not running" - fi - + fi exit; elif [ "${action}" == "RESTART" ]; then - echo "Stopping Ranger Tagsync" + echo "Restarting Apache Ranger Tagsync" ${cdir}/ranger-tagsync-services.sh stop - echo "Starting Apache Ranger Tagsync" ${cdir}/ranger-tagsync-services.sh start exit; elif [ "${action}" == "VERSION" ]; then http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1bd72ed3/unixauthservice/scripts/ranger-usersync-services.sh ---------------------------------------------------------------------- diff --git a/unixauthservice/scripts/ranger-usersync-services.sh b/unixauthservice/scripts/ranger-usersync-services.sh index ed3c936..4f57fdc 100644 --- a/unixauthservice/scripts/ranger-usersync-services.sh +++ b/unixauthservice/scripts/ranger-usersync-services.sh @@ -49,56 +49,60 @@ if [ "${action}" == "START" ]; then cp="${cdir}/dist/*:${cdir}/lib/*:${cdir}/conf:${RANGER_USERSYNC_HADOOP_CONF_DIR}/*" - if [ -f $pidf ]; then - PID=`cat $pidf` - if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then - rm -f ${pidf} - else - kill -9 ${PID} > /dev/null 2>&1 - rm -f ${pidf} - echo "Ranger Usersync Service [pid = ${PID}] has been stopped." - fi - fi - cd ${cdir} umask 0077 - if [ -z "${logdir}" ] - then + if [ -z "${logdir}" ]; then logdir=${cdir}/logs fi - + if [ -f "$pidf" ] ; then + pid=`cat $pidf` + if ps -p $pid > /dev/null + then + echo "Apache Ranger Usersync Service is already running [pid={$pid}]" + exit ; + else + rm -rf $pidf + fi + fi + SLEEP_TIME_AFTER_START=5 nohup java -Dproc_rangerusersync -Dlog4j.configuration=file:/etc/ranger/usersync/conf/log4j.properties ${JAVA_OPTS} -Dlogdir="${logdir}" -cp "${cp}" org.apache.ranger.authentication.UnixAuthenticationService -enableUnixAuth > ${logdir}/auth.log 2>&1 & - echo $! > ${pidf} - chown ranger ${pidf} - sleep 5 - pid=`cat $pidf` - - if [ "${pid}" != "" ] - then - echo "Ranger Usersync Service has started successfully." + VALUE_OF_PID=$! + echo "Starting Apache Ranger Usersync 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 Usersync Service with pid ${pid} has started." else - echo "Ranger Usersync Service failed to start. Please refer to log files under ${logdir} for further details." + echo "Apache Ranger Usersync Service failed to start!" fi exit; elif [ "${action}" == "STOP" ]; then - - if [ -f $pidf ]; then - pidf=/var/run/ranger/usersync.pid - PID=`cat $pidf` > /dev/null 2>&1 - kill -9 $PID > /dev/null 2>&1 - rm -f $pidf - echo "Ranger Usersync Service [pid = ${PID}] has been stopped." - else - echo "Ranger Usersync Service not running" - fi - + WAIT_TIME_FOR_SHUTDOWN=2 + NR_ITER_FOR_SHUTDOWN_CHECK=15 + if [ -f $pidf ]; then + pidf=/var/run/ranger/usersync.pid + pid=`cat $pidf` > /dev/null 2>&1 + kill -9 $pid > /dev/null 2>&1 + sleep 1 #Give kill -9 sometime to "kill" + if ps -p $pid > /dev/null; then + echo "Wow, even kill -9 failed, giving up! Sorry.." + else + rm -f $pidf + echo "Apache Ranger Usersync Service [pid = ${pid}] has been stopped." + fi + else + echo "Apache Ranger Usersync Service not running" + fi exit; elif [ "${action}" == "RESTART" ]; then - echo "Stopping Ranger Usersync" + echo "Restarting Apache Ranger Usersync" ${cdir}/ranger-usersync-services.sh stop - echo "Starting Apache Ranger Usersync" ${cdir}/ranger-usersync-services.sh start exit; elif [ "${action}" == "VERSION" ]; then @@ -106,7 +110,7 @@ elif [ "${action}" == "VERSION" ]; then java -cp ranger-util-*.jar org.apache.ranger.common.RangerVersionInfo exit else - echo "Invalid argument [$1];" - echo "Usage: Only start | stop | restart | version, are supported." - exit; + echo "Invalid argument [$1];" + echo "Usage: Only start | stop | restart | version, are supported." + exit; fi
