Created
November 28, 2019 17:11
-
-
Save LnL7/baac41ce71336fefca46d08d19f063fb to your computer and use it in GitHub Desktop.
redis server setup-hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ makeSetupHook, redis }: | |
makeSetupHook { deps = [ redis ]; } ./setup-hook.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} }: | |
let | |
redisHook = pkgs.callPackage ./. {}; | |
in | |
stdenv.mkDerivation { | |
name = "redis-hook-test"; | |
buildInputs = [ redisHook ]; | |
unpackPhase = ":"; | |
doCheck = true; | |
checkPhase = '' | |
redis-cli -p $redisPort ping | |
''; | |
installPhase = '' | |
touch $out | |
''; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare -a backgroundPids | |
killPhase() { | |
echo "killing background jobs..." >&2 | |
kill "${backgroundPids[@]}" || kill -9 "${backgroundPids[@]}" | |
wait "${backgroundPids[@]}" | |
} | |
postPhases+=" killPhase" | |
redisPhase() { | |
runHook preRedis | |
redisPort=$(shuf -i 2000-65000 -n 1) | |
mkdir $NIX_BUILD_TOP/redis | |
cat <<-EOF > $NIX_BUILD_TOP/redis/redis.conf | |
port $redisPort | |
bind 127.0.0.1 | |
dir $NIX_BUILD_TOP/redis | |
EOF | |
echo "starting redis on port $redisPort..." >&2 | |
redis-server $NIX_BUILD_TOP/redis/redis.conf & | |
backgroundPids+=("$!") | |
runHook postRedis | |
} | |
prePhases+=" redisPhase" | |
exitHook() { | |
runHook killPhase | |
} | |
failureHook() { | |
runHook killPhase | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment