linux之redis启动脚本编写v1.0
来源:互联网 发布:linux php不支持mysql 编辑:程序博客网 时间:2024/06/06 23:16
#!/bin/bash
#*****************************************************
# Author: suixiaofeng
# blog:https:
//blog.cool360.org
# Email: 258818040@qq.com
# Last modified: 2017-06-30 19:34
# Filename: redis
# Description:
#****************************************************
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
redis_server=
"/u02/redis/bin/redis-server"
redis_conf=
"/u02/redis/conf/redis.conf"
[ -x /u02/redis/bin/redis-server -a -f /u02/redis/conf/redis.conf ] || {
echo
"redis is not install."
exit
1
}
if
[ $# -ne 1 ]
then
echo
$
"usage:$0 {start|stop|restart|status}"
exit
1
fi
function
start () {
stapro=`netstat -lntup|grep redis |wc -l`
if
[
$stapro
-ne 0 ] ; then
echo
-e
"\033[32mredis is running \033[0m"
exit
2
else
${redis_server} ${redis_conf}
sleep 2
stapro1=`netstat -lntup|grep redis |wc -l`
[
$stapro1
-ne 0 ] &&{
action
"redis is started"
/bin/true
exit
0
}
fi
}
function
stop () {
stopro=`netstat -lntup|grep redis |wc -l`
if
[
$stopro
-eq 0 ] ; then
echo
-e
"\033[32mredis is stopped \033[0m"
exit
2
else
# PID=`ps aux|grep redis|grep -v grep|awk
'{print $2}'
`
# kill -9 ${PID} >/dev/null
killproc redis-server
sleep 2
stopro1=`netstat -lntup|grep redis |wc -l`
[
$stopro1
-eq 0 ] &&{
action
"redis is stopped"
/bin/true
exit
0
}
fi
}
function
status () {
statpro=`netstat -lntup|grep redis |wc -l`
if
[
$statpro
-eq 0 ] ; then
echo
-e
"\033[32mredis is stopped \033[0m "
else
echo
-e
"\033[32mredis is running \033[0m "
fi
exit
0
}
case
$1
in
"start"
)
start
;;
"stop"
)
stop
;;
"restart"
)
stop
start
;;
"status"
)
status
;;
* )
echo
$
"Usage:$0 {start|stop|restart|status}"
exit
4
esac
exit
0
接着把脚本放在/etc/init.d下,赋权 chmod +x /etc/init.d/redis
操作如下:
[root@sf106232 srv]# /etc/init.d/redis status
redis is stopped
[root@sf106232 srv]# /etc/init.d/redis
usage:/etc/init.d/redis {start|stop|restart|status}
[root@sf106232 srv]# /etc/init.d/redis start
redis is started [ OK ]
[root@sf106232 srv]# /etc/init.d/redis status
redis is running
[root@sf106232 srv]# /etc/init.d/redis stop
redis is stopped [ OK ]
[root@sf106232 srv]# /etc/init.d/redis status
redis is stopped
[root@sf106232 srv]#
这个版本为最初的,可以参考标准的去完善。
阅读全文
0 0
- linux之redis启动脚本编写v1.0
- SHELL编写redis启动脚本
- Linux启动脚本编写
- redis安装部署 启动脚本的编写
- 编写linux服务启动脚本
- linux oracle 自启动脚本编写
- JSVC编写自己的Linux启动脚本
- 基于JSVC编写Linux启动脚本
- linux 自己编写脚本,开机自动启动
- linux如何编写自启动shell脚本
- 安全脚本程序的编写 V1.0(2)
- Linux下启动Java程序的启动脚本编写
- Linux脚本编写之sed用法
- Linux下shell之脚本编写基础
- 编写启动脚本
- 编写启动脚本
- 编写自启动脚本
- redis启动脚本
- 2017年年中总结
- 王者荣耀脚本,按键精灵做的,智能脚本,试用也可以
- [noip2010]:导弹拦截
- 关于QML监控系统粘贴板的问题
- 【论文笔记】Learning Deconvolution Network for Semantic Segmentation
- linux之redis启动脚本编写v1.0
- 初识activity工作流
- CC3200-UART-ADC-PWM
- PWA初探
- 关于android studio ndk Error:(115) *** Android NDK: Aborting . Stop.错误
- Linux系统目录结构
- Maven项目pom.xml文件报xxx\target\classes\META-INF\MANIFEST.MF (系统找不到指定的路径)的问题解决
- Spring MVC与JAX-RS比较与分析
- element-ui 表格实现单元格可编辑的方法