redis启动管理脚本怎么写

59次阅读
没有评论

共计 1542 个字符,预计需要花费 4 分钟才能阅读完成。

这篇文章主要介绍 redis 启动管理脚本怎么写,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

我是源码安装的 redis-3.0.5

安装路径 /usr/local/redis

编辑创建脚本文件:

vim /etc/init.d/redis

#!/bin/sh
# chkconfig: 2345 85 15 
# description: this script can manager the redis-server daemon
# Redis is a persistent key-value database
# exec: /usr/local/redis/bin/redis-server
# config: /usr/local/redis/conf/redis.conf 
# pidfile: /usr/local/redis/logs/redis.pid 
# datafile: /usr/local/redis/data/redis.rdb 
redis= /usr/local/redis/bin/redis-server 
REDIS_CONF_FILE= /usr/local/redis/conf/redis.conf 
prog=$(basename $redis)
lockfile=/var/lock/subsys/redis
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[  $NETWORKING  =  no  ]   exit 0
 
start() { [ -x $redis ] || exit 5
 [ -f $REDIS_CONF_FILE ] || exit 6
 echo -n $ Starting $prog:  
 daemon $redis $REDIS_CONF_FILE
 retval=$?
 echo
 [ $retval -eq 0 ]   touch $lockfile
 return $retval
stop() {
 echo -n $ Stopping $prog:  
 killproc $prog -QUIT
 retval=$?
 echo
 [ $retval -eq 0 ]   rm -f $lockfile
 return $retval
restart() {
 stop
 start
reload() {
 echo -n $ Reloading $prog:  
 killproc $redis -HUP
 RETVAL=$?
 echo
rh_status() {
 status $prog
rh_status_q() {
 rh_status  /dev/null 2 1
case  $1  in
 start)
 rh_status_q   exit 0
 $1
 ;;
 stop)
 rh_status_q || exit 0
 $1
 ;;
 restart)
 $1
 ;;
 reload)
 rh_status_q || exit 7
 $1
 ;;
 status)
 rh_status
 ;;
 *)
 echo $ Usage: $0 {start|stop|restart|reload|status} 
 exit 2
esac

修改脚本操作权限,添加可执行权限

chmod 755 /etc/init.d/redis

以上是“redis 启动管理脚本怎么写”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注丸趣 TV 行业资讯频道!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-20发表,共计1542字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)