Search code examples
javalinuxhadoophiveredhat

What is the proper way to stop hiveserver2?


I've installed hive 0.14 on top of hadoop 2.6.0.

The setup mainly involved just extracting the tar.bin file.

I followed this guide to do the setup.

http://www.ishaanguliani.com/content/hive-0140-setup-ubuntu

I start hiveserver2 with a command line:

( $HIVE_HOME/bin/hiveserver2 &> hiveserver.log & )

Now, I am wondering what is the proper to stop hiveserver2. I can kill it but I doubt that provides a graceful exit.


Solution

  • write a small shell script to find hiveserver2 process and stop it. I used below shell script to stop hiveserver2 and hive metastore process. Hope this helps.

    hive2_pid=`pgrep -f org.apache.hive.service.server.HiveServer2`
    
        if [[ -n "$hive2_pid" ]]
        then
            echo "Found hivesevrer2 PID-- "$hive2_pid
            kill $hive2_pid
            # if process is still around, use kill -9
            if ps -p $hive2_pid > /dev/null ; then
                echo "Initial kill failed, killing with -9 "
                kill -9 $hive2_pid
            fi
        echo "Hive server2 stopped successfully"
        else
            echo "Hiveserver2 process not found , HIveserver2 is not running !!!"
        fi
    
        meta_pid=`pgrep -f org.apache.hadoop.hive.metastore.HiveMetaStore`
    
        if [[ -n "$meta_pid" ]]
        then
            echo "Found hivesevrer2 PID-- "$meta_pid
            kill $meta_pid
            # if process is still around, use kill -9
            if ps -p $meta_pid > /dev/null ; then
                echo "Initial kill failed, killing with -9 "
                kill -9 $meta_pid
            fi
        echo "Hive metastore stopped successfully"
        else
            echo "Hive metastore process not found , Hive metastore is not running !!!"
        fi