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 ...
随机推荐
- jeecg Online表单开发中新增自定义按钮
要求:给表单增加一个“确认”按钮,按钮功能更改选中数据的flag字段为1 点击“自定义按钮”,录入一个“确认”按钮 按钮编码:该编码在一个智能表单配置中唯一,该编码同时是按钮触发的JS函数名.例如:按 ...
- apache httpd.conf alias
参考 Apache alias目录配置 我的环境是 Ubuntu apache2,配置文件目录在 /etc/apache2/sites-available/000-default.conf 在这个配置 ...
- 发现一个新的远程软件 gotohttp
之前直到远程桌面连接是TeamViewer 替换的原因是: 被控制端版本 11.0.x (很久以前安装的),而我本地的Teamviewer是 14.x, 去连接,好像提示被控制端的版本太低:本地使用 ...
- nacos配置服务入门
1.nacos服务端部署 参见官方文档:https://nacos.io/zh-cn/docs/quick-start.html 2.nacos配置中心功能使用 在pol文件中添加依赖: 在启动类中使 ...
- Spring中使用到的设计模式
1.工厂模式:Beanfactory和ApplicationContext 2.单例模式:bean的构建 3.代理模式:AOP 4.模板模式:jdbcTemplate,hibernateTemplat ...
- Python pillow库安装报错
报错信息: D:\pythontest\duanxinhongzha>pip3 install pillowCollecting pillow Could not find a version ...
- 移动端多选插件-jquery
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 牛客多校第九场 J Symmetrical Painting 计算几何/扫描线
题意: 平面上有几个宽度相同的矩形区域被涂黑了,让你找到一条横线横截若干个矩形,把这些黑色部分抠下来一部分使得它们以这条横线为对称轴,求能抠下来的最大面积. 题解: 在随着对称轴上移的过程中,必然有一 ...
- [转]设置修改CentOS系统时区
在我们使用CentOS系统的时候,也许时区经常会出现问题,有时候改完之后还是会出错,下面我们就来学习一种方法来改变这个状况.如果没有安装,而你使用的是 CentOS系统 那使用命令 yum insta ...
- Spring源码由浅入深系列四 创建BeanFactory
继上一章refresh之后,上图描述了obtainFreshBeanFactory过程.