| #!/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 an Apache Hama Groom node |
| # |
| # chkconfig: 2345 90 10 |
| # description: Apache Hama Groom node |
| # |
| ### BEGIN INIT INFO |
| # Provides: hama-groom |
| # Required-Start: $remote_fs |
| # Should-Start: |
| # Required-Stop: $remote_fs |
| # Should-Stop: |
| # Default-Start: 2 3 4 5 |
| # Default-Stop: 0 1 6 |
| # Short-Description: Apache Hama Groom node |
| ### END INIT INFO |
| |
| . /lib/lsb/init-functions |
| |
| if [ -f /etc/default/hama ] ; then |
| . /etc/default/hama |
| fi |
| |
| # 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 |
| |
| STATUS_RUNNING=0 |
| STATUS_DEAD=1 |
| STATUS_DEAD_AND_LOCK=2 |
| STATUS_NOT_RUNNING=3 |
| |
| ERROR_PROGRAM_NOT_INSTALLED=5 |
| |
| HAMA_RUN_DIR=/var/run/hama |
| HAMA_LOCK_DIR="/var/lock/subsys/" |
| LOCKFILE="${HAMA_LOCK_DIR}/hama-groom" |
| desc="Apache Hama Groom node" |
| |
| HAMA_USER=hama |
| EXEC_PATH=/usr/bin/hama |
| HAMA_PID_FILE="${HAMA_RUN_DIR}/hama-groom.pid" |
| HAMA_LOG_FILE="${HAMA_LOG_DIR}/hama-groom.log" |
| |
| # These directories may be tmpfs and may or may not exist |
| # depending on the OS (ex: /var/lock/subsys does not exist on debian/ubuntu) |
| for dir in "$HAMA_RUN_DIR" "$HAMA_LOCK_DIR"; do |
| [ -d "${dir}" ] || install -d -m 0755 -o $HAMA_USER -g $HAMA_USER ${dir} |
| done |
| |
| |
| start() { |
| [ -x $exec ] || exit $ERROR_PROGRAM_NOT_INSTALLED |
| |
| checkstatus |
| status=$? |
| if [ "$status" -eq "$STATUS_RUNNING" ]; then |
| exit 0 |
| fi |
| |
| log_success_msg "Starting $desc: " |
| /bin/su -s /bin/bash -c "/bin/bash -c 'echo \$\$ > ${HAMA_PID_FILE} && exec ${EXEC_PATH} groom >>${HAMA_LOG_FILE} 2>&1' &" $HAMA_USER |
| RETVAL=$? |
| [ $RETVAL -eq 0 ] && touch $LOCKFILE |
| return $RETVAL |
| } |
| |
| stop() { |
| if [ ! -e $HAMA_PID_FILE ]; then |
| log_failure_msg "Apache Hama Groom node is not running" |
| exit 0 |
| fi |
| |
| log_success_msg "Stopping $desc: " |
| |
| HAMA_PID=`cat $HAMA_PID_FILE` |
| if [ -n $HAMA_PID ]; then |
| kill -TERM ${HAMA_PID} &>/dev/null |
| sleep 5 |
| kill -KILL ${HAMA_PID} &>/dev/null |
| fi |
| rm -f $LOCKFILE $HAMA_PID_FILE |
| return 0 |
| } |
| |
| restart() { |
| stop |
| start |
| } |
| |
| checkstatus(){ |
| pidofproc -p $HAMA_PID_FILE java > /dev/null |
| status=$? |
| |
| case "$status" in |
| $STATUS_RUNNING) |
| log_success_msg "$desc is running" |
| ;; |
| $STATUS_DEAD) |
| log_failure_msg "$desc is dead and pid file exists" |
| ;; |
| $STATUS_DEAD_AND_LOCK) |
| log_failure_msg "$desc is dead and lock file exists" |
| ;; |
| $STATUS_NOT_RUNNING) |
| log_failure_msg "$desc is not running" |
| ;; |
| *) |
| log_failure_msg "$desc status is unknown" |
| ;; |
| esac |
| return $status |
| } |
| |
| condrestart(){ |
| [ -e ${LOCKFILE} ] && 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|condrestart}" |
| exit 1 |
| esac |
| |
| exit $RETVAL |