免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2700 | 回复: 1
打印 上一主题 下一主题

[Redis] 一个适用于CentOS下的Redis启动脚本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-16 19:21 |只看该作者 |倒序浏览
一个适用于CentOS下的Redis启动脚本








下面是一个Shell脚本,用于管理Redis进程(启动,停止,重启),如果你在使用Redis,这个脚本可供参考。
  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="/usr/local/sbin/redis-server"
  18. prog=$(basename $redis)

  19. REDIS_CONF_FILE="/etc/redis/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
复制代码
来源:https://gist.github.com/257849

论坛徽章:
0
2 [报告]
发表于 2012-02-17 22:36 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP