#!/bin/bash

systemctl stop firewalld
systemctl disable firewalld

path=`pwd`

chmod -R 777 $path/jre/

#创建licence文件目录
if [ ! -d $path"/licence" ]; then
  mkdir $path/licence
fi

# start.sh
echo "#!/bin/bash" > $path/start.sh
echo "nohup $path/jre/bin/java -Xms1g -Xmx2g -jar $path/licencemanager-6.0.0-SNAPSHOT.jar --licence.path=$path/licence > $path/licencemanager.log 2>&1 &" >> $path/start.sh

chmod +x $path/start.sh

# # LicenceManager.service
echo "[Unit]" > /usr/lib/systemd/system/LicenceManager.service
echo "Description=Licence.service " >> /usr/lib/systemd/system/LicenceManager.service
echo "[Service]" >> /usr/lib/systemd/system/LicenceManager.service
echo "Type=forking " >> /usr/lib/systemd/system/LicenceManager.service
echo "KillMode=control-group " >> /usr/lib/systemd/system/LicenceManager.service
echo "Restart=on-failure" >> /usr/lib/systemd/system/LicenceManager.service
echo "ExecStart=$path/start.sh" >> /usr/lib/systemd/system/LicenceManager.service
echo "PrivateTmp=true" >> /usr/lib/systemd/system/LicenceManager.service
echo "[Install]" >> /usr/lib/systemd/system/LicenceManager.service
echo "WantedBy=multi-user.target" >> /usr/lib/systemd/system/LicenceManager.service

systemctl daemon-reload

systemctl enable LicenceManager.service
systemctl start LicenceManager.service
