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
|
#! /usr/bin/env ruby
# frozen_string_literal: true
# This is a helper script used together with examples/sentinel.rb
# It runs two Redis masters, two slaves for each of them, and two sentinels.
# After 30 seconds, the first master dies.
#
# You don't need to run this script yourself. Rather, use examples/sentinel.rb.
require "fileutils"
pids = []
at_exit do
pids.each do |pid|
Process.kill(:INT, pid)
rescue Errno::ESRCH
end
Process.waitall
end
base = __dir__
# Masters
pids << spawn("redis-server --port 6380 --loglevel warning")
pids << spawn("redis-server --port 6381 --loglevel warning")
# Slaves of Master 1
pids << spawn("redis-server --port 63800 --slaveof 127.0.0.1 6380 --loglevel warning")
pids << spawn("redis-server --port 63801 --slaveof 127.0.0.1 6380 --loglevel warning")
# Slaves of Master 2
pids << spawn("redis-server --port 63810 --slaveof 127.0.0.1 6381 --loglevel warning")
pids << spawn("redis-server --port 63811 --slaveof 127.0.0.1 6381 --loglevel warning")
FileUtils.cp(File.join(base, "sentinel.conf"), "tmp/sentinel1.conf")
FileUtils.cp(File.join(base, "sentinel.conf"), "tmp/sentinel2.conf")
# Sentinels
pids << spawn("redis-server tmp/sentinel1.conf --sentinel --port 26379")
pids << spawn("redis-server tmp/sentinel2.conf --sentinel --port 26380")
sleep 30
Process.kill(:KILL, pids[0])
Process.waitall
|