Created
December 11, 2015 00:22
-
-
Save cmoscardi/e9364b88b0ed19788ec0 to your computer and use it in GitHub Desktop.
ahh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 HDFS DataNode | |
# | |
# chkconfig: 345 85 15 | |
# description: Starts a Hadoop HDFS DataNode | |
# processname: java | |
# | |
### BEGIN INIT INFO | |
# Provides: hadoop-hdfs-datanode | |
# Required-Start: $syslog $remote_fs | |
# Should-Start: | |
# Required-Stop: $syslog $remote_fs | |
# Should-Stop: | |
# Default-Start: 3 4 5 | |
# Default-Stop: 0 1 2 6 | |
# Short-Description: Starts a Hadoop HDFS DataNode | |
### END INIT INFO | |
. /lib/lsb/init-functions | |
[ -f /etc/default/hadoop ] && . /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 | |
[ -f /etc/profile.d/jdk.sh ] && . /etc/profile.d/jdk.sh | |
RETVAL_SUCCESS=0 | |
STATUS_RUNNING=0 | |
STATUS_DEAD=1 | |
STATUS_DEAD_AND_LOCK=2 | |
STATUS_NOT_RUNNING=3 | |
STATUS_DEBIAN_NOT_RUNNING=4 | |
STATUS_OTHER_ERROR=102 | |
ERROR_PROGRAM_NOT_INSTALLED=5 | |
ERROR_PROGRAM_NOT_CONFIGURED=6 | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
NAME="hadoop-hdfs-datanode" | |
DESC="Hadoop HDFS DataNode" | |
SYS_FILE="/etc/default/${NAME}" | |
[ -f ${SYS_FILE} ] && SOURCE=". ${SYS_FILE};" && . ${SYS_FILE} | |
LOG_FILE="${HADOOP_LOG_DIR}/hadoop-hdfs-datanode.log" | |
PKG_USER="hdfs" | |
PKG_HOME="/usr/lib/hadoop" | |
CONF_DIR="${HADOOP_CONF_DIR}" | |
[ -f ${CONF_DIR}/${NAME}-env.sh ] && . ${CONF_DIR}/${NAME}-env.sh | |
PID_FILE="${HADOOP_PID_DIR}/hadoop-hdfs-datanode.pid" | |
EXE_FILE="/usr/lib/hadoop/sbin/hadoop-daemon.sh" | |
EXE_ARGS="--config ${CONF_DIR} start datanode" | |
LOCKFILE="/var/lock/hadoop-hdfs-datanode" | |
NICENESS="+0" | |
TIMEOUT=3 | |
_start() { | |
[ -x ${EXE_FILE} ] || exit ${ERROR_PROGRAM_NOT_INSTALLED} | |
log_success_msg "Starting ${DESC} (${NAME}): " | |
mkdir -p `dirname ${PID_FILE}` `dirname ${LOG_FILE}` | |
chown ${PKG_USER} `dirname ${PID_FILE}` `dirname ${LOG_FILE}` | |
su -s /bin/bash ${PKG_USER} -c "cd ${PKG_HOME}; ${SOURCE} exec nice -n ${NICENESS} ${EXE_FILE} ${EXE_ARGS}& echo \$! > ${PID_FILE}" | |
RETVAL=$? | |
[ ${RETVAL} -eq ${RETVAL_SUCCESS} ] && touch ${LOCKFILE} | |
return ${RETVAL} | |
} | |
_stop() { | |
log_success_msg "Stopping ${DESC} (${NAME}): " | |
killproc -p ${PID_FILE} java | |
RETVAL=$? | |
[ ${RETVAL} -eq ${RETVAL_SUCCESS} ] && rm -f ${LOCKFILE} ${PID_FILE} | |
return ${RETVAL} | |
} | |
_restart() { | |
_stop | |
[ -n "${TIMEOUT}" ] && sleep ${TIMEOUT} | |
_start | |
} | |
_status() { | |
echo -n "Checking for service ${DESC}: " | |
pidofproc -p ${PID_FILE} java > /dev/null | |
RETVAL=$? | |
case ${RETVAL} in | |
${STATUS_RUNNING}) | |
log_success_msg "${NAME} is running" | |
;; | |
${STATUS_DEAD}) | |
log_failure_msg "${NAME} is dead and pid file exists" | |
;; | |
${STATUS_DEAD_AND_LOCK}) | |
log_failure_msg "${NAME} is dead and lock file exists" | |
;; | |
${STATUS_NOT_RUNNING}|${STATUS_DEBIAN_NOT_RUNNING}) | |
log_failure_msg "${NAME} is not running" | |
;; | |
*) | |
log_failure_msg "${NAME} status is unknown" | |
;; | |
esac | |
return ${RETVAL} | |
} | |
RETVAL=0 | |
case ${1} in | |
start) _start ;; | |
stop|force-stop) _stop ;; | |
force-reload|condrestart|try-restart) [ -e $LOCKFILE ] && _restart || : ;; | |
restart|reload) _restart ;; | |
status) _status ;; | |
*) | |
N=/etc/init.d/${NAME} | |
echo "Usage: ${N} {start|stop|restart|reload|condrestart|try-restart|force-reload|status|force-stop}" >&2 | |
RETVAL=1 | |
;; | |
esac | |
exit ${RETVAL} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment