CentOS Redis Auto Restart

Source: Internet
Author: User
Tags redis server

Configuring the Init Script

For CentOS, there is a copy of the https://gist.github.com/1335694

After modification, the following:

  1. ##########################
  2. Path=/usr/local/bin:/sbin:/usr/bin:/bin
  3. redisport=6379
  4. Exec=/usr/local/bin/redis-server
  5. Redis_cli=/usr/local/bin/redis-cli
  6. Pidfile=/var/run/redis.pid
  7. conf="/etc/redis.conf"
  8. Case "$" in
  9. Start
  10. If [-F $PIDFILE]
  11. Then
  12. echo "$PIDFILE exists, process is already running or crashed"
  13. Else
  14. echo "Starting Redis server ..."
  15. $EXEC $CONF
  16. Fi
  17. If ["$?" = "0"]
  18. Then
  19. echo "Redis is running ..."
  20. Fi
  21. ;;
  22. Stop
  23. if [!-F $PIDFILE]
  24. Then
  25. echo "$PIDFILE does not exist, process was not running"
  26. Else
  27. pid=$ (cat $PIDFILE)
  28. echo "Stopping ..."
  29. $REDIS _cli-p $REDISPORT SHUTDOWN
  30. While [-X ${pidfile}]
  31. Do
  32. echo "Waiting for Redis to shutdown ..."
  33. Sleep 1
  34. Done
  35. echo "Redis stopped"
  36. Fi
  37. ;;
  38. Restart|force-reload)
  39. ${0} stop
  40. ${0} start
  41. ;;
  42. *)
  43. echo "Usage:/etc/init.d/redis {start|stop|restart|force-reload}" >&2
  44. Exit 1
  45. Esac
  46. ##############################

Save the above code as Redis and put it under/etc/init.d/

chmod +x/etc/init.d/redis

Actually make service start, also call Redis-server, if want to let it run as daemon in the background, then

Need to modify redis.conf, change daemonize No to daemonize Yes

4, set the boot service

sudo chkconfig redis on

5, start, stop Redis

Service Redis start #或者/etc/init.d/redis start

Service Redis stop #或者/etc/init.d/redis stop

6, Test Redis

      1. Redis-cli
      2. Redis 127.0.0.1:6379> set foo 123
      3. Ok
      4. Redis 127.0.0.1:6379> get foo
      5. "123"
      6. Redis 127.0.0.1:6379> Exit

CentOS Redis Auto Restart

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.