By Default, HiveServer2 and HiveMetastore does not have configuration for HeapDump on OOM. Production clusters have OOM and since the HeapDump on OOM is not configured, root cause analysis of the issue is obstructed.
The script seems wrong. With this configuration, the lines for "hiveserver2" will never be valid. The settings in the previous lines "export HADOOP_CLIENT_OPTS=" will overwirte them all with the "$HADOOP_CLIENT_OPTS" at the end. The name of ErrorFile will become "hive-metastore-error.log-`date +'%Y%m%d%H%M'" for example. The script should be:
if [ "$SERVICE" = "metastore" ]; then .... elif [ "$SERVICE" = "hiveserver2" ]; then .... fi