1#!/bin/sh 2# 3### BEGIN INIT INFO 4# Provides: redis-server 5# Required-Start: $network 6# Required-Stop: $network 7# Default-Start: S 2 3 4 5 8# Default-Stop: 0 1 6 9# Short-Description: Redis, a key-value store 10# Description: Redis is an open source, advanced key-value store. 11# http://redis.io 12### END INIT INFO 13 14test -f /usr/bin/redis-server || exit 0 15 16ARGS="/etc/redis/redis.conf" 17 18case "$1" in 19 start) 20 echo "Starting redis-server..." 21 start-stop-daemon --start --quiet --exec /usr/bin/redis-server -- $ARGS 22 ;; 23 stop) 24 echo "Stopping redis-server..." 25 start-stop-daemon --stop --quiet --exec /usr/bin/redis-server 26 ;; 27 restart) 28 echo "Stopping redis-server..." 29 start-stop-daemon --stop --quiet --exec /usr/bin/redis-server 30 31 # Since busybox implementation ignores --retry arguments repeatedly check 32 # if the process is still running and try another signal after a timeout, 33 # efectively simulating a stop with --retry=TERM/5/KILL/5 schedule. 34 waitAfterTerm=5000000 # us / 5000 ms / 5 s 35 waitAfterKill=5000000 # us / 5000 ms / 5 s 36 waitStep=100000 # us / 100 ms / 0.1 s 37 waited=0 38 start-stop-daemon --stop --test --quiet --exec /usr/bin/redis-server 39 processOff=$? 40 while [ $processOff -eq 0 ] && [ $waited -le $waitAfterTerm ] ; do 41 usleep ${waitStep} 42 ((waited+=${waitStep})) 43 start-stop-daemon --stop --test --quiet --exec /usr/bin/redis-server 44 processOff=$? 45 done 46 if [ $processOff -eq 0 ] ; then 47 start-stop-daemon --stop --signal KILL --exec /usr/bin/redis-server 48 start-stop-daemon --stop --test --quiet --exec /usr/bin/redis-server 49 processOff=$? 50 fi 51 waited=0 52 while [ $processOff -eq 0 ] && [ $waited -le $waitAfterKill ] ; do 53 usleep ${waitStep} 54 ((waited+=${waitStep})) 55 start-stop-daemon --stop --test --quiet --exec /usr/bin/redis-server 56 processOff=$? 57 done 58 # Here $processOff will indicate if waiting and retrying according to 59 # the schedule ended in a successfull stop or not. 60 61 echo "Starting redis-server..." 62 start-stop-daemon --start --quiet --exec /usr/bin/redis-server -- $ARGS 63 ;; 64 *) 65 echo "Usage: /etc/init.d/redis-server {start|stop|restart}" 66 exit 1 67 ;; 68esac 69 70exit 0 71 72