#!/bin/bash
set -e
#echo "[`date +'%F %H:%M:%S'`] [INFO] useage : sh install_mdd.sh "
pd=$PWD
source /etc/profile
#export JAVA_HOME=$JAVA_HOME
#export PATH=$PATH:$JAVA_HOME/bin
## install mdd ##
if [ -z "$JAVA_HOME" ];then
    echo "jdk not be installed,please install jdk first!"
    exit 1
fi

mkdir -p olapserver && unzip -o olap6.6.2.zip -d olapserver > /dev/null 2>&1
##mkdir -p $pd/olapserver/redo && mkdir -p $pd/olapserver/backup
chmod -R 755 $pd/
chmod +x $pd/olapserver/bin/start.sh

#redo=$pd/olapserver/redo
#redoRe=$pd/olapserver/redoRe

## register systemd ##
cat > /usr/lib/systemd/system/mdd.service <<EOF
[Unit]
Description=mdd
After=syslog.target network.target

[Service]
Type=forking
Environment="JAVA_HOME=$JAVA_HOME"
Environment="PATH=$PATH:$JAVA_HOME/bin"
ExecStart=$pd/olapserver/bin/start.sh start
ExecStop=$pd/olapserver/bin/start.sh stop

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start mdd
systemctl enable mdd

## echo install resault ##
netstat -ntpl|grep 8888
if [ $? -eq 0 ];then
    echo "mdd install susses!"
else
    echo "mdd install failed!"
fi

