Linux教程

Linux一键部署脚本

本文主要是介绍Linux一键部署脚本,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

前言

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

 

管理jeecg项目

1.启动

#!/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.停止

#!/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

[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

 

这篇关于Linux一键部署脚本的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!