hadoop hbase /etc/init.d style startup scripts

I scoured the InterTubes for example hadoop/hbase startup scripts and found absolutely none! I ended up creating a minimal one that is so far only suited for the Pseudo-Distributed Operation mode as it just calls the start-all / stop-all scripts.

/etc/init.d/hadoop
Create the place it will put its startup logs

mkdir /var/log/hadoopCreate /etc/init.d/hadoop with the following:


#!/bin/sh
### BEGIN INIT INFO
# Provides: hadoop services
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Hadoop services
# Short-Description: Enable Hadoop services including hdfs
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HADOOP_BIN=/usr/local/hadoop/bin
NAME=hadoop
DESC=hadoop
USER=hadoop
ROTATE_SUFFIX=
test -x $HADOOP_BIN || exit 0
RETVAL=0
set -e
cd /

start_hadoop () {
set +e
su $USER -s /bin/sh -c $HADOOP_BIN/start-all.sh > /var/log/hadoop/startup_log
case "$?" in
0)
echo SUCCESS
RETVAL=0
;;
1)
echo TIMEOUT - check /var/log/hadoop/startup_log
RETVAL=1
;;
*)
echo FAILED - check /var/log/hadoop/startup_log
RETVAL=1
;;
esac
set -e
}

stop_hadoop () {
set +e
if [ $RETVAL = 0 ] ; then
su $USER -s /bin/sh -c $HADOOP_BIN/stop-all.sh > /var/log/hadoop/shutdown_log
RETVAL=$?
if [ $RETVAL != 0 ] ; then
echo FAILED - check /var/log/hadoop/shutdown_log
fi
else
echo No nodes running
RETVAL=0
fi
set -e
}

restart_hadoop() {
stop_hadoop
start_hadoop
}

case "$1" in
start)
echo -n "Starting $DESC: "
start_hadoop
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
stop_hadoop
echo "$NAME."
;;
force-reload|restart)
echo -n "Restarting $DESC: "
restart_hadoop
echo "$NAME."
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
RETVAL=1
;;
esac
exit $RETVAL



/etc/init.d/hbase
Create the place it will put its startup logs

mkdir /var/log/hbaseCreate /etc/init.d/hbase with the following:


#!/bin/sh
### BEGIN INIT INFO
# Provides: hbase services
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Hbase services
# Short-Description: Enable Hbase services including hdfs
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HBASE_BIN=/usr/local/hbase/bin
NAME=hbase
DESC=hbase
USER=hadoop
ROTATE_SUFFIX=
test -x $HBASE_BIN || exit 0
RETVAL=0
set -e
cd /

start_hbase () {
set +e
su $USER -s /bin/sh -c $HBASE_BIN/start-hbase.sh > /var/log/hbase/startup_log
case "$?" in
0)
echo SUCCESS
RETVAL=0
;;
1)
echo TIMEOUT - check /var/log/hbase/startup_log
RETVAL=1
;;
*)
echo FAILED - check /var/log/hbase/startup_log
RETVAL=1
;;
esac
set -e
}

stop_hbase () {
set +e
if [ $RETVAL = 0 ] ; then
su $USER -s /bin/sh -c $HBASE_BIN/stop-hbase.sh > /var/log/hbase/shutdown_log
RETVAL=$?
if [ $RETVAL != 0 ] ; then
echo FAILED - check /var/log/hbase/shutdown_log
fi
else
echo No nodes running
RETVAL=0
fi
set -e
}

restart_hbase() {
stop_hbase
start_hbase
}

case "$1" in
start)
echo -n "Starting $DESC: "
start_hbase
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
stop_hbase
echo "$NAME."
;;
force-reload|restart)
echo -n "Restarting $DESC: "
restart_hbase
echo "$NAME."
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
RETVAL=1
;;
esac
exit $RETVAL


Set up the init system
This assumes you put the above init files in /etc/init.d

chmod +x /etc/init.d/{hbase,hadoop}
update-rc.d hadoop defaults
update-rc.d hbase defaults 25You can now start / stop hadoop by saying:

/etc/init.d/hadoop start/etc/init.d/hadoop stopAnd similarly with hbase

/etc/init.d/hbase start/etc/init.d/hbase stopMake sure you start hadoop before hbase and stop hbase before you stop hadoop
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值