-
Notifications
You must be signed in to change notification settings - Fork 1
/
redis_sentinel.init.j2
94 lines (83 loc) · 2.54 KB
/
redis_sentinel.init.j2
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
#
# Redis init script for Debian-based distros
#
#
### BEGIN INIT INFO
# Provides: sentinel_{{ redis_sentinel_port }}
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: $syslog $named
# Should-Stop: $syslog $named
# Short-Description: Start and stop sentinel_{{ redis_sentinel_port }}
# Description: Redis Sentinel monitor
### END INIT INFO
# Source the Linux Standard Base functions
. /lib/lsb/init-functions
SENTINEL_PORT={{ redis_sentinel_port }}
NAME="sentinel_${SENTINEL_PORT}"
DAEMON={{ redis_install_dir }}/bin/redis-server
PIDFILE={{ redis_sentinel_pidfile }}
PIDFILE_DIR=$(dirname "${PIDFILE}")
REDIS_USER={{ redis_user }}
CONF="/etc/redis/sentinel_${SENTINEL_PORT}.conf"
CLIEXEC="{{ redis_install_dir }}/bin/redis-cli -p ${SENTINEL_PORT}"
if [ -r /etc/default/sentinel_${SENTINEL_PORT} ]; then
. /etc/default/sentinel_${SENTINEL_PORT}
fi
if [ -n "$REDIS_PASSWORD" ]; then
CLIEXEC="${CLIEXEC} -a ${REDIS_PASSWORD}"
fi
if [ -n "$BIND_ADDRESS" ]; then
CLIEXEC="${CLIEXEC} -h ${BIND_ADDRESS}"
fi
case "$1" in
start)
if [ -f "$PIDFILE" ]; then
status_of_proc -p "$PIDFILE" $DAEMON "$NAME process" && return 0
fi
if [ -n "$NOFILE_LIMIT" ]; then
ulimit -n $NOFILE_LIMIT
fi
if [ ! -d "$PIDFILE_DIR" ]; then
mkdir "$PIDFILE_DIR"
chown ${REDIS_USER}:${REDIS_USER} "$PIDFILE_DIR"
chmod 0755 "$PIDFILE_DIR"
fi
log_daemon_msg "Starting $NAME..."
if start-stop-daemon --start -q --oknodo -p "$PIDFILE" -c $REDIS_USER --exec $DAEMON -- $CONF --sentinel; then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
if [ -f "$PIDFILE" ]; then
PID=$(cat "$PIDFILE")
log_daemon_msg "Stopping $NAME..."
$CLIEXEC shutdown
while [ -x /proc/${PID} ]; do
log_daemon_msg "Waiting for Redis Sentinel to shutdown ..."
sleep 1
done
log_end_msg 0
else
log_daemon_msg "$NAME is not running"
log_end_msg 0
fi
;;
status)
status_of_proc -p "$PIDFILE" $DAEMON "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|status|restart|force-reload}" >&2
exit 1
;;
esac
exit 0