HADOOP-12364. Deleting pid file after stop is causing the daemons to keep restarting (Sigi Li via aw)
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/56dc7773 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/56dc7773 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/56dc7773 Branch: refs/heads/HDFS-7966 Commit: 56dc7773f857085f1110894b427e596afd11ee2e Parents: 0d77e85 Author: Allen Wittenauer <a...@apache.org> Authored: Wed Oct 14 11:16:10 2015 -0700 Committer: Allen Wittenauer <a...@apache.org> Committed: Wed Oct 14 11:16:10 2015 -0700 ---------------------------------------------------------------------- hadoop-common-project/hadoop-common/CHANGES.txt | 3 ++ .../src/main/bin/hadoop-functions.sh | 36 ++++++++++++++++--- .../src/test/scripts/hadoop_stop_daemon.bats | 31 ++++++++++++++++ .../test/scripts/hadoop_stop_secure_daemon.bats | 37 ++++++++++++++++++++ 4 files changed, 103 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/56dc7773/hadoop-common-project/hadoop-common/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 76e7884..27f368d 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -510,6 +510,9 @@ Trunk (Unreleased) HADOOP-11942. Add links to SLGUserGuide to site index. (Masatake Iwasaki via xyao) + HADOOP-12364. Deleting pid file after stop is causing the daemons to + keep restarting (Sigi Li via aw) + OPTIMIZATIONS HADOOP-7761. Improve the performance of raw comparisons. (todd) http://git-wip-us.apache.org/repos/asf/hadoop/blob/56dc7773/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh index b9b7919..e81216a 100755 --- a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh +++ b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh @@ -1501,7 +1501,7 @@ function hadoop_start_secure_daemon local daemonname=$1 local class=$2 - # pid file to create for our deamon + # pid file to create for our daemon local daemonpidfile=$3 # where to send stdout. jsvc has bad habits so this *may* be &1 @@ -1662,6 +1662,7 @@ function hadoop_stop_daemon shift 2 local pid + local cur_pid if [[ -f "${pidfile}" ]]; then pid=$(cat "$pidfile") @@ -1675,7 +1676,12 @@ function hadoop_stop_daemon if ps -p "${pid}" > /dev/null 2>&1; then hadoop_error "ERROR: Unable to kill ${pid}" else - rm -f "${pidfile}" >/dev/null 2>&1 + cur_pid=$(cat "$pidfile") + if [[ "${pid}" = "${cur_pid}" ]]; then + rm -f "${pidfile}" >/dev/null 2>&1 + else + hadoop_error "WARNING: pid has changed for ${cmd}, skip deleting pid file" + fi fi fi } @@ -1697,9 +1703,31 @@ function hadoop_stop_secure_daemon shift 3 local ret + local daemon_pid + local priv_pid + local cur_daemon_pid + local cur_priv_pid + + daemon_pid=$(cat "$daemonpidfile") + priv_pid=$(cat "$privpidfile") + hadoop_stop_daemon "${command}" "${daemonpidfile}" ret=$? - rm -f "${daemonpidfile}" "${privpidfile}" 2>/dev/null + + cur_daemon_pid=$(cat "$daemonpidfile") + cur_priv_pid=$(cat "$privpidfile") + + if [[ "${daemon_pid}" = "${cur_daemon_pid}" ]]; then + rm -f "${daemonpidfile}" >/dev/null 2>&1 + else + hadoop_error "WARNING: daemon pid has changed for ${command}, skip deleting daemon pid file" + fi + + if [[ "${priv_pid}" = "${cur_priv_pid}" ]]; then + rm -f "${privpidfile}" >/dev/null 2>&1 + else + hadoop_error "WARNING: priv pid has changed for ${command}, skip deleting priv pid file" + fi return ${ret} } @@ -1956,4 +1984,4 @@ function hadoop_parse_args done hadoop_debug "hadoop_parse: asking caller to skip ${HADOOP_PARSE_COUNTER}" -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/56dc7773/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_stop_daemon.bats ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_stop_daemon.bats b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_stop_daemon.bats new file mode 100644 index 0000000..023d01c --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_stop_daemon.bats @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load hadoop-functions_test_helper + +@test "hadoop_stop_daemon" { + old_pid=12345 + new_pid=54321 + HADOOP_STOP_TIMEOUT=3 + + echo ${old_pid} > pidfile + run hadoop_stop_daemon stop pidfile & + sleep 1 + echo ${new_pid} > pidfile + sleep ${HADOOP_STOP_TIMEOUT} + + [ -f pidfile ] + [ "$(cat pidfile)" = "${new_pid}" ] +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/56dc7773/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_stop_secure_daemon.bats ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_stop_secure_daemon.bats b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_stop_secure_daemon.bats new file mode 100644 index 0000000..1bb3f4b --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_stop_secure_daemon.bats @@ -0,0 +1,37 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load hadoop-functions_test_helper + +@test "hadoop_stop_secure_daemon" { + old_daemon_pid=12345 + old_priv_pid=23456 + new_daemon_pid=54321 + new_priv_pid=65432 + HADOOP_STOP_TIMEOUT=3 + + echo ${old_daemon_pid} > daemonpidfile + echo ${old_priv_pid} > privpidfile + run hadoop_stop_secure_daemon stop daemonpidfile privpidfile & + sleep 1 + echo ${new_daemon_pid} > daemonpidfile + echo ${new_priv_pid} > privpidfile + sleep ${HADOOP_STOP_TIMEOUT} + + [ -f daemonpidfile ] + [ "$(cat daemonpidfile)" = "${new_daemon_pid}" ] + [ -f privpidfile ] + [ "$(cat privpidfile)" = "${new_priv_pid}" ] +}