HADOOP-11055. non-daemon pid files are missing (aw)

This commit is contained in:
Allen Wittenauer 2014-09-16 14:11:15 -07:00
parent 56119fec96
commit ffdb7eb3b2
2 changed files with 83 additions and 37 deletions

View File

@ -325,6 +325,8 @@ Trunk (Unreleased)
HADOOP-11052. hadoop_verify_secure_prereq's results aren't checked HADOOP-11052. hadoop_verify_secure_prereq's results aren't checked
in bin/hdfs (aw) in bin/hdfs (aw)
HADOOP-11055. non-daemon pid files are missing (aw)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-7761. Improve the performance of raw comparisons. (todd) HADOOP-7761. Improve the performance of raw comparisons. (todd)

View File

@ -645,7 +645,7 @@ function hadoop_verify_secure_prereq
# ${EUID} comes from the shell itself! # ${EUID} comes from the shell itself!
if [[ "${EUID}" -ne 0 ]] && [[ -z "${HADOOP_SECURE_COMMAND}" ]]; then if [[ "${EUID}" -ne 0 ]] && [[ -z "${HADOOP_SECURE_COMMAND}" ]]; then
hadoop_error "ERROR: You must be a privileged in order to run a secure serice." hadoop_error "ERROR: You must be a privileged user in order to run a secure service."
exit 1 exit 1
else else
return 0 return 0
@ -704,7 +704,8 @@ function hadoop_verify_logdir
rm "${HADOOP_LOG_DIR}/$$" >/dev/null 2>&1 rm "${HADOOP_LOG_DIR}/$$" >/dev/null 2>&1
} }
function hadoop_status_daemon() { function hadoop_status_daemon()
{
# #
# LSB 4.1.0 compatible status command (1) # LSB 4.1.0 compatible status command (1)
# #
@ -760,11 +761,19 @@ function hadoop_start_daemon
# so complex! so wow! much java! # so complex! so wow! much java!
local command=$1 local command=$1
local class=$2 local class=$2
shift 2 local pidfile=$3
shift 3
hadoop_debug "Final CLASSPATH: ${CLASSPATH}" hadoop_debug "Final CLASSPATH: ${CLASSPATH}"
hadoop_debug "Final HADOOP_OPTS: ${HADOOP_OPTS}" hadoop_debug "Final HADOOP_OPTS: ${HADOOP_OPTS}"
# this is for the non-daemon pid creation
#shellcheck disable=SC2086
echo $$ > "${pidfile}" 2>/dev/null
if [[ $? -gt 0 ]]; then
hadoop_error "ERROR: Cannot write ${command} pid ${pidfile}."
fi
export CLASSPATH export CLASSPATH
#shellcheck disable=SC2086 #shellcheck disable=SC2086
exec "${JAVA}" "-Dproc_${command}" ${HADOOP_OPTS} "${class}" "$@" exec "${JAVA}" "-Dproc_${command}" ${HADOOP_OPTS} "${class}" "$@"
@ -780,26 +789,41 @@ function hadoop_start_daemon_wrapper
local outfile=$4 local outfile=$4
shift 4 shift 4
local counter
hadoop_rotate_log "${outfile}" hadoop_rotate_log "${outfile}"
hadoop_start_daemon "${daemonname}" \ hadoop_start_daemon "${daemonname}" \
"$class" "$@" >> "${outfile}" 2>&1 < /dev/null & "$class" \
"${pidfile}" \
"$@" >> "${outfile}" 2>&1 < /dev/null &
# we need to avoid a race condition here
# so let's wait for the fork to finish
# before overriding with the daemonized pid
(( counter=0 ))
while [[ ! -f ${pidfile} && ${counter} -le 5 ]]; do
sleep 1
(( counter++ ))
done
# this is for daemon pid creation
#shellcheck disable=SC2086 #shellcheck disable=SC2086
echo $! > "${pidfile}" 2>/dev/null echo $! > "${pidfile}" 2>/dev/null
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
hadoop_error "ERROR: Cannot write pid ${pidfile}." hadoop_error "ERROR: Cannot write ${daemonname} pid ${pidfile}."
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
renice "${HADOOP_NICENESS}" $! >/dev/null 2>&1 renice "${HADOOP_NICENESS}" $! >/dev/null 2>&1
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
hadoop_error "ERROR: Cannot set priority of process $!" hadoop_error "ERROR: Cannot set priority of ${daemoname} process $!"
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
disown $! 2>&1 disown %+ >/dev/null 2>&1
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
hadoop_error "ERROR: Cannot disconnect process $!" hadoop_error "ERROR: Cannot disconnect ${daemoname} process $!"
fi fi
sleep 1 sleep 1
@ -829,7 +853,8 @@ function hadoop_start_secure_daemon
# where to send stderr. same thing, except &2 = stderr # where to send stderr. same thing, except &2 = stderr
local daemonerrfile=$5 local daemonerrfile=$5
shift 5 local privpidfile=$6
shift 6
hadoop_rotate_log "${daemonoutfile}" hadoop_rotate_log "${daemonoutfile}"
hadoop_rotate_log "${daemonerrfile}" hadoop_rotate_log "${daemonerrfile}"
@ -850,16 +875,22 @@ function hadoop_start_secure_daemon
hadoop_debug "Final CLASSPATH: ${CLASSPATH}" hadoop_debug "Final CLASSPATH: ${CLASSPATH}"
hadoop_debug "Final HADOOP_OPTS: ${HADOOP_OPTS}" hadoop_debug "Final HADOOP_OPTS: ${HADOOP_OPTS}"
#shellcheck disable=SC2086
echo $$ > "${privpidfile}" 2>/dev/null
if [[ $? -gt 0 ]]; then
hadoop_error "ERROR: Cannot write ${daemoname} pid ${privpidfile}."
fi
exec "${jsvc}" \ exec "${jsvc}" \
"-Dproc_${daemonname}" \ "-Dproc_${daemonname}" \
-outfile "${daemonoutfile}" \ -outfile "${daemonoutfile}" \
-errfile "${daemonerrfile}" \ -errfile "${daemonerrfile}" \
-pidfile "${daemonpidfile}" \ -pidfile "${daemonpidfile}" \
-nodetach \ -nodetach \
-user "${HADOOP_SECURE_USER}" \ -user "${HADOOP_SECURE_USER}" \
-cp "${CLASSPATH}" \ -cp "${CLASSPATH}" \
${HADOOP_OPTS} \ ${HADOOP_OPTS} \
"${class}" "$@" "${class}" "$@"
} }
function hadoop_start_secure_daemon_wrapper function hadoop_start_secure_daemon_wrapper
@ -887,38 +918,51 @@ function hadoop_start_secure_daemon_wrapper
local daemonerrfile=$7 local daemonerrfile=$7
shift 7 shift 7
local counter
hadoop_rotate_log "${jsvcoutfile}" hadoop_rotate_log "${jsvcoutfile}"
hadoop_start_secure_daemon \ hadoop_start_secure_daemon \
"${daemonname}" \ "${daemonname}" \
"${class}" \ "${class}" \
"${daemonpidfile}" \ "${daemonpidfile}" \
"${daemonoutfile}" \ "${daemonoutfile}" \
"${daemonerrfile}" "$@" >> "${jsvcoutfile}" 2>&1 < /dev/null & "${daemonerrfile}" \
"${jsvcpidfile}" "$@" >> "${jsvcoutfile}" 2>&1 < /dev/null &
# This wrapper should only have one child. Unlike Shawty Lo. # we need to avoid a race condition here
# so let's wait for the fork to finish
# before overriding with the daemonized pid
(( counter=0 ))
while [[ ! -f ${pidfile} && ${counter} -le 5 ]]; do
sleep 1
(( counter++ ))
done
# this is for the daemon pid creation
#shellcheck disable=SC2086 #shellcheck disable=SC2086
echo $! > "${jsvcpidfile}" 2>/dev/null echo $! > "${jsvcpidfile}" 2>/dev/null
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
hadoop_error "ERROR: Cannot write pid ${pidfile}." hadoop_error "ERROR: Cannot write ${daemonname} pid ${pidfile}."
fi fi
sleep 1 sleep 1
#shellcheck disable=SC2086 #shellcheck disable=SC2086
renice "${HADOOP_NICENESS}" $! >/dev/null 2>&1 renice "${HADOOP_NICENESS}" $! >/dev/null 2>&1
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
hadoop_error "ERROR: Cannot set priority of process $!" hadoop_error "ERROR: Cannot set priority of ${daemonname} process $!"
fi fi
if [[ -f "${daemonpidfile}" ]]; then if [[ -f "${daemonpidfile}" ]]; then
#shellcheck disable=SC2046 #shellcheck disable=SC2046
renice "${HADOOP_NICENESS}" $(cat "${daemonpidfile}") >/dev/null 2>&1 renice "${HADOOP_NICENESS}" $(cat "${daemonpidfile}" 2>/dev/null) >/dev/null 2>&1
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
hadoop_error "ERROR: Cannot set priority of process $(cat "${daemonpidfile}")" hadoop_error "ERROR: Cannot set priority of ${daemonname} process $(cat "${daemonpidfile}" 2>/dev/null)"
fi fi
fi fi
#shellcheck disable=SC2086 #shellcheck disable=SC2046
disown $! 2>&1 disown %+ >/dev/null 2>&1
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
hadoop_error "ERROR: Cannot disconnect process $!" hadoop_error "ERROR: Cannot disconnect ${daemonname} process $!"
fi fi
# capture the ulimit output # capture the ulimit output
su "${HADOOP_SECURE_USER}" -c 'bash -c "ulimit -a"' >> "${jsvcoutfile}" 2>&1 su "${HADOOP_SECURE_USER}" -c 'bash -c "ulimit -a"' >> "${jsvcoutfile}" 2>&1
@ -994,7 +1038,7 @@ function hadoop_daemon_handler
hadoop_verify_logdir hadoop_verify_logdir
hadoop_status_daemon "${daemon_pidfile}" hadoop_status_daemon "${daemon_pidfile}"
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
hadoop_error "${daemonname} running as process $(cat "${daemon_pidfile}"). Stop it first." hadoop_error "${daemonname} is running as process $(cat "${daemon_pidfile}"). Stop it first."
exit 1 exit 1
else else
# stale pid file, so just remove it and continue on # stale pid file, so just remove it and continue on
@ -1003,7 +1047,7 @@ function hadoop_daemon_handler
##COMPAT - differenticate between --daemon start and nothing ##COMPAT - differenticate between --daemon start and nothing
# "nothing" shouldn't detach # "nothing" shouldn't detach
if [[ "$daemonmode" = "default" ]]; then if [[ "$daemonmode" = "default" ]]; then
hadoop_start_daemon "${daemonname}" "${class}" "$@" hadoop_start_daemon "${daemonname}" "${class}" "${daemon_pidfile}" "$@"
else else
hadoop_start_daemon_wrapper "${daemonname}" \ hadoop_start_daemon_wrapper "${daemonname}" \
"${class}" "${daemon_pidfile}" "${daemon_outfile}" "$@" "${class}" "${daemon_pidfile}" "${daemon_outfile}" "$@"
@ -1042,7 +1086,7 @@ function hadoop_secure_daemon_handler
hadoop_verify_logdir hadoop_verify_logdir
hadoop_status_daemon "${daemon_pidfile}" hadoop_status_daemon "${daemon_pidfile}"
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
hadoop_error "${daemonname} running as process $(cat "${daemon_pidfile}"). Stop it first." hadoop_error "${daemonname} is running as process $(cat "${daemon_pidfile}"). Stop it first."
exit 1 exit 1
else else
# stale pid file, so just remove it and continue on # stale pid file, so just remove it and continue on
@ -1054,7 +1098,7 @@ function hadoop_secure_daemon_handler
if [[ "${daemonmode}" = "default" ]]; then if [[ "${daemonmode}" = "default" ]]; then
hadoop_start_secure_daemon "${daemonname}" "${classname}" \ hadoop_start_secure_daemon "${daemonname}" "${classname}" \
"${daemon_pidfile}" "${daemon_outfile}" \ "${daemon_pidfile}" "${daemon_outfile}" \
"${priv_errfile}" "$@" "${priv_errfile}" "${priv_pidfile}" "$@"
else else
hadoop_start_secure_daemon_wrapper "${daemonname}" "${classname}" \ hadoop_start_secure_daemon_wrapper "${daemonname}" "${classname}" \
"${daemon_pidfile}" "${daemon_outfile}" \ "${daemon_pidfile}" "${daemon_outfile}" \