From 3edf3579c8b01e613eaa90976dfa80bab545a685 Mon Sep 17 00:00:00 2001 From: Eric Yang Date: Tue, 4 Oct 2011 00:44:08 +0000 Subject: [PATCH] HADOOP-7684. Added init.d script for jobhistory server and secondary namenode. (Eric Yang) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1178653 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 + .../deb/init.d/hadoop-secondarynamenode | 142 +++++++++++++++++ .../rpm/init.d/hadoop-secondarynamenode | 92 +++++++++++ .../packages/deb/init.d/hadoop-historyserver | 143 ++++++++++++++++++ .../packages/rpm/init.d/hadoop-historyserver | 85 +++++++++++ 5 files changed, 465 insertions(+) create mode 100644 hadoop-hdfs-project/hadoop-hdfs/src/main/packages/deb/init.d/hadoop-secondarynamenode create mode 100644 hadoop-hdfs-project/hadoop-hdfs/src/main/packages/rpm/init.d/hadoop-secondarynamenode create mode 100644 hadoop-mapreduce-project/src/packages/deb/init.d/hadoop-historyserver create mode 100644 hadoop-mapreduce-project/src/packages/rpm/init.d/hadoop-historyserver diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 500c0dd4e8..1a134ed1cc 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -647,6 +647,9 @@ Release 0.23.0 - Unreleased HADOOP-7658. Fixed HADOOP_SECURE_DN_USER environment variable in hadoop-evn.sh (Eric Yang) + HADOOP-7684. Added init.d script for jobhistory server and + secondary namenode. (Eric Yang) + Release 0.22.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/packages/deb/init.d/hadoop-secondarynamenode b/hadoop-hdfs-project/hadoop-hdfs/src/main/packages/deb/init.d/hadoop-secondarynamenode new file mode 100644 index 0000000000..1b08cd38b8 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/packages/deb/init.d/hadoop-secondarynamenode @@ -0,0 +1,142 @@ +#! /bin/sh + +# 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. + +### BEGIN INIT INFO +# Provides: hadoop-secondarynamenode +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: Apache Hadoop Name Node server +### END INIT INFO + +set -e + +# /etc/init.d/hadoop-secondarynamenode: start and stop the Apache Hadoop Secondary Name Node daemon + +test -x /usr/bin/hadoop || exit 0 +( /usr/bin/hadoop 2>&1 | grep -q hadoop ) 2>/dev/null || exit 0 + +umask 022 + +if test -f /etc/default/hadoop-env.sh; then + . /etc/default/hadoop-env.sh +fi + +. /lib/lsb/init-functions + +# Are we running from init? +run_by_init() { + ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ] +} + +check_for_no_start() { + # forget it if we're trying to start, and /etc/hadoop/hadoop-secondarynamenode_not_to_be_run exists + if [ -e /etc/hadoop/hadoop-secondarynamenode_not_to_be_run ]; then + if [ "$1" = log_end_msg ]; then + log_end_msg 0 + fi + if ! run_by_init; then + log_action_msg "Apache Hadoop Name Node server not in use (/etc/hadoop/hadoop-secondarynamenode_not_to_be_run)" + fi + exit 0 + fi +} + +check_privsep_dir() { + # Create the PrivSep empty dir if necessary + if [ ! -d ${HADOOP_PID_DIR} ]; then + mkdir -p ${HADOOP_PID_DIR} + chown root:hadoop ${HADOOP_PID_DIR} + chmod 0775 ${HADOOP_PID_DIR} + fi +} + +export PATH="${PATH:+$PATH:}/usr/sbin:/usr/bin" +export HADOOP_PREFIX="/usr" + +case "$1" in + start) + check_privsep_dir + check_for_no_start + log_daemon_msg "Starting Apache Hadoop Secondary Name Node server" "hadoop-secondarynamenode" + if start-stop-daemon --start --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-hdfs-secondarynamenode.pid -c hdfs -x ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh -- --config ${HADOOP_CONF_DIR} start secondarynamenode; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + stop) + log_daemon_msg "Stopping Apache Hadoop Secondary Name Node server" "hadoop-secondarynamenode" + if start-stop-daemon --stop --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-hdfs-secondarynamenode.pid; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + restart) + check_privsep_dir + log_daemon_msg "Restarting Apache Hadoop Secondary Name Node server" "hadoop-secondarynamenode" + start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile ${HADOOP_PID_DIR}/hadoop-hdfs-secondarynamenode.pid + check_for_no_start log_end_msg + if start-stop-daemon --start --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-hdfs-secondarynamenode.pid -c hdfs -x ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh -- --config ${HADOOP_CONF_DIR} start secondarynamenode; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + + try-restart) + check_privsep_dir + log_daemon_msg "Restarting Apache Hadoop Secondary Name Node server" "hadoop-secondarynamenode" + set +e + start-stop-daemon --stop --quiet --retry 30 --pidfile ${HADOOP_PID_DIR}/hadoop-hdfs-secondarynamenode.pid + RET="$?" + set -e + case $RET in + 0) + # old daemon stopped + check_for_no_start log_end_msg + if start-stop-daemon --start --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-hdfs-secondarynamenode.pid -c hdfs -x ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh -- --config ${HADOOP_CONF_DIR} start secondarynamenode; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + 1) + # daemon not running + log_progress_msg "(not running)" + log_end_msg 0 + ;; + *) + # failed to stop + log_progress_msg "(failed to stop)" + log_end_msg 1 + ;; + esac + ;; + + status) + status_of_proc -p ${HADOOP_PID_DIR}/hadoop-hdfs-secondarynamenode.pid ${JAVA_HOME}/bin/java hadoop-secondarynamenode && exit 0 || exit $? + ;; + + *) + log_action_msg "Usage: /etc/init.d/hadoop-secondarynamenode {start|stop|restart|try-restart|status}" + exit 1 +esac + +exit 0 diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/packages/rpm/init.d/hadoop-secondarynamenode b/hadoop-hdfs-project/hadoop-hdfs/src/main/packages/rpm/init.d/hadoop-secondarynamenode new file mode 100644 index 0000000000..81fb7445cd --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/packages/rpm/init.d/hadoop-secondarynamenode @@ -0,0 +1,92 @@ +#!/bin/bash + +# 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. + +# +# Starts a Hadoop secondarynamenode +# +# chkconfig: 2345 90 10 +# description: Hadoop secondarynamenode + +source /etc/rc.d/init.d/functions +source /etc/default/hadoop-env.sh + +RETVAL=0 +PIDFILE="${HADOOP_PID_DIR}/hadoop-hdfs-secondarynamenode.pid" +desc="Hadoop secondary namenode daemon" +export HADOOP_PREFIX="/usr" + +start() { + echo -n $"Starting $desc (hadoop-secondarynamenode): " + daemon --user hdfs ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh --config "${HADOOP_CONF_DIR}" start secondarynamenode $1 + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/hadoop-secondarynamenode + return $RETVAL +} + +upgrade() { + start -upgrade +} + +stop() { + echo -n $"Stopping $desc (hadoop-secondarynamenode): " + daemon --user hdfs ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh --config "${HADOOP_CONF_DIR}" stop secondarynamenode + RETVAL=$? + sleep 5 + echo + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/hadoop-secondarynamenode $PIDFILE +} + +checkstatus(){ + status -p $PIDFILE ${JAVA_HOME}/bin/java + RETVAL=$? +} + +restart() { + stop + start +} + +condrestart(){ + [ -e /var/lock/subsys/hadoop-secondarynamenode ] && restart || : +} + +case "$1" in + start) + start + ;; + upgrade) + upgrade + ;; + stop) + stop + ;; + status) + checkstatus + ;; + restart) + restart + ;; + condrestart|try-restart) + condrestart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|try-restart|upgrade}" + exit 1 +esac + +exit $RETVAL diff --git a/hadoop-mapreduce-project/src/packages/deb/init.d/hadoop-historyserver b/hadoop-mapreduce-project/src/packages/deb/init.d/hadoop-historyserver new file mode 100644 index 0000000000..4421f5538e --- /dev/null +++ b/hadoop-mapreduce-project/src/packages/deb/init.d/hadoop-historyserver @@ -0,0 +1,143 @@ +#! /bin/sh + +# 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. + +### BEGIN INIT INFO +# Provides: hadoop-historyserver +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: Apache Hadoop Job Tracker server +### END INIT INFO + +set -e + +# /etc/init.d/hadoop-historyserver: start and stop the Apache Hadoop Job History daemon + +test -x /usr/bin/hadoop || exit 0 +( /usr/bin/hadoop 2>&1 | grep -q hadoop ) 2>/dev/null || exit 0 + +umask 022 + +if test -f /etc/default/hadoop-env.sh; then + . /etc/default/hadoop-env.sh +fi + +. /lib/lsb/init-functions + +# Are we running from init? +run_by_init() { + ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ] +} + +check_for_no_start() { + # forget it if we're trying to start, and /etc/hadoop/hadoop-historyserver_not_to_be_run exists + if [ -e /etc/hadoop/hadoop-historyserver_not_to_be_run ]; then + if [ "$1" = log_end_msg ]; then + log_end_msg 0 + fi + if ! run_by_init; then + log_action_msg "Apache Hadoop Job History server not in use (/etc/hadoop/hadoop-historyserver_not_to_be_run)" + fi + exit 0 + fi +} + +check_privsep_dir() { + # Create the PrivSep empty dir if necessary + if [ ! -d ${HADOOP_PID_DIR} ]; then + mkdir -p ${HADOOP_PID_DIR} + chown root:hadoop ${HADOOP_PID_DIR} + chmod 0775 ${HADOOP_PID_DIR} + fi +} + +export PATH="${PATH:+$PATH:}/usr/sbin:/usr/bin" +export HADOOP_PREFIX="/usr" + +case "$1" in + start) + check_privsep_dir + check_for_no_start + log_daemon_msg "Starting Apache Hadoop Job History server" "hadoop-historyserver" + if start-stop-daemon --start --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-historyserver.pid -c mapred -x ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh -- --config ${HADOOP_CONF_DIR} start historyserver; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + stop) + log_daemon_msg "Stopping Apache Hadoop Job History server" "hadoop-historyserver" + if start-stop-daemon --stop --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-historyserver.pid; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + + restart) + check_privsep_dir + log_daemon_msg "Restarting Apache Hadoop Job History server" "hadoop-historyserver" + start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-historyserver.pid + check_for_no_start log_end_msg + if start-stop-daemon --start --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-historyserver.pid -c mapred -x ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh -- --config ${HADOOP_CONF_DIR} start historyserver; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + + try-restart) + check_privsep_dir + log_daemon_msg "Restarting Apache Hadoop Job History server" "hadoop-historyserver" + set +e + start-stop-daemon --stop --quiet --retry 30 --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-historyserver.pid + RET="$?" + set -e + case $RET in + 0) + # old daemon stopped + check_for_no_start log_end_msg + if start-stop-daemon --start --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-historyserver.pid -c mapred -x ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh -- --config ${HADOOP_CONF_DIR} start historyserver; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + 1) + # daemon not running + log_progress_msg "(not running)" + log_end_msg 0 + ;; + *) + # failed to stop + log_progress_msg "(failed to stop)" + log_end_msg 1 + ;; + esac + ;; + + status) + status_of_proc -p ${HADOOP_PID_DIR}/hadoop-mapred-historyserver.pid ${JAVA_HOME}/bin/java hadoop-historyserver && exit 0 || exit $? + ;; + + *) + log_action_msg "Usage: /etc/init.d/hadoop-historyserver {start|stop|restart|try-restart|status}" + exit 1 +esac + +exit 0 diff --git a/hadoop-mapreduce-project/src/packages/rpm/init.d/hadoop-historyserver b/hadoop-mapreduce-project/src/packages/rpm/init.d/hadoop-historyserver new file mode 100644 index 0000000000..71d1658327 --- /dev/null +++ b/hadoop-mapreduce-project/src/packages/rpm/init.d/hadoop-historyserver @@ -0,0 +1,85 @@ +#!/bin/bash + +# 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. + +# +# Starts a Hadoop historyserver +# +# chkconfig: 2345 90 10 +# description: Hadoop historyserver + +source /etc/rc.d/init.d/functions +source /etc/default/hadoop-env.sh + +RETVAL=0 +PIDFILE="${HADOOP_PID_DIR}/hadoop-mapred-historyserver.pid" +desc="Hadoop historyserver daemon" +export HADOOP_PREFIX="/usr" + +start() { + echo -n $"Starting $desc (hadoop-historyserver): " + daemon --user mapred ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh --config "${HADOOP_CONF_DIR}" start historyserver + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/hadoop-historyserver + return $RETVAL +} + +stop() { + echo -n $"Stopping $desc (hadoop-historyserver): " + daemon --user mapred ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh --config "${HADOOP_CONF_DIR}" stop historyserver + RETVAL=$? + sleep 5 + echo + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/hadoop-historyserver $PIDFILE +} + +restart() { + stop + start +} + +checkstatus(){ + status -p $PIDFILE ${JAVA_HOME}/bin/java + RETVAL=$? +} + +condrestart(){ + [ -e /var/lock/subsys/hadoop-historyserver ] && restart || : +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + checkstatus + ;; + restart) + restart + ;; + condrestart) + condrestart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart}" + exit 1 +esac + +exit $RETVAL