<commit_before>PATH := ./work/redis-git/src:${PATH}
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
STUNNEL_BIN := $(shell which stunnel)
BREW_BIN := $(shell which brew)
YUM_BIN := $(shell which yum)
APT_BIN := $(shell which apt-get)
PROFILE ?= netty-41

define REDIS_CLUSTER_CONFIG1
c2043458aa5646cee429fdd5e3c18220dddf2ce5 127.0.0.1:7380 master - 1434887920102 1434887920002 0 connected 12000-16383
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7379 myself,master - 0 0 1 connected 0-11999
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7382 slave c2043458aa5646cee429fdd5e3c18220dddf2ce5 1434887920102 1434887920002 2 connected
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7381 slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 1434887920102 1434887920002 3 connected
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG2
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7382 slave c2043458aa5646cee429fdd5e3c18220dddf2ce5 1434887920102 1434887920002 2 connected
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7379 master - 1434887920102 1434887920002 1 connected 0-11999
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7381 slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 1434887920102 1434887920002 3 connected
c2043458aa5646cee429fdd5e3c18220dddf2ce5 127.0.0.1:7380 myself,master - 0 0 0 connected 12000-16383
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG3
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7381 myself,slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 0 0 3 connected
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7382 slave c2043458aa5646cee429fdd5e3c18220dddf2ce5 1434887920102 1434887920002 2 connected
c2043458aa5646cee429fdd5e3c18220dddf2ce5 127.0.0.1:7380 master - 1434887920102 1434887920002 0 connected 12000-16383
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7379 master - 1434887920102 1434887920002 1 connected 0-11999
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG4
c2043458aa5646cee429fdd5e3c18220dddf2ce5 127.0.0.1:7380 master - 0 1434887920102 0 connected 12000-16383
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7381 slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 0 1434887920102 3 connected
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7382 myself,slave c2043458aa5646cee429fdd5e3c18220dddf2ce5 0 0 2 connected
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7379 master - 0 1434887920102 1 connected 0-11999
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG8
c2043458aa5646cee429fdd5e3c18220dddf2ce5 127.0.0.1:7580 master - 0 1434887920102 0 connected
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7581 master - 0 1434887920102 3 connected 10001-16384
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7582 myself,master - 0 0 2 connected 0-10000
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7579 master - 0 1434887920102 1 connected
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG_SSL_1
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7479@17479 myself,master - 0 1434887920102 1 connected 0-10000
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7480@17480 slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 0 1434887920102 3 connected
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7481@17481 master  - 0 0 2 connected 10001-16384
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG_SSL_2
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7479@17479 master - 0 1434887920102 1 connected 0-10000
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7480@17480 myself,slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 0 1434887920102 3 connected
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7481@17481 master  - 0 0 2 connected 10001-16384
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG_SSL_3
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7479@17479 master - 0 1434887920102 1 connected 0-10000
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7480@17480 slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 0 1434887920102 3 connected
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7481@17481 myself,master  - 0 0 2 connected 10001-16384
vars currentEpoch 3 lastVoteEpoch 0
endef


#######
# Redis
#######
.PRECIOUS: work/redis-%.conf

# Sentinel monitored slave
work/redis-6483.conf:
	@mkdir -p $(@D)

	@echo port 6483 >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/redis-6483.pid >> $@
	@echo logfile $(shell pwd)/work/redis-6483.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo client-output-buffer-limit pubsub 256k 128k 5 >> $@
	@echo unixsocket $(ROOT_DIR)/work/socket-6483 >> $@
	@echo unixsocketperm 777 >> $@
	@echo slaveof 127.0.0.1 6482 >> $@

work/redis-%.conf:
	@mkdir -p $(@D)

	@echo port $* >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/redis-$*.pid >> $@
	@echo logfile $(shell pwd)/work/redis-$*.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo client-output-buffer-limit pubsub 256k 128k 5 >> $@
	@echo unixsocket $(ROOT_DIR)/work/socket-$* >> $@
	@echo unixsocketperm 777 >> $@

work/redis-%.pid: work/redis-%.conf work/redis-git/src/redis-server
	work/redis-git/src/redis-server $<

redis-start: work/redis-6479.pid work/redis-6480.pid work/redis-6481.pid work/redis-6482.pid work/redis-6483.pid

##########
# Sentinel
##########
.PRECIOUS: work/sentinel-%.conf

work/sentinel-%.conf:
	@mkdir -p $(@D)

	@echo port $* >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/redis-sentinel-$*.pid >> $@
	@echo logfile $(shell pwd)/work/redis-sentinel-$*.log >> $@

	@echo sentinel monitor mymaster 127.0.0.1 6482 1 >> $@
	@echo sentinel down-after-milliseconds mymaster 200 >> $@
	@echo sentinel failover-timeout mymaster 200 >> $@
	@echo sentinel parallel-syncs mymaster 1 >> $@
	@echo unixsocket $(ROOT_DIR)/work/socket-$* >> $@
	@echo unixsocketperm 777 >> $@

work/sentinel-%.pid: work/sentinel-%.conf work/redis-git/src/redis-server
	work/redis-git/src/redis-server $< --sentinel
	sleep 0.5

sentinel-start: work/sentinel-26379.pid work/sentinel-26380.pid

##########
# Cluster
##########
.PRECIOUS: work/cluster-node-%.conf

work/cluster-node-7385.conf:
	@mkdir -p $(@D)

	@echo port 7385 >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/cluster-node-7385.pid >> $@
	@echo logfile $(shell pwd)/work/cluster-node-7385.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo unixsocket $(ROOT_DIR)/work/socket-7385 >> $@
	@echo cluster-enabled yes >> $@
	@echo cluster-node-timeout 150 >> $@
	@echo cluster-config-file $(shell pwd)/work/cluster-node-config-7385.conf >> $@
	@echo requirepass <PASSWORD> >> $@


work/cluster-node-7479.conf:
	@mkdir -p $(@D)

	@echo port 7479 >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/cluster-node-7479.pid >> $@
	@echo logfile $(shell pwd)/work/cluster-node-7479.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo cluster-enabled yes >> $@
	@echo cluster-node-timeout 150 >> $@
	@echo cluster-config-file $(shell pwd)/work/cluster-node-config-7479.conf >> $@
	@echo cluster-announce-port 7443 >> $@
	@echo requirepass <PASSWORD> >> $@


work/cluster-node-7480.conf:
	@mkdir -p $(@D)

	@echo port 7480 >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/cluster-node-7480.pid >> $@
	@echo logfile $(shell pwd)/work/cluster-node-7480.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo cluster-enabled yes >> $@
	@echo cluster-node-timeout 150 >> $@
	@echo cluster-config-file $(shell pwd)/work/cluster-node-config-7480.conf >> $@
	@echo cluster-announce-port 7444 >> $@
	@echo requirepass <PASSWORD> >> $@


work/cluster-node-7481.conf:
	@mkdir -p $(@D)

	@echo port 7481 >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/cluster-node-7481.pid >> $@
	@echo logfile $(shell pwd)/work/cluster-node-7481.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo cluster-enabled yes >> $@
	@echo cluster-node-timeout 150 >> $@
	@echo cluster-config-file $(shell pwd)/work/cluster-node-config-7481.conf >> $@
	@echo cluster-announce-port 7445 >> $@
	@echo requirepass <PASSWORD> >> $@


work/cluster-node-%.conf:
	@mkdir -p $(@D)

	@echo port $* >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/cluster-node-$*.pid >> $@
	@echo logfile $(shell pwd)/work/cluster-node-$*.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo client-output-buffer-limit pubsub 256k 128k 5 >> $@
	@echo unixsocket $(ROOT_DIR)/work/socket-$* >> $@
	@echo cluster-enabled yes >> $@
	@echo cluster-node-timeout 150 >> $@
	@echo cluster-config-file $(shell pwd)/work/cluster-node-config-$*.conf >> $@

work/cluster-node-%.pid: work/cluster-node-%.conf work/redis-git/src/redis-server
	work/redis-git/src/redis-server $<

cluster-start: work/cluster-node-7379.pid work/cluster-node-7380.pid work/cluster-node-7381.pid work/cluster-node-7382.pid work/cluster-node-7383.pid work/cluster-node-7384.pid work/cluster-node-7385.pid work/cluster-node-7479.pid work/cluster-node-7480.pid work/cluster-node-7481.pid work/cluster-node-7582.pid

##########
# stunnel
##########

work/stunnel.conf:
	@mkdir -p $(@D)

	@echo cert=$(ROOT_DIR)/work/ca/certs/foo-host.cert.pem >> $@
	@echo key=$(ROOT_DIR)/work/ca/private/foo-host.decrypted.key.pem >> $@
	@echo capath=$(ROOT_DIR)/work/ca/certs/ca.cert.pem >> $@
	@echo cafile=$(ROOT_DIR)/work/ca/certs/ca.cert.pem >> $@
	@echo delay=yes >> $@
	@echo pid=$(ROOT_DIR)/work/stunnel.pid >> $@
	@echo foreground = no >> $@

	@echo [stunnel] >> $@
	@echo accept = 127.0.0.1:6443 >> $@
	@echo connect = 127.0.0.1:6479 >> $@

	@echo [stunnel-2] >> $@
	@echo accept = 127.0.0.1:6444 >> $@
	@echo connect = 127.0.0.1:6479 >> $@
	@echo cert=$(ROOT_DIR)/work/ca/certs/localhost.cert.pem >> $@
	@echo key=$(ROOT_DIR)/work/ca/private/localhost.decrypted.key.pem >> $@
	@echo capath=$(ROOT_DIR)/work/ca/certs/localhost.cert.pem >> $@
	@echo cafile=$(ROOT_DIR)/work/ca/certs/localhost.cert.pem >> $@

	@echo [ssl-cluster-node-1] >> $@
	@echo accept = 127.0.0.1:7443 >> $@
	@echo connect = 127.0.0.1:7479 >> $@

	@echo [ssl-cluster-node-2] >> $@
	@echo accept = 127.0.0.1:7444 >> $@
	@echo connect = 127.0.0.1:7480 >> $@

	@echo [ssl-cluster-node-3] >> $@
	@echo accept = 127.0.0.1:7445 >> $@
	@echo connect = 127.0.0.1:7481 >> $@

	@echo [stunnel-client-cert] >> $@
	@echo accept = 127.0.0.1:6445 >> $@
	@echo connect = 127.0.0.1:6479 >> $@
	@echo cert=$(ROOT_DIR)/work/ca/certs/localhost.cert.pem >> $@
	@echo key=$(ROOT_DIR)/work/ca/private/localhost.decrypted.key.pem >> $@
	@echo cafile=$(ROOT_DIR)/work/ca/certs/ca.cert.pem >> $@
	@echo verifyChain=yes >> $@
	@echo verify=2 >> $@


work/stunnel.pid: work/stunnel.conf ssl-keys
	which stunnel4 >/dev/null 2>&1 && stunnel4 $(ROOT_DIR)/work/stunnel.conf || stunnel $(ROOT_DIR)/work/stunnel.conf

stunnel-start: work/stunnel.pid

export REDIS_CLUSTER_CONFIG1
export REDIS_CLUSTER_CONFIG2
export REDIS_CLUSTER_CONFIG3
export REDIS_CLUSTER_CONFIG4
export REDIS_CLUSTER_CONFIG8
export REDIS_CLUSTER_CONFIG_SSL_1
export REDIS_CLUSTER_CONFIG_SSL_2
export REDIS_CLUSTER_CONFIG_SSL_3

start: cleanup
	@echo "$$REDIS_CLUSTER_CONFIG1" > work/cluster-node-config-7379.conf
	@echo "$$REDIS_CLUSTER_CONFIG2" > work/cluster-node-config-7380.conf
	@echo "$$REDIS_CLUSTER_CONFIG3" > work/cluster-node-config-7381.conf
	@echo "$$REDIS_CLUSTER_CONFIG4" > work/cluster-node-config-7382.conf
	@echo "$$REDIS_CLUSTER_CONFIG8" > work/cluster-node-config-7582.conf
	@echo "$$REDIS_CLUSTER_CONFIG_SSL_1" > work/cluster-node-config-7479.conf
	@echo "$$REDIS_CLUSTER_CONFIG_SSL_2" > work/cluster-node-config-7480.conf
	@echo "$$REDIS_CLUSTER_CONFIG_SSL_3" > work/cluster-node-config-7481.conf
	$(MAKE) redis-start
	$(MAKE) sentinel-start
	$(MAKE) cluster-start<commit_msg>Remove verifyChain from stunnel config<commit_after>PATH := ./work/redis-git/src:${PATH}
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
STUNNEL_BIN := $(shell which stunnel)
BREW_BIN := $(shell which brew)
YUM_BIN := $(shell which yum)
APT_BIN := $(shell which apt-get)
PROFILE ?= netty-41

define REDIS_CLUSTER_CONFIG1
c2043458aa5646cee429fdd5e3c18220dddf2ce5 127.0.0.1:7380 master - 1434887920102 1434887920002 0 connected 12000-16383
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7379 myself,master - 0 0 1 connected 0-11999
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7382 slave c2043458aa5646cee429fdd5e3c18220dddf2ce5 1434887920102 1434887920002 2 connected
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7381 slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 1434887920102 1434887920002 3 connected
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG2
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7382 slave c2043458aa5646cee429fdd5e3c18220dddf2ce5 1434887920102 1434887920002 2 connected
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7379 master - 1434887920102 1434887920002 1 connected 0-11999
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7381 slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 1434887920102 1434887920002 3 connected
c2043458aa5646cee429fdd5e3c18220dddf2ce5 127.0.0.1:7380 myself,master - 0 0 0 connected 12000-16383
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG3
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7381 myself,slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 0 0 3 connected
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7382 slave c2043458aa5646cee429fdd5e3c18220dddf2ce5 1434887920102 1434887920002 2 connected
c2043458aa5646cee429fdd5e3c18220dddf2ce5 127.0.0.1:7380 master - 1434887920102 1434887920002 0 connected 12000-16383
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7379 master - 1434887920102 1434887920002 1 connected 0-11999
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG4
c2043458aa5646cee429fdd5e3c18220dddf2ce5 127.0.0.1:7380 master - 0 1434887920102 0 connected 12000-16383
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7381 slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 0 1434887920102 3 connected
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7382 myself,slave c2043458aa5646cee429fdd5e3c18220dddf2ce5 0 0 2 connected
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7379 master - 0 1434887920102 1 connected 0-11999
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG8
c2043458aa5646cee429fdd5e3c18220dddf2ce5 127.0.0.1:7580 master - 0 1434887920102 0 connected
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7581 master - 0 1434887920102 3 connected 10001-16384
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7582 myself,master - 0 0 2 connected 0-10000
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7579 master - 0 1434887920102 1 connected
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG_SSL_1
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7479@17479 myself,master - 0 1434887920102 1 connected 0-10000
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7480@17480 slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 0 1434887920102 3 connected
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7481@17481 master  - 0 0 2 connected 10001-16384
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG_SSL_2
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7479@17479 master - 0 1434887920102 1 connected 0-10000
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7480@17480 myself,slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 0 1434887920102 3 connected
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7481@17481 master  - 0 0 2 connected 10001-16384
vars currentEpoch 3 lastVoteEpoch 0
endef

define REDIS_CLUSTER_CONFIG_SSL_3
27f88788f03a86296b7d860152f4ae24ee59c8c9 127.0.0.1:7479@17479 master - 0 1434887920102 1 connected 0-10000
1c541b6daf98719769e6aacf338a7d81f108a180 127.0.0.1:7480@17480 slave 27f88788f03a86296b7d860152f4ae24ee59c8c9 0 1434887920102 3 connected
2c07344ffa94ede5ea57a2367f190af6144c1adb 127.0.0.1:7481@17481 myself,master  - 0 0 2 connected 10001-16384
vars currentEpoch 3 lastVoteEpoch 0
endef


#######
# Redis
#######
.PRECIOUS: work/redis-%.conf

# Sentinel monitored slave
work/redis-6483.conf:
	@mkdir -p $(@D)

	@echo port 6483 >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/redis-6483.pid >> $@
	@echo logfile $(shell pwd)/work/redis-6483.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo client-output-buffer-limit pubsub 256k 128k 5 >> $@
	@echo unixsocket $(ROOT_DIR)/work/socket-6483 >> $@
	@echo unixsocketperm 777 >> $@
	@echo slaveof 127.0.0.1 6482 >> $@

work/redis-%.conf:
	@mkdir -p $(@D)

	@echo port $* >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/redis-$*.pid >> $@
	@echo logfile $(shell pwd)/work/redis-$*.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo client-output-buffer-limit pubsub 256k 128k 5 >> $@
	@echo unixsocket $(ROOT_DIR)/work/socket-$* >> $@
	@echo unixsocketperm 777 >> $@

work/redis-%.pid: work/redis-%.conf work/redis-git/src/redis-server
	work/redis-git/src/redis-server $<

redis-start: work/redis-6479.pid work/redis-6480.pid work/redis-6481.pid work/redis-6482.pid work/redis-6483.pid

##########
# Sentinel
##########
.PRECIOUS: work/sentinel-%.conf

work/sentinel-%.conf:
	@mkdir -p $(@D)

	@echo port $* >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/redis-sentinel-$*.pid >> $@
	@echo logfile $(shell pwd)/work/redis-sentinel-$*.log >> $@

	@echo sentinel monitor mymaster 127.0.0.1 6482 1 >> $@
	@echo sentinel down-after-milliseconds mymaster 200 >> $@
	@echo sentinel failover-timeout mymaster 200 >> $@
	@echo sentinel parallel-syncs mymaster 1 >> $@
	@echo unixsocket $(ROOT_DIR)/work/socket-$* >> $@
	@echo unixsocketperm 777 >> $@

work/sentinel-%.pid: work/sentinel-%.conf work/redis-git/src/redis-server
	work/redis-git/src/redis-server $< --sentinel
	sleep 0.5

sentinel-start: work/sentinel-26379.pid work/sentinel-26380.pid

##########
# Cluster
##########
.PRECIOUS: work/cluster-node-%.conf

work/cluster-node-7385.conf:
	@mkdir -p $(@D)

	@echo port 7385 >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/cluster-node-7385.pid >> $@
	@echo logfile $(shell pwd)/work/cluster-node-7385.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo unixsocket $(ROOT_DIR)/work/socket-7385 >> $@
	@echo cluster-enabled yes >> $@
	@echo cluster-node-timeout 150 >> $@
	@echo cluster-config-file $(shell pwd)/work/cluster-node-config-7385.conf >> $@
	@echo requirepass <PASSWORD> >> $@


work/cluster-node-7479.conf:
	@mkdir -p $(@D)

	@echo port 7479 >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/cluster-node-7479.pid >> $@
	@echo logfile $(shell pwd)/work/cluster-node-7479.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo cluster-enabled yes >> $@
	@echo cluster-node-timeout 150 >> $@
	@echo cluster-config-file $(shell pwd)/work/cluster-node-config-7479.conf >> $@
	@echo cluster-announce-port 7443 >> $@
	@echo requirepass <PASSWORD> >> $@


work/cluster-node-7480.conf:
	@mkdir -p $(@D)

	@echo port 7480 >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/cluster-node-7480.pid >> $@
	@echo logfile $(shell pwd)/work/cluster-node-7480.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo cluster-enabled yes >> $@
	@echo cluster-node-timeout 150 >> $@
	@echo cluster-config-file $(shell pwd)/work/cluster-node-config-7480.conf >> $@
	@echo cluster-announce-port 7444 >> $@
	@echo requirepass <PASSWORD>ared >> $@


work/cluster-node-7481.conf:
	@mkdir -p $(@D)

	@echo port 7481 >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/cluster-node-7481.pid >> $@
	@echo logfile $(shell pwd)/work/cluster-node-7481.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo cluster-enabled yes >> $@
	@echo cluster-node-timeout 150 >> $@
	@echo cluster-config-file $(shell pwd)/work/cluster-node-config-7481.conf >> $@
	@echo cluster-announce-port 7445 >> $@
	@echo requirepass <PASSWORD> >> $@


work/cluster-node-%.conf:
	@mkdir -p $(@D)

	@echo port $* >> $@
	@echo daemonize yes >> $@
	@echo pidfile $(shell pwd)/work/cluster-node-$*.pid >> $@
	@echo logfile $(shell pwd)/work/cluster-node-$*.log >> $@
	@echo save \"\" >> $@
	@echo appendonly no >> $@
	@echo client-output-buffer-limit pubsub 256k 128k 5 >> $@
	@echo unixsocket $(ROOT_DIR)/work/socket-$* >> $@
	@echo cluster-enabled yes >> $@
	@echo cluster-node-timeout 150 >> $@
	@echo cluster-config-file $(shell pwd)/work/cluster-node-config-$*.conf >> $@

work/cluster-node-%.pid: work/cluster-node-%.conf work/redis-git/src/redis-server
	work/redis-git/src/redis-server $<

cluster-start: work/cluster-node-7379.pid work/cluster-node-7380.pid work/cluster-node-7381.pid work/cluster-node-7382.pid work/cluster-node-7383.pid work/cluster-node-7384.pid work/cluster-node-7385.pid work/cluster-node-7479.pid work/cluster-node-7480.pid work/cluster-node-7481.pid work/cluster-node-7582.pid

##########
# stunnel
##########

work/stunnel.conf:
	@mkdir -p $(@D)

	@echo cert=$(ROOT_DIR)/work/ca/certs/foo-host.cert.pem >> $@
	@echo key=$(ROOT_DIR)/work/ca/private/foo-host.decrypted.key.pem >> $@
	@echo capath=$(ROOT_DIR)/work/ca/certs/ca.cert.pem >> $@
	@echo cafile=$(ROOT_DIR)/work/ca/certs/ca.cert.pem >> $@
	@echo delay=yes >> $@
	@echo pid=$(ROOT_DIR)/work/stunnel.pid >> $@
	@echo foreground = no >> $@

	@echo [stunnel] >> $@
	@echo accept = 127.0.0.1:6443 >> $@
	@echo connect = 127.0.0.1:6479 >> $@

	@echo [stunnel-2] >> $@
	@echo accept = 127.0.0.1:6444 >> $@
	@echo connect = 127.0.0.1:6479 >> $@
	@echo cert=$(ROOT_DIR)/work/ca/certs/localhost.cert.pem >> $@
	@echo key=$(ROOT_DIR)/work/ca/private/localhost.decrypted.key.pem >> $@
	@echo capath=$(ROOT_DIR)/work/ca/certs/localhost.cert.pem >> $@
	@echo cafile=$(ROOT_DIR)/work/ca/certs/localhost.cert.pem >> $@

	@echo [ssl-cluster-node-1] >> $@
	@echo accept = 127.0.0.1:7443 >> $@
	@echo connect = 127.0.0.1:7479 >> $@

	@echo [ssl-cluster-node-2] >> $@
	@echo accept = 127.0.0.1:7444 >> $@
	@echo connect = 127.0.0.1:7480 >> $@

	@echo [ssl-cluster-node-3] >> $@
	@echo accept = 127.0.0.1:7445 >> $@
	@echo connect = 127.0.0.1:7481 >> $@

	@echo [stunnel-client-cert] >> $@
	@echo accept = 127.0.0.1:6445 >> $@
	@echo connect = 127.0.0.1:6479 >> $@
	@echo cert=$(ROOT_DIR)/work/ca/certs/localhost.cert.pem >> $@
	@echo key=$(ROOT_DIR)/work/ca/private/localhost.decrypted.key.pem >> $@
	@echo cafile=$(ROOT_DIR)/work/ca/certs/ca.cert.pem >> $@
	@echo verify=2 >> $@


work/stunnel.pid: work/stunnel.conf ssl-keys
	which stunnel4 >/dev/null 2>&1 && stunnel4 $(ROOT_DIR)/work/stunnel.conf || stunnel $(ROOT_DIR)/work/stunnel.conf

stunnel-start: work/stunnel.pid

export REDIS_CLUSTER_CONFIG1
export REDIS_CLUSTER_CONFIG2
export REDIS_CLUSTER_CONFIG3
export REDIS_CLUSTER_CONFIG4
export REDIS_CLUSTER_CONFIG8
export REDIS_CLUSTER_CONFIG_SSL_1
export REDIS_CLUSTER_CONFIG_SSL_2
export REDIS_CLUSTER_CONFIG_SSL_3

start: cleanup
	@echo "$$REDIS_CLUSTER_CONFIG1" > work/cluster-node-config-7379.conf
	@echo "$$REDIS_CLUSTER_CONFIG2" > work/cluster-node-config-7380.conf
	@echo "$$REDIS_CLUSTER_CONFIG3" > work/cluster-node-config-7381.conf
	@echo "$$REDIS_CLUSTER_CONFIG4" > work/cluster-node-config-7382.conf
	@echo "$$REDIS_CLUSTER_CONFIG8" > work/cluster-node-config-7582.conf
	@echo "$$REDIS_CLUSTER_CONFIG_SSL_1" > work/cluster-node-config-7479.conf
	@echo "$$REDIS_CLUSTER_CONFIG_SSL_2" > work/cluster-node-config-7480.conf
	@echo "$$REDIS_CLUSTER_CONFIG_SSL_3" > work/cluster-node-config-7481.conf
	$(MAKE) redis-start
	$(MAKE) sentinel-start
	$(MAKE) cluster-start
{'fraction_non_alphanumeric': 0.15107853050219078, 'fraction_numerical': 0.2019716885743175, 'mean_word_length': 4.916500498504487, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 501, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 86, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3117972', 'n_tokens_mistral': 13023, 'n_tokens_neox': 9995, 'n_words': 1661}