#!/bin/bash

set -e

cd $AUTOPKGTEST_TMP
redis_tmp=$AUTOPKGTEST_TMP/redis-tmp
mkdir $redis_tmp

find tests/redis-configurations -print -name '*.conf' -exec \
	sed -ir "s@\([\" ]\)/tmp/@\1${redis_tmp}/@g" {} +
sed -i "s@dir \".\"@dir \"${redis_tmp}\"@" \
	tests/redis-configurations/sentinel/redis-sentinel.conf

redis-server tests/redis-configurations/basic.conf
redis-server tests/redis-configurations/cluster/redis-0.conf
redis-server tests/redis-configurations/cluster/redis-1.conf
redis-server tests/redis-configurations/cluster/redis-2.conf
redis-server tests/redis-configurations/cluster/redis-3.conf
redis-server tests/redis-configurations/cluster/redis-4.conf
redis-server tests/redis-configurations/cluster/redis-5.conf
redis-server tests/redis-configurations/passwd.conf
redis-server tests/redis-configurations/sentinel/redis-master.conf
redis-server tests/redis-configurations/sentinel/redis-sentinel.conf --sentinel
redis-server tests/redis-configurations/sentinel/redis-slave.conf
redis-server tests/redis-configurations/unixdomainsocket.conf

echo "yes" | redis-cli --cluster create --cluster-replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

memcached -u nobody -d -p 22122 -P $redis_tmp/limits.memcached.1.pid
memcached -u nobody -d -p 22123 -P $redis_tmp/limits.memcached.2.pid
memcached -u nobody -d -s /tmp/limits.memcached.sock -P $redis_tmp/limits.memcached.uds.pid
