redis_init_script 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. ### BEGIN INIT INFO
  6. # Provides: redis_6379
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: Redis data structure server
  10. # Description: Redis data structure server. See https://redis.io
  11. ### END INIT INFO
  12. REDISPORT=6379
  13. EXEC=/usr/local/bin/redis-server
  14. CLIEXEC=/usr/local/bin/redis-cli
  15. PIDFILE=/var/run/redis_${REDISPORT}.pid
  16. CONF="/etc/redis/${REDISPORT}.conf"
  17. case "$1" in
  18. start)
  19. if [ -f $PIDFILE ]
  20. then
  21. echo "$PIDFILE exists, process is already running or crashed"
  22. else
  23. echo "Starting Redis server..."
  24. $EXEC $CONF
  25. fi
  26. ;;
  27. stop)
  28. if [ ! -f $PIDFILE ]
  29. then
  30. echo "$PIDFILE does not exist, process is not running"
  31. else
  32. PID=$(cat $PIDFILE)
  33. echo "Stopping ..."
  34. $CLIEXEC -p $REDISPORT shutdown
  35. while [ -x /proc/${PID} ]
  36. do
  37. echo "Waiting for Redis to shutdown ..."
  38. sleep 1
  39. done
  40. echo "Redis stopped"
  41. fi
  42. ;;
  43. *)
  44. echo "Please use start or stop as first argument"
  45. ;;
  46. esac