文章目录
- 前言
前言
#!/usr/bin/env bash
#可变参数变量#部署磁盘路径
baseDirPath=/data/apps/java/smj-exchange-upload
#jar包名称
packageName=smj-exchange-upload.jar #命令启动包名 xx.jar的xxpid= #进程pid#检测pid
getPid(){echo "检测状态---------------------------------------------"pid=`ps -ef | grep -n ${packageName} | grep -v grep | awk '{print $2}'`if [ ${pid} ]thenecho "运行pid:${pid}"elseecho "未运行"fi
}
#启动程序
function start()
{#启动前,先停止之前的stopif [ ${pid} ]thenecho "停止程序失败,无法启动"elseecho "启动程序---------------------------------------------"#进入运行包目录cd ${baseDirPath}nohup java -jar ${packageName} >/dev/null 2>&1 &# java -jar ${baseDirPath}/${packageName}#查询是否有启动进程getPidif [ ${pid} ]thenecho "已启动"#nohup日志tail -f nohup.outelseecho "启动失败"fifi
}#停止程序
function stop()
{getPidif [ ${pid} ]thenecho "停止程序---------------------------------------------"kill -9 ${pid}getPid
}#停止程序
function stop()
{getPidif [ ${pid} ]thenecho "停止程序---------------------------------------------"kill -9 ${pid}getPidif [ ${pid} ]then#stopecho "停止失败"elseecho "停止成功"fifi
}#启动时带参数,根据参数执行
if [ ${#} -ge 1 ]
thencase ${1} in"start")start;;"restart")start;;"stop")stop;;# "unzip")# #执行解压# shenniu_unzip# #执行启动# start# ;;*)echo "${1}无任何操作";;esac
elseecho "command如下命令:start:启动stop:停止进程restart:重启示例命令如:./upload_start start"
fi
注意:
- 遇到权限不够
执行 chmod u+x ./upload_start.sh
- 没有目录或者文件 是因为Windows格式和Linux格式不一致
执行 vim upload_start.sh 编辑文件
:set ff=unix
:eq
接下来就是见证奇迹的时刻了