Skip to content

Instantly share code, notes, and snippets.

@myui
Last active May 17, 2017 09:22
Show Gist options
  • Save myui/4dff723bcf4aa9ab712e to your computer and use it in GitHub Desktop.
Save myui/4dff723bcf4aa9ab712e to your computer and use it in GitHub Desktop.
Init.d script for hadoop-nodemanager
#!/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 YARN NodeManager
#
# chkconfig: 2345 80 10
# description: Hadoop YARN NodeManager
source /etc/profile.d/hadoop26-env.sh
source /etc/profile.d/jdk.sh
source /etc/init.d/functions
source ${HADOOP_HOME}/etc/hadoop/hadoop-env.sh
source ${HADOOP_HOME}/etc/hadoop/yarn-env.sh
RETVAL=0
PIDFILE="${YARN_PID_DIR}/hadoop-yarn-nodemanager.pid"
desc="Hadoop YARN NodeManager daemon"
start() {
echo -n $"Starting $desc (hadoop-nodemanager): "
daemon --user hadoop ${HADOOP_HOME}/sbin/yarn-daemon.sh --config "${HADOOP_CONF_DIR}" start nodemanager
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/hadoop-yarn-nodemanager
return $RETVAL
}
stop() {
echo -n $"Stopping $desc (hadoop-nodemanager): "
daemon --user hadoop ${HADOOP_HOME}/sbin/yarn-daemon.sh --config "${HADOOP_CONF_DIR}" stop nodemanager
RETVAL=$?
sleep 5
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/hadoop-yarn-nodemanager $PIDFILE
}
checkstatus(){
echo $"$desc $(status -p $PIDFILE)"
RETVAL=$?
}
restart() {
stop
start
}
condrestart(){
[ -e /var/lock/hadoop-yarn-nodemanager ] && restart || :
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
checkstatus
;;
restart)
restart
;;
condrestart|try-restart)
condrestart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart}"
exit 1
esac
exit $RETVAL
@myui
Copy link
Author

myui commented Apr 23, 2015

sudo ln -sf /lib/lsb/init-functions /etc/init.d/functions
sudo apt-get install daemon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment