Linux一键部署脚本

前言

通过systemctl/shell脚本一键启动和停止各种服务,提升软件交付效率。

 

管理jeecg项目

1.启动

Linux一键部署脚本
#!/bin/bash
export JAVA_HOME="/mingde/jdk"
export PATH=$JAVA_HOME/bin:$PATH
ServiceName=$1
if [ ! -n "$ServiceName" ]; then
echo "##################请输入要启动的服务名称##################" && exit 0
else
echo "###################正在启动${ServiceName}服务################################"
fi
CMD_PATH="/mingde/${ServiceName}"

if [[ ! -d "$CMD_PATH" ]]; then
rm -rf echo "##############${CMD_PATH}不存在############" && exit 0
else
cd $CMD_PATH/
fi
chmod 755 ${CMD_PATH}/${ServiceName}.jar
nohup java -jar ${CMD_PATH}/${ServiceName}.jar &
echo $! > $CMD_PATH/logs/${ServiceName}.pid
startProject.sh

 

2.停止

Linux一键部署脚本
#!/bin/bash
set -e
ServiceName=$1
if [ ! -n "$ServiceName" ]; then
echo "##################请输入要停止的服务名称################" && exit 0
else
echo "###################正在停止${ServiceName}服务################################"
fi
CMD_PATH="/mingde/${ServiceName}"
if [[ ! -d "$CMD_PATH" ]]; then
rm -rf echo "##############${CMD_PATH}不存在############" && exit 0
else cd $CMD_PATH/
fi

PID=$(cat $CMD_PATH/logs/${ServiceName}.pid)
if [ ! -n "$PID" ]; then
echo "#####PID为空#####" && exit 0
else
echo "当前PID为${PID}"
fi
kill -9 $PID || echo "#############PID为${PID}的进程已经关闭############"
rm -f nohup.out
stopProject.sh

 

3.systemd

Linux一键部署脚本
[Unit]
Description=######神华项目######
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME="/mingde/jdk"
ExecStart=/mingde/conf/startProject.sh "shenhua"
ExecStop=/mingde/conf/stopProject.sh "shenhua"
#ExecReload=/mingde/conf/restartProject.sh "shenhua"
PrivateTmp=true

User=root
Group=root

[Install]
WantedBy=multi-user.targe
shenhua.service

 

上一篇:PHP常用字符串函数


下一篇:【bat批处理脚本命令】bat脚本命令的基本使用(保姆级图文+实现代码)