找回密码
 立即注册

只需一扫,快速开始

QQ登录

只需一步,快速开始

搜索
查看: 19375|回复: 0

[技术经验] 分享一个redis管理脚本

[复制链接]

8万

主题

431

回帖

9万

积分

管理员

积分
94396
QQ
发表于 2016-6-2 16:06:02 | 显示全部楼层 |阅读模式
  1. #!/bin/sh
  2. #
  3. # redis - this script starts and stops the redis-server daemon
  4. #
  5. # chkconfig:   - 85 15
  6. # description:  Redis is a persistent key-value database
  7. # processname: redis-server
  8. # config:      /etc/redis/redis.conf
  9. # config:      /etc/sysconfig/redis
  10. # pidfile:     /var/run/redis.pid

  11. # Source function library.
  12. . /etc/rc.d/init.d/functions

  13. # Source networking configuration.
  14. . /etc/sysconfig/network

  15. # Check that networking is up.
  16. [ "$NETWORKING" = "no" ] && exit 0

  17. redis="/home/redis/redis-3.2.0/src/redis-server"
  18. prog=$(basename $redis)

  19. REDIS_CONF_FILE="/home/redis/redis-3.2.0/redis.conf"

  20. [ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis

  21. lockfile=/var/lock/subsys/redis

  22. start() {
  23.     [ -x $redis ] || exit 5
  24.     [ -f $REDIS_CONF_FILE ] || exit 6
  25.     echo -n $"Starting $prog: "
  26.     daemon $redis $REDIS_CONF_FILE
  27.     retval=$?
  28.     echo
  29.     [ $retval -eq 0 ] && touch $lockfile
  30.     return $retval
  31. }

  32. stop() {
  33.     echo -n $"Stopping $prog: "
  34.     killproc $prog -QUIT
  35.     retval=$?
  36.     echo
  37.     [ $retval -eq 0 ] && rm -f $lockfile
  38.     return $retval
  39. }

  40. restart() {
  41.     stop
  42.     start
  43. }

  44. reload() {
  45.     echo -n $"Reloading $prog: "
  46.     killproc $redis -HUP
  47.     RETVAL=$?
  48.     echo
  49. }

  50. force_reload() {
  51.     restart
  52. }

  53. rh_status() {
  54.     status $prog
  55. }

  56. rh_status_q() {
  57.     rh_status >/dev/null 2>&1
  58. }

  59. case "$1" in
  60.     start)
  61.         rh_status_q && exit 0
  62.         $1
  63.         ;;
  64.     stop)
  65.         rh_status_q || exit 0
  66.         $1
  67.         ;;
  68.     restart|configtest)
  69.         $1
  70.         ;;
  71.     reload)
  72.         rh_status_q || exit 7
  73.         $1
  74.         ;;
  75.     force-reload)
  76.         force_reload
  77.         ;;
  78.     status)
  79.         rh_status
  80.         ;;
  81.     condrestart|try-restart)
  82.         rh_status_q || exit 0
  83.             ;;
  84.     *)
  85.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
  86.         exit 2
  87. esac
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册   

本版积分规则

QQ|Archiver|手机版|小黑屋|站秘书 ( 蜀ICP备15034504号-3 )

GMT+8, 2024-5-6 11:58 , Processed in 0.086789 second(s), 40 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表