-
Notifications
You must be signed in to change notification settings - Fork 2
/
pharod-start
executable file
·55 lines (41 loc) · 1.57 KB
/
pharod-start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
set -eo pipefail
pharod="$(command -v pharod)"
if [[ -z $pharod ]]; then
echo "pharod not found in \$PATH, please check it's installed properly"
exit 1
fi
if pgrep -qx pharod; then
echo "You can only have one instance of pharod running at one time"
exit 1
fi
if [[ $(docker version --format "{{.Server.KernelVersion}}") == *-moby ]]; then
echo "** Detected Docker for Mac"
DOCKER_HOST_IP="$HOSTNAME.local"
# We have to hard-code this because we have no SSH access to the VM:
DOCKER_FIRST_EPHEMERAL_PORT='32768'
elif command -v dlite >/dev/null; then
echo "** Docker for Mac not installed or not running; trying Dlite"
if ! pgrep -qx dlite; then
echo "dlite not running, please start it with 'dlite start'"
exit 1
fi
echo "** Detected Dlite"
DOCKER_HOST_IP="local.docker"
if ! grep -qw "^$DOCKER_HOST_IP " ~/.ssh/known_hosts; then
ssh-keyscan -t rsa "$DOCKER_HOST_IP" 2>/dev/null >>~/.ssh/known_hosts
fi
if [[ -z $DOCKER_FIRST_EPHEMERAL_PORT ]]; then
# This is what Docker also reads the first port from.
DOCKER_FIRST_EPHEMERAL_PORT="$(ssh docker@$DOCKER_HOST_IP cat /proc/sys/net/ipv4/ip_local_port_range | egrep -o '^\d+')"
fi
elif [[ $(uname -s) == "Darwin" ]]; then
echo "To use Docker in OS X, you need to install Docker for Mac"
echo "or Dlite: https://github.com/nlf/dlite"
exit 1
fi
args=""
if [[ -z $PHAROD_FOREGROUND ]]; then
args="$args -d"
fi
exec sudo sh -c "DOCKER_HOST='unix:///var/run/docker.sock' DOCKER_HOST_IP='$DOCKER_HOST_IP' DOCKER_FIRST_EPHEMERAL_PORT='$DOCKER_FIRST_EPHEMERAL_PORT' '$pharod' $args"