Author: rvs
Date: Tue Nov  1 02:50:39 2011
New Revision: 1195785

URL: http://svn.apache.org/viewvc?rev=1195785&view=rev
Log:
BIGTOP-34. Add Hive server package

Removed:
    incubator/bigtop/trunk/bigtop-packages/src/common/hive/hadoop-hive.sh.suse
Modified:
    incubator/bigtop/trunk/bigtop-packages/src/common/hive/hadoop-hive.sh
    incubator/bigtop/trunk/bigtop-packages/src/deb/hive/service-init.d.tpl
    incubator/bigtop/trunk/bigtop-packages/src/rpm/hive/SPECS/hive.spec

Modified: incubator/bigtop/trunk/bigtop-packages/src/common/hive/hadoop-hive.sh
URL: 
http://svn.apache.org/viewvc/incubator/bigtop/trunk/bigtop-packages/src/common/hive/hadoop-hive.sh?rev=1195785&r1=1195784&r2=1195785&view=diff
==============================================================================
--- incubator/bigtop/trunk/bigtop-packages/src/common/hive/hadoop-hive.sh 
(original)
+++ incubator/bigtop/trunk/bigtop-packages/src/common/hive/hadoop-hive.sh Tue 
Nov  1 02:50:39 2011
@@ -14,22 +14,27 @@
 # 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.
-
-# chkconfig: 2345 90 10
-# description: 
+#
+#
+#
+# Starts a Hive @HIVE_DAEMON@
+#
+# chkconfig: 345 90 10
+# description: Starts a Hive @HIVE_DAEMON@
 # processname: hive
 # pidfile: /var/run/hive/hive-@[email protected]
 ### BEGIN INIT INFO
-# Provides:          hive-@HIVE_DAEMON@
-# Required-Start:    $network $local_fs
-# Required-Stop:
-# Should-Start:      $named
+# Provides:          hadoop-hive-@HIVE_DAEMON@
+# Required-Start:    $syslog $remote_fs
+# Should-Start:
+# Required-Stop:     $syslog $remote_fs
 # Should-Stop:
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: hive
+# Default-Start:     3 4 5
+# Default-Stop:      0 1 2 6
+# Short-Description: Starts a Hive @HIVE_DAEMON@
 ### END INIT INFO
 
+source /lib/lsb/init-functions
 
 # Autodetect JAVA_HOME if not defined
 if [ -e /usr/libexec/bigtop-detect-javahome ]; then
@@ -38,126 +43,92 @@ elif [ -e /usr/lib/bigtop-utils/bigtop-d
   . /usr/lib/bigtop-utils/bigtop-detect-javahome
 fi
 
-# Modelled after $HADOOP_HOME/bin/hadoop-daemon.sh
+RETVAL_SUCCESS=0
+
+STATUS_RUNNING=0
+STATUS_DEAD=1
+STATUS_DEAD_AND_LOCK=2
+STATUS_NOT_RUNNING=3
+
+ERROR_PROGRAM_NOT_INSTALLED=5
+ERROR_PROGRAM_NOT_CONFIGURED=6
 
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 SYS_FILE="/etc/default/hadoop-hive-@HIVE_DAEMON@"
 EXE_FILE="/usr/lib/hive/bin/hive"
 PID_FILE="/var/run/hive/hive-@[email protected]"
+LOCKFILE="/var/lock/subsys/hadoop-hive-@HIVE_DAEMON@"
 LOG_FILE="/var/log/hive/hive-@[email protected]"
 HIVE_USER="hive"
-NICENESS="0"
+HIVE_HOME="`eval echo ~$HIVE_USER`"
+NICENESS="+0"
 NAME="hadoop-hive-@HIVE_DAEMON@"
-DESC="Hive daemon"
- 
-DODTIME=3
-SLAVE_TIMEOUT=300
+DESC="Hive @HIVE_DAEMON@ daemon"
+TIMEOUT=3
 
 [ -f $SYS_FILE ] && . $SYS_FILE
 
-hive_die() {
-    echo "$@"
-    exit 1
-}
-hive_is_process_alive() {
-    local pid="$1"
-    kill -0 $pid > /dev/null 2>&1
-}
-hive_check_pidfile() {
-    local pidfile="$1" # IN
-    local pid
-
-    pid=`cat "$pidfile" 2>/dev/null`
-    if [ "$pid" = '' ]; then
-    # The file probably does not exist or is empty. 
-       return 1
-    fi
-    
-    set -- $pid
-    pid="$1"
-
-    hive_is_process_alive $pid
-}
-hive_process_kill() {
-    local pid="$1"    # IN
-    local signal="$2" # IN
-    local second
-
-    kill -$signal $pid 2>/dev/null
-
-    for second in 0 1 2 3 4 5 6 7 8 9 10; do
-      hive_is_process_alive "$pid" || return 0
-      sleep 1
-    done
-
-    return 1
-}
-hive_stop_pidfile() {
-    local pidfile="$1" # IN
-    local pid
-
-    pid=`cat "$pidfile" 2>/dev/null`
-    if [ "$pid" = '' ]; then
-      # The file probably does not exist or is empty. Success
-       return 0
-    fi
-    
-    set -- $pid
-    pid="$1"
-
-    # First try the easy way
-    if hive_process_kill "$pid" 15; then
-       return 0
-    fi
-
-    # Otherwise try the hard way
-    if hive_process_kill "$pid" 9; then
-       return 0
-    fi
-
-    return 1
-}
-
 hive_start() {
-    if hive_check_pidfile $PID_FILE ; then
-      exit 0
-    fi
+    [ -x $EXE_FILE ] || exit $ERROR_PROGRAM_NOT_INSTALLED
 
     service_name="@HIVE_DAEMON@"
     if [ $service_name = "server" ] ; then
       service_name="hiveserver"
       exec_env="HADOOP_OPTS=\"-Dhive.log.dir=`dirname $LOG_FILE`\""
     fi
-    echo starting $EXE_FILE, logging to $LOG_FILE
-    su -s /bin/sh $HIVE_USER \
-       -c "$exec_env nohup nice -n $NICENESS       \
+
+    log_success_msg "Starting $desc (hadoop-hive-@HIVE_DAEMON@): "
+    start_daemon -u $HIVE_USER -p $PID_FILE -n $NICENESS  /bin/sh -c "cd 
$HIVE_HOME ; $exec_env nohup \
            $EXE_FILE --service $service_name $PORT \
              > $LOG_FILE 2>&1 < /dev/null & "'echo $! '"> $PID_FILE"
-    sleep 3
 
-    hive_check_pidfile $PID_FILE || hive_die "failed to start @HIVE_DAEMON@"
+    RETVAL=$?
+    [ $RETVAL -eq $RETVAL_SUCCESS ] && touch $LOCKFILE
+    return $RETVAL
 }
+
 hive_stop() {
-    if [ -f $PID_FILE ]; then
-      hive_stop_pidfile $PID_FILE || hive_die "failed to stop metastore"
-      rm $PID_FILE  
-    fi
+    log_success_msg "Stopping $desc (hadoop-hive-@HIVE_DAEMON@): "
+    killproc -p $PID_FILE java
+    RETVAL=$?
+
+    [ $RETVAL -eq $RETVAL_SUCCESS ] && rm -f $LOCKFILE $PID_FILE
+    return $RETVAL
 }
+
 hive_restart() {
     hive_stop
-    [ -n "$DODTIME" ] && sleep $DODTIME
+    [ -n "$TIMEOUT" ] && sleep $TIMEOUT
     hive_start
 }
+
 hive_status() {
-    echo -n "$NAME is "
-    if hive_check_pidfile $PID_FILE ;  then
-     echo "running"
-    else
-     echo "not running"
-     exit 1
-    fi
+    echo -n "Checking for service $desc: "
+    pidofproc -p $PID_FILE java > /dev/null
+    status=$?
+
+    case "$status" in
+      $STATUS_RUNNING)
+        log_success_msg "@HADOOP_DAEMON@ is running"
+        ;;
+      $STATUS_DEAD)
+        log_failure_msg "@HADOOP_DAEMON@ is dead and pid file exists"
+        ;;
+      $STATUS_DEAD_AND_LOCK)
+        log_failure_msg "@HADOOP_DAEMON@ is dead and lock file exists"
+        ;;
+      $STATUS_NOT_RUNNING)
+        log_failure_msg "@HADOOP_DAEMON@ is not running"
+        ;;
+      *)
+        log_failure_msg "@HADOOP_DAEMON@ status is unknown"
+        ;;
+    esac
+    return $status
 }
 
+RETVAL=0
+
 case "$1" in
     start)
       hive_start
@@ -168,7 +139,7 @@ case "$1" in
       ;; 
 
     force-reload|condrestart|try-restart)
-      hive_check_pidfile $PID_FILE && hive_restart
+      [ -e $LOCKFILE ] && hive_restart || :
       ;;
 
     restart|reload)
@@ -186,3 +157,5 @@ case "$1" in
        exit 1
        ;;
 esac
+
+exit $RETVAL

Modified: incubator/bigtop/trunk/bigtop-packages/src/deb/hive/service-init.d.tpl
URL: 
http://svn.apache.org/viewvc/incubator/bigtop/trunk/bigtop-packages/src/deb/hive/service-init.d.tpl?rev=1195785&r1=1195784&r2=1195785&view=diff
==============================================================================
--- incubator/bigtop/trunk/bigtop-packages/src/deb/hive/service-init.d.tpl 
(original)
+++ incubator/bigtop/trunk/bigtop-packages/src/deb/hive/service-init.d.tpl Tue 
Nov  1 02:50:39 2011
@@ -23,139 +23,120 @@
 #    by Ian Murdock <[email protected]>.
 #               Further changes by Javier Fernandez-Sanguino <[email protected]>
 #
-# Version:  @(#)skeleton  1.9  26-Feb-2001  [email protected]
+# Starts a Hive @HIVE_DAEMON@
+#
+# chkconfig: 345 85 15
+# description: Starts a Hive @HIVE_DAEMON@
+# processname: hive
 #
 ### BEGIN INIT INFO
-# Provides:          hive-@HIVE_DAEMON@
-# Required-Start:    $network $local_fs $remote_fs
-# Required-Stop:     $remote_fs
-# Should-Start:      $named
+# Provides:          hadoop-hive-@HIVE_DAEMON@
+# Required-Start:    $syslog $remote_fs
+# Should-Start:
+# Required-Stop:     $syslog $remote_fs
 # Should-Stop:
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: hive
+# Default-Start:     3 4 5
+# Default-Stop:      0 1 2 6
+# Short-Description: Starts a Hive @HIVE_DAEMON@
 ### END INIT INFO
 
-# Modelled after $HADOOP_HOME/bin/hadoop-daemon.sh
+source /lib/lsb/init-functions
+
+# 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
+
+RETVAL_SUCCESS=0
+
+STATUS_RUNNING=0
+STATUS_DEAD=1
+STATUS_DEAD_AND_LOCK=2
+STATUS_NOT_RUNNING=3
+STATUS_DEBIAN_NOT_RUNNING=4
+
+ERROR_PROGRAM_NOT_INSTALLED=5
+ERROR_PROGRAM_NOT_CONFIGURED=6
 
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 SYS_FILE="/etc/default/hadoop-hive-@HIVE_DAEMON@"
 EXE_FILE="/usr/lib/hive/bin/hive"
 PID_FILE="/var/run/hive/hive-@[email protected]"
+LOCKFILE="/var/lock/subsys/hadoop-hive-@HIVE_DAEMON@"
 LOG_FILE="/var/log/hive/hive-@[email protected]"
 HIVE_USER="hive"
-NICENESS="0"
+HIVE_HOME="`eval echo ~$HIVE_USER`"
+NICENESS="+0"
 NAME="hadoop-hive-@HIVE_DAEMON@"
-DESC="Hive daemon"
- 
-DODTIME=3
-SLAVE_TIMEOUT=300
+DESC="Hive @HIVE_DAEMON@ daemon"
+TIMEOUT=3
 
 [ -f $SYS_FILE ] && . $SYS_FILE
 
-hive_die() {
-    echo "$@"
-    exit 1
-}
-hive_is_process_alive() {
-    local pid="$1"
-    kill -0 $pid > /dev/null 2>&1
-}
-hive_check_pidfile() {
-    local pidfile="$1" # IN
-    local pid
-
-    pid=`cat "$pidfile" 2>/dev/null`
-    if [ "$pid" = '' ]; then
-    # The file probably does not exist or is empty. 
-       return 1
-    fi
-    
-    set -- $pid
-    pid="$1"
-
-    hive_is_process_alive $pid
-}
-hive_process_kill() {
-    local pid="$1"    # IN
-    local signal="$2" # IN
-    local second
-
-    kill -$signal $pid 2>/dev/null
-
-    for second in 0 1 2 3 4 5 6 7 8 9 10; do
-      hive_is_process_alive "$pid" || return 0
-      sleep 1
-    done
-
-    return 1
-}
-hive_stop_pidfile() {
-    local pidfile="$1" # IN
-    local pid
-
-    pid=`cat "$pidfile" 2>/dev/null`
-    if [ "$pid" = '' ]; then
-      # The file probably does not exist or is empty. Success
-       return 0
-    fi
-    
-    set -- $pid
-    pid="$1"
-
-    # First try the easy way
-    if hive_process_kill "$pid" 15; then
-       return 0
-    fi
-
-    # Otherwise try the hard way
-    if hive_process_kill "$pid" 9; then
-       return 0
-    fi
-
-    return 1
-}
-
 hive_start() {
-    if hive_check_pidfile $PID_FILE ; then
-      exit 0
-    fi
+    [ -x $EXE_FILE ] || exit $ERROR_PROGRAM_NOT_INSTALLED
 
     service_name="@HIVE_DAEMON@"
     if [ $service_name = "server" ] ; then
       service_name="hiveserver"
       exec_env="HADOOP_OPTS=\"-Dhive.log.dir=`dirname $LOG_FILE`\""
     fi
-    echo starting $EXE_FILE, logging to $LOG_FILE
-    su -s /bin/sh $HIVE_USER \
-       -c "$exec_env nohup nice -n $NICENESS       \
-           $EXE_FILE --service $service_name $PORT \
-             > $LOG_FILE 2>&1 < /dev/null & "'echo $! '"> $PID_FILE"
-    sleep 3
 
-    hive_check_pidfile $PID_FILE || hive_die "failed to start @HIVE_DAEMON@"
+    log_success_msg "Starting $desc (hadoop-hive-@HIVE_DAEMON@): "
+    /sbin/start-stop-daemon --quiet --oknodo --start --user $HIVE_USER --name 
java --background \
+       --chuid $HIVE_USER --nicelevel $NICENESS --chdir $HIVE_HOME \
+       --make-pidfile --pidfile $PID_FILE --startas /bin/sh -- \
+       -c "$exec_env exec $EXE_FILE --service $service_name $PORT > $LOG_FILE 
2>&1 < /dev/null"
+
+    RETVAL=$?
+    [ $RETVAL -eq $RETVAL_SUCCESS ] && touch $LOCKFILE
+    return $RETVAL
 }
+
 hive_stop() {
-    if [ -f $PID_FILE ]; then
-      hive_stop_pidfile $PID_FILE || hive_die "failed to stop metastore"
-      rm $PID_FILE  
-    fi
+    log_success_msg "Stopping $desc (hadoop-hive-@HIVE_DAEMON@): "
+    killproc -p $PID_FILE java
+    RETVAL=$?
+
+    [ $RETVAL -eq $RETVAL_SUCCESS ] && rm -f $LOCKFILE $PID_FILE
+    return $RETVAL
 }
+
 hive_restart() {
     hive_stop
-    [ -n "$DODTIME" ] && sleep $DODTIME
+    [ -n "$TIMEOUT" ] && sleep $TIMEOUT
     hive_start
 }
+
 hive_status() {
-    echo -n "$NAME is "
-    if hive_check_pidfile $PID_FILE ;  then
-     echo "running"
-    else
-     echo "not running"
-     exit 1
-    fi
+    echo -n "Checking for service $desc: "
+    pidofproc -p $PID_FILE java > /dev/null
+    status=$?
+
+    case "$status" in
+      $STATUS_RUNNING)
+        log_success_msg "@HADOOP_DAEMON@ is running"
+        ;;
+      $STATUS_DEAD)
+        log_failure_msg "@HADOOP_DAEMON@ is dead and pid file exists"
+        ;;
+      $STATUS_DEAD_AND_LOCK)
+        log_failure_msg "@HADOOP_DAEMON@ is dead and lock file exists"
+        ;;
+      $STATUS_NOT_RUNNING|$STATUS_DEBIAN_NOT_RUNNING)
+        log_failure_msg "@HADOOP_DAEMON@ is not running"
+        ;;
+      *)
+        log_failure_msg "@HADOOP_DAEMON@ status is unknown"
+        ;;
+    esac
+    return $status
 }
 
+RETVAL=0
+
 case "$1" in
     start)
       hive_start
@@ -166,7 +147,7 @@ case "$1" in
       ;; 
 
     force-reload|condrestart|try-restart)
-      hive_check_pidfile $PID_FILE && hive_restart
+      [ -e $LOCKFILE ] && hive_restart || :
       ;;
 
     restart|reload)
@@ -179,8 +160,10 @@ case "$1" in
 
     *)
        N=/etc/init.d/$NAME
-        echo "Usage: $N 
{start|stop|restart|reload|condrestart|try-restart|force-reload|status|force-stop}"
 >&2
+       echo "Usage: $N 
{start|stop|restart|reload|condrestart|try-restart|force-reload|status|force-stop}"
 >&2
 
        exit 1
        ;;
 esac
+
+exit $RETVAL

Modified: incubator/bigtop/trunk/bigtop-packages/src/rpm/hive/SPECS/hive.spec
URL: 
http://svn.apache.org/viewvc/incubator/bigtop/trunk/bigtop-packages/src/rpm/hive/SPECS/hive.spec?rev=1195785&r1=1195784&r2=1195785&view=diff
==============================================================================
--- incubator/bigtop/trunk/bigtop-packages/src/rpm/hive/SPECS/hive.spec 
(original)
+++ incubator/bigtop/trunk/bigtop-packages/src/rpm/hive/SPECS/hive.spec Tue Nov 
 1 02:50:39 2011
@@ -65,11 +65,10 @@ Source0: hive-%{hive_base_version}.tar.g
 Source1: do-component-build
 Source2: install_hive.sh
 Source3: hadoop-hive.sh
-Source4: hadoop-hive.sh.suse
+Source4: hive-site.xml
 Source5: hadoop-hive-server.default
 Source6: hadoop-hive-metastore.default
 Source7: hive.1
-Source8: hive-site.xml
 Requires: hadoop >= 0.20.2, bigtop-utils
 Obsoletes: %{name}-webinterface
 
@@ -137,16 +136,10 @@ cp $RPM_SOURCE_DIR/hive-site.xml .
 %__install -m 0644 $RPM_SOURCE_DIR/hadoop-hive-metastore.default 
$RPM_BUILD_ROOT/etc/default/hadoop-hive-metastore
 %__install -m 0644 $RPM_SOURCE_DIR/hadoop-hive-server.default 
$RPM_BUILD_ROOT/etc/default/hadoop-hive-server
 
-%if  %{?suse_version:1}0
-orig_init_file=$RPM_SOURCE_DIR/hadoop-hive.sh.suse
-%else
-orig_init_file=$RPM_SOURCE_DIR/hadoop-hive.sh
-%endif
-
 for service in %{hive_services}
 do
         init_file=$RPM_BUILD_ROOT/%{initd_dir}/%{name}-${service}
-        %__cp $orig_init_file $init_file
+        %__cp $RPM_SOURCE_DIR/hadoop-hive.sh $init_file
         %__sed -i -e "s|@HIVE_DAEMON@|${service}|" $init_file
         chmod 755 $init_file
 done


Reply via email to