shell启停服务脚本模板
一、 启动脚本模板:符合幂等性
如果该服务已经启动,再次调用该脚本,不会报错,也就是说可以反复多次调用,另外启动成功返回 一个参数,提供给自动发布平台校验该服务是否启动
#!/bin/bash
instancename=
# check is instance running
PID=`ps -ef | $instancename | grep -v grep `
if [ ! -z "$PID" ]; then
echo "instance $instancename is running."
exit 0
fi # start instance
# TODO: start cmd # chenk whether instance be running by url or key word in logfile,choose one or check url
url=
loop=60
count=0
while $count < 60
do
curl $url && exit 0
sleep 1
count=$(($count + 1))
done
if [ $count -ge 60 ];then
echo "[ERROR]: Timeout ,failed."
exit 1
fi
echo "[INFO]: Instance $instancename started." # or check key word in logfile
keyword= xxx
logfile=
orgLineNum=`wc -1 $logfile | cut -d " " -f1`
loop=60
count=0
while $count < 60
do
endLineNum=`wc -1 $logfile | cut -d " " -f1`
deltaLine=$(($endLineNum - $orgLineNum))
tail -n $deltaLine $logfile | sed /$keyword/ && break
$orgLineNum=$endLineNum
sleep 1
done
if [ $count -ge 60 ];then
echo "[ERROR]: Timeout , failed."
exit 1
fi
echo "[INFO]: Instance $instancename started."
二、停止脚本,符合幂等性
可以重复调用
#!/bin/bash
instancename=
#check is instance running
PID=`ps -ef | grep $instancename | grep -v grep `
if [ -z "$PID" ];then
echo "instance $instancename is not running."
exit 0
fi # stop instance
# TODO : stop cmd # if stop cmd failed ,may kill or exit with error #or kill
PID=`ps -ef | grep $instancename | grep -v grep `
if [ ! -z "$PID" ];then
echo "stop cmd failed , try to kill."
kill $PID
fi # if kill failed ,may kill -9
if [ ! -z "$PID" ];then
echo "kill process failed, try to kill -9."
kill -9 $PID
fi # or exit with error
PID=`ps -ef | grep $instancename | grep -v grep `
if [ ! -z "$PID" ];then
echo "stop cmd failed."
exit 1
fi
shell启停服务脚本模板的更多相关文章
- 编写Redis启停服务脚本
脚本内容如下; fi esac exit$RETVAL 下载脚本:艺搜下载 将下载下来的脚本放在/etc/init.d/目录下 更改脚本权限 chmod 777 /etc/init.d/red ...
- 编写Nginx启停服务脚本
在/etc/init.d/目录下创建脚本 vim /etc/init.d/nginx 编写脚本内容:(其中下面2行需要根据情况自行修改) nginxd=/opt/nginx/sbin/nginx ng ...
- shell编程之服务脚本编写,文件锁以及信号捕获
shell脚本编程是linux运维工程师必备的技能,也是非常重要的一个技能,所以把shell编程学好,只有好处.基础语法我也就不讲了,学过C语言这些语言的,稍微看一下就能明白shell编程的基础,所以 ...
- Redis windows版本的启停bat脚本命令
Reids windows版本安装 redis windows官网推荐:https://github.com/MicrosoftArchive/redis/releases 下载解压即可. 启停bat ...
- MySQL - 启停服务
Windows 环境 命令行方式 启动 MySQL 服务: net start mysql停止 MySQL 服务: net stop mysql 注:需要以管理员身份启动 cmd 后再执行上述命令. ...
- 04. 启停redis服务
启动 查看redis.conf文件,可以通过general中的说明,配置通过systemd来启停redis和查看redis状态(作者没有采用,而是使用service管理,service配置参考< ...
- redis安装、配置、启停
Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and ...
- liunx weblogic服务启停脚本
#!/bin/bash #sh xx.sh start xx项目 例如:sh autoWeblogic.sh start bius #经测试发现weblogic 启动大概需要完全启动成功35秒左右 停 ...
- nginx启停脚本
安装nginx时,源码包中未带官方的启动脚本,也就无法使用service nginxd start这种启动方式,查了下资料自己写了一个: #!/bin/bash #@version: #@author ...
随机推荐
- Android开发 MediaPlayer播放本地视频完善的demo(只是代码记录)
xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.w ...
- 尝试让Virtualbox的Ubuntu可以调整分辨率
在Virtualbox安装的Ubuntu,默认不是全屏,操作起来不是很方便,网上查了资料,按照网上的教程来操作并记录下自己的操作记录. 在安装的Ubuntu的虚拟机,通过 "设备" ...
- ubuntu 16.04 pecl 不能安裝 mcrypt
vagrant@ubuntu-xenial:/etc/apt$ sudo pecl install mcrypt-1.0.1 downloading mcrypt-1.0.1.tgz ... Star ...
- CSIC_716_20191204【网络编程 OSI 七层结构】
软件开发架构 C/S架构: Client: 客户端 Server: 服务端 比如: 微信客户端.QQ客户端等... 优点: - 软件的使用稳定 - 节省网络资源 缺点: - 安装麻烦,用户体验差 - ...
- delphi xe10 获取屏幕截图
//截取屏幕图片 function MakeScaleScreenshot(Sender: TControl): TBitmap; function GetScreenScale: Single; v ...
- 59 cuda 不同版本__half冲突问题 —— "__half" has no member "x"
0 引言 深度学习中常常用到half类型的半精度浮点数,但是cpu本身是不支持half的,因此需要进行转换. 1 half - float转换 参考了某博主的github,链接如下. https:// ...
- 今天工作整整一个月了,来记录一下(web前端)
25号,工作整整一个月了,时光飞逝, 这一个月以来,无论是工作上还是生活上,都让我成长了很多,也多了些对人生的思考… 先回顾一下找工作的那段时间吧年前找工作有多辛酸,年后找工作就有多幸运那段日子,我这 ...
- 绘制窗体渐变背景的函数[delphi]
绘制窗体渐变背景的函数,三个参数分别代表起始颜色,终止颜色,绘制方向procedure TForm1.Draw(StartColor:TColor;EndColor:TColor;Direction: ...
- 暴力”注入Explorer
暴力"注入Explorer pjf(jfpan20000@sina.com) 向一个运行中的进程注入自己的代码,最自然莫过于使用Cr ...
- Flex birdeye笔记
1.将官网示例demo运行起来 新建Flex项目,直接将官网src下的demo拷贝到新建的项目的src下 .将官网example-binaries目录下的文件拷贝到新建项目的bin-debug下即可 ...