redis_init_script 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. #
  3. # Simple Redis init.d script conceived to work on Linux systems
  4. # as it does use of the /proc filesystem.
  5. REDISPORT=6379
  6. EXEC=/usr/local/bin/redis-server
  7. CLIEXEC=/usr/local/bin/redis-cli
  8. PIDFILE=/var/run/redis_${REDISPORT}.pid
  9. CONF="/etc/redis/${REDISPORT}.conf"
  10. case "$1" in
  11. start)
  12. if [ -f $PIDFILE ]
  13. then
  14. echo "$PIDFILE exists, process is already running or crashed"
  15. else
  16. echo "Starting Redis server..."
  17. $EXEC $CONF
  18. fi
  19. ;;
  20. stop)
  21. if [ ! -f $PIDFILE ]
  22. then
  23. echo "$PIDFILE does not exist, process is not running"
  24. else
  25. PID=$(cat $PIDFILE)
  26. echo "Stopping ..."
  27. $CLIEXEC -p $REDISPORT shutdown
  28. while [ -x /proc/${PID} ]
  29. do
  30. echo "Waiting for Redis to shutdown ..."
  31. sleep 1
  32. done
  33. echo "Redis stopped"
  34. fi
  35. ;;
  36. *)
  37. echo "Please use start or stop as first argument"
  38. ;;
  39. esac