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 ...
随机推荐
- 笔记54 Mybatis快速入门(五)
Mybatis中注解的使用 1.XML方式的CRUD 新增加接口CategoryMapper ,并在接口中声明的方法上,加上注解对比配置文件Category.xml,其实就是把SQL语句从XML挪到了 ...
- word embedding 精要整理
word embedding 具体含义:词的实数向量化表示,可以通过向量相似性度量语义相似性,相似性原理是上下文的一致性 Embedding在数学上表示一个maping, f: X -> Y, ...
- LoadRunner模拟REST接口的json请求
LoadRunner模拟REST接口的json请求 现在很多手机应用的性能测试,REST接口调用通过json格式,在用loadrunner模拟这些json请求时,需要开发提供 1.供接口地址 2.提交 ...
- 关于使用vue-router的嵌套路由的命名路由时踩的坑
今天在做我的模仿微博项目时,我想实现点击router-link后,跳转到微博正文页面,并渲染其嵌套视图-评论组件.但是在实际实现时,我发现页面可以正常跳转,但是在页面加载后,并不渲染该页面的嵌套视图, ...
- 2018-2019-2-20175323 java实验五 网络编程与安全
20175323 java实验五 网络编程与安全 任务一 ①编写MyBC.java实现中缀表达式转后缀表达式的功能 ②编写MyDC.java实现从上面功能中获取的表达式中实现后缀表达式求值的功能 基本 ...
- POJ3241 最小曼哈顿距离生成树 - 真有趣哇
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 原题目描述在最下面. 给你n个坐标, ...
- spring-helloworld (1)
目录 一.eclipse安装springsource-tools插件 二.新建maven工程,引入spring配置 三.添加helloworld类 四.使用springsource-tools插件 创 ...
- CodeForces-1221A-2048 Game-思维题
You are playing a variation of game 2048. Initially you have a multiset ss of nn integers. Every int ...
- Jmeter---参数化之用户参数
总结: 参数化几次就要设置几个线程,执行的时候,是按顺序执行,下面的请求也会跟着请求
- 添加ASP.NET AJAX控件工具集到VS2010的方法
在VS2010中Ajax控件只有5个,其实还有很多支持AJAX特定功能的服务器控件,微软是将这些控件当作开放源代码项目.所以没有集成到VS2010中.这些AJAX控件被称为ASP.NET AJAX控件 ...