Skip to content
Snippets Groups Projects
start.sh 1.41 KiB
Newer Older
Robert Martin-Legene's avatar
Robert Martin-Legene committed
#!/bin/bash

trap 'exit 1' ERR

if ! which docker > /dev/null 2>&1
then
Robert Martin-Legene's avatar
Robert Martin-Legene committed
    echo 'Can not find Docker. Make sure it is installed.' >&2
Robert Martin-Legene's avatar
Robert Martin-Legene committed
    exit 1
fi

if [ "$1" = "test" ]
then
    tag="test"
    class="test"
    name="bfanodotest"
    netdir="test2network"
    tag="latest"
    class="prod"
    name="bfanodo"
    netdir="network"
else
    echo Argument 1 must be either latest or test. >&2
    exit 1
mounts=
for guestdir in /home/bfa/bfa/${netdir}/node /home/bfa/bfa/${netdir}/cache
do
    # docker dirs
    d_dirs="${d_dirs} ${guestdir}"
    # guestdirs
    g_dir=${guestdir//\//,}
    g_dirs="${g_dirs} ${g_dir}"
    # hostdirs
Robert Martin-Legene's avatar
Robert Martin-Legene committed
    h_dir=/home/dockers/volumes/${name}${guestdir//\//,}
    h_dirs="${h_dirs} ${h_dir}"
    mkdir -p ${h_dir}
    mounts="${mounts} -v ${h_dir}:${guestdir}"
done

if [ "$UID" = "0" ]
then
    chown -R 30303:30303 ${h_dirs}
else
    # This is a bit slower, but works
    docker run --rm $mounts -u root alpine chown -R 30303:30303 ${d_dirs}
Robert Martin-Legene's avatar
Robert Martin-Legene committed

# Run this just a single time.
# Docker itself makes sure it autostarts if it crashes or the server reboots.
docker run                      \
    --detach                    \
    --restart=unless-stopped    \
    --memory 4g                 \
    $mounts                     \
    -p 8545:8545                \
    -p 8546:8546                \
    -p 30303:30303              \
    --name ${name}              \