summaryrefslogtreecommitdiff
path: root/community/redis/redis.d
blob: 333f45d6b93c8614befd8ca3881363990700f477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

PID=`cat /var/run/redis.pid 2>/dev/null`
case "$1" in
  start)
    stat_busy "Starting Redis Server"
    [ -d /var/lib/redis ] || { mkdir /var/lib/redis; }
    if [ -z "$PID" ]; then
        /usr/bin/redis-server /etc/redis.conf >/dev/null
        RESULT=$?
    else
        REDIS_PID=`pidof redis-server`
        if [ -z "$REDIS_PID" ]; then
            /usr/bin/redis-server /etc/redis.conf >/dev/null
            RESULT=$?
        elif [ `pidof redis-server` -eq $PID ]; then
            RESULT=1
        else
            /usr/bin/redis-server /etc/redis.conf >/dev/null
            RESULT=$?
        fi
    fi

    if [ $RESULT -gt 0 ]; then
      stat_fail
    else
      add_daemon redis
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping Redis Server"
    [ ! -z "$PID" ]  && kill $PID &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm /var/run/redis.pid
      rm_daemon redis
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac
exit 0