#!/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/functionsredis_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
1fifunction
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
4esacexit
0 |
接着把脚本放在/etc/init.d下,赋权 chmod +x /etc/init.d/redis
操作如下:
[root@sf106232 srv]# /etc/init.d/redis statusredis 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 startredis is started [ OK ][root@sf106232 srv]# /etc/init.d/redis statusredis is running
[root@sf106232 srv]# /etc/init.d/redis stopredis is stopped [ OK ][root@sf106232 srv]# /etc/init.d/redis statusredis is stopped
[root@sf106232 srv]#
|
这个版本为最初的,可以参考标准的去完善。

2010

被折叠的 条评论
为什么被折叠?



