#!/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 @HADOOP_DAEMON@ # # chkconfig: 2345 85 15 # description: Hadoop @HADOOP_DAEMON@ . /etc/rc.d/init.d/functions . /etc/default/hadoop # Autodetect JAVA_HOME if not defined if [ -e /usr/libexec/bigtop-detect-javahome ]; then . /usr/libexec/bigtop-detect-javahome elif [ -e /usr/lib/bigtop-utils/bigtop-detect-javahome ]; then . /usr/lib/bigtop-utils/bigtop-detect-javahome fi . @HADOOP_COMMON_ROOT@/bin/hadoop-config.sh # FIXME: this needs to be removed once hadoop-config.sh stop clobbering HADOOP_HOME . /etc/default/hadoop RETVAL_SUCCESS=0 STATUS_RUNNING=0 STATUS_DEAD=1 STATUS_DEAD_AND_LOCK=2 STATUS_NOT_RUNNING=3 RETVAL=0 HADOOP_PID_DIR=${HADOOP_PID_DIR:-/var/run/hadoop} PIDFILE="$HADOOP_PID_DIR/hadoop-$HADOOP_IDENT_STRING-@HADOOP_DAEMON@.pid" LOCKFILE="/var/lock/subsys/hadoop-@HADOOP_DAEMON@" desc="Hadoop @HADOOP_DAEMON@ daemon" SLEEP_TIME=5 start() { echo -n $"Starting $desc (hadoop-@HADOOP_DAEMON@): " TARGET_USER_NAME="HADOOP_`echo @HADOOP_DAEMON@ | tr a-z A-Z`_USER" TARGET_USER=$(eval "echo \$$TARGET_USER_NAME") if [ "@HADOOP_DAEMON@" = "datanode" ]; then # The following needs to be removed once HDFS-1943 gets finally put to rest. # The logic of this ugly hack is this: IFF we do NOT have jsvc installed it is # guaranteed that we can NOT be running in a secure mode and thus we need to # workaround HDFS-1943 (start as non-root). As soon as jsvc gets installed # we are assuming a secure installation and starting a data node as root. # This leaves 2 corner cases: # 1. HADOOP_DATANODE_USER being set to root # 2. jsvc is installed but Hadoop is configures to run in an unsecure mode # Both will currently fail if [ -f $HADOOP_HOME/libexec/jsvc.amd64 -o -f $HADOOP_HOME/libexec/jsvc.i386 ] && [ -n "$HADOOP_SECURE_DN_USER" ]; then TARGET_USER=root fi fi su -s /bin/bash $TARGET_USER -c "@HADOOP_COMMON_ROOT@/bin/hadoop-daemon.sh --config '@HADOOP_CONF_DIR@' start @HADOOP_DAEMON@ $DAEMON_FLAGS" # Some processes are slow to start sleep $SLEEP_TIME checkstatus RETVAL=$? [ $RETVAL -eq $RETVAL_SUCCESS ] && touch $LOCKFILE return $RETVAL } stop() { echo -n $"Stopping $desc (hadoop-@HADOOP_DAEMON@): " daemon @HADOOP_COMMON_ROOT@/bin/hadoop-daemon.sh --config "@HADOOP_CONF_DIR@" stop @HADOOP_DAEMON@ RETVAL=$? [ $RETVAL -eq $RETVAL_SUCCESS ] && rm -f $LOCKFILE $PIDFILE if [ "@HADOOP_DAEMON@" = "datanode" ]; then # Some processes are slow to stop sleep $SLEEP_TIME checkstatus # Stopping a non running process should be a success if [ $RETVAL -eq $STATUS_NOT_RUNNING ]; then RETVAL=0 fi fi } restart() { stop start } checkstatus(){ status -p $PIDFILE @HADOOP_DAEMON@ RETVAL=$? } condrestart(){ [ -e $LOCKFILE ] && restart || : } check_for_root() { if [ $(id -ur) -ne 0 ]; then echo 'Error: root user required' echo exit 1 fi } hadoopservice() { case "$1" in start) check_for_root start ;; stop) check_for_root stop ;; status) checkstatus ;; restart) check_for_root restart ;; condrestart|try-restart) check_for_root condrestart ;; *) if [ "@HADOOP_DAEMON@" = "namenode" ]; then if [ "$1" = "upgrade" -o "$1" = "rollback" ]; then DAEMON_FLAGS=-$1 $0 start RETVAL=$? else echo $"Usage: $0 {start|stop|status|restart|try-restart|condrestart|upgrade|rollback}" exit 1 fi else echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" exit 1 fi esac } hadoopservice "$1" exit $RETVAL