Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 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 | |
| 14 | test -f /usr/bin/redis-server || exit 0 |
| 15 | |
| 16 | ARGS="/etc/redis/redis.conf" |
| 17 | |
| 18 | case "$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 |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 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 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 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 | ;; |
| 68 | esac |
| 69 | |
| 70 | exit 0 |
| 71 | |