ipfs-cluster/docker/test-entrypoint.sh
ZenGround0 1d81a1fedc Docker test image add cluster respawn (#111)
* First draft of test dockerfile build

* Test dockerfile, build works, container runs and cluster tests go through

* Removed fifo for output

* renaming dockerfile

* Adding functionality for test 12
Added scripts and entrypoint mods to the testing docker image to allow for random shut down and startup
(both SIGSTOP and SIGINT) of the ipfs-cluster-service.

* test docker image ready for tests 12 and 13

* Added cluster daemon respawn
 to docker image
2017-06-29 12:34:00 +02:00

61 lines
1.7 KiB
Bash

#!/bin/sh
set -e
user=ipfs
repo="$IPFS_PATH"
echo "Version 0.4"
if [ `id -u` -eq 0 ]; then
# ensure folders are writeable
su-exec "$user" test -w "$repo" || chown -R -- "$user" "$repo"
su-exec "$user" test -w "$IPFS_CLUSTER_PATH" || chown -R -- "$user" "$IPFS_CLUSTER_PATH"
# restart script with new privileges
exec su-exec "$user" "$0" "$@"
fi
# Second invocation with regular user
echo "Second invocation"
if [ `id -u` -eq 0 ]; then
# ensure directories are writable
su-exec "$user" test -w "$repo" || chown -R -- "$user" "$repo"
su-exec "$user" test -w "$IPFS_CLUSTER_PATH" || chown -R -- "$user" "$IPFS_CLUSTER_PATH"
exec su-exec "$user" "$0" "$@"
fi
ipfs version
if [ -e "$repo/config" ]; then
echo "Found IPFS fs-repo at $repo"
else
ipfs init
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
fi
ipfs daemon --migrate=true &
sleep 3
ipfs-cluster-service --version
if [ -e "$IPFS_CLUSTER_PATH/service.json" ]; then
echo "Found IPFS cluster configuration at $IPFS_CLUSTER_PATH"
else
ipfs-cluster-service init
sed -i 's/127\.0\.0\.1\/tcp\/9094/0.0.0.0\/tcp\/9094/' "$IPFS_CLUSTER_PATH/service.json"
sed -i 's/127\.0\.0\.1\/tcp\/9095/0.0.0.0\/tcp\/9095/' "$IPFS_CLUSTER_PATH/service.json"
fi
ipfs-cluster-service --debug $@ &
# Testing scripts that spawn background processes are spawned and stopped here
/usr/local/bin/random-stopper.sh &
kill -STOP $!
echo $! > /data/ipfs-cluster/random-stopper-pid
/usr/local/bin/random-killer.sh &
kill -STOP $!
echo $! > /data/ipfs-cluster/random-killer-pid
/usr/local/bin/cluster-restart.sh &
kill -STOP $!
echo $! > /data/ipfs-cluster/cluster-restart-pid
echo "Daemons launched"
exec tail -f /dev/null