Skip to content

Commit e341abd

Browse files
committed
Automatically kill a master to show how sentinel works.
1 parent ff0b963 commit e341abd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

examples/sentinel/sentinel.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
sentinel monitor master1 127.0.0.1 6380 2
2+
sentinel down-after-milliseconds master1 5000
3+
sentinel failover-timeout master1 15000
4+
sentinel parallel-syncs master1 1
5+
26
sentinel monitor master2 127.0.0.1 6381 2
7+
sentinel down-after-milliseconds master2 5000
8+
sentinel failover-timeout master2 15000
9+
sentinel parallel-syncs master2 1

examples/sentinel/start

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
#! /usr/bin/env ruby
22

3+
# This is a helper script used together with examples/sentinel.rb
4+
# It runs two Redis masters, two slaves for each of them, and two sentinels.
5+
# After 30 seconds, the first master dies.
6+
#
7+
# You don't need to run this script yourself. Rather, use examples/sentinel.rb.
8+
39
require "fileutils"
410

511
$pids = []
612

713
at_exit do
814
$pids.each do |pid|
9-
Process.kill(:INT, pid)
15+
begin
16+
Process.kill(:INT, pid)
17+
rescue Errno::ESRCH
18+
end
1019
end
1120

1221
Process.waitall
@@ -33,4 +42,8 @@ FileUtils.cp(File.join(base, "sentinel.conf"), "tmp/sentinel2.conf")
3342
$pids << spawn("redis-server tmp/sentinel1.conf --sentinel --port 26379")
3443
$pids << spawn("redis-server tmp/sentinel2.conf --sentinel --port 26380")
3544

45+
sleep 30
46+
47+
Process.kill(:KILL, $pids[0])
48+
3649
Process.waitall

0 commit comments

Comments
 (0)