-
Notifications
You must be signed in to change notification settings - Fork 15
/
dmstart
executable file
·36 lines (29 loc) · 1000 Bytes
/
dmstart
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
#!/usr/bin/env bash
# This is a shell script to start a Docker Machine
# virtual machine, if it is not already running
# Set full path to "docker-machine" command
DMCMD=$(command -v docker-machine)
# Check for presence of the "docker-machine" command
if [[ ! -x $DMCMD ]]; then
echo "Docker Machine does not appear to be installed"
exit 1
fi
# Check for correct parameters (exactly one VM name expected)
if [[ "$#" -ne 1 ]]; then
echo "Incorrect number of parameters; please specify a single VM name"
exit 1
fi
# Set the name of the Docker Machine VM
VM=$1
# Get the current status of the specified Docker Machine VM
# $STATUS will be zero-length if no matching VMs are found
STATUS=$($DMCMD ls | grep "$VM\s" | awk '{print $4}')
# If $STATUS is zero-length, report an error
if [[ -z $STATUS ]]; then
echo "No matching Docker Machine VM found"
exit 1
fi
# Start Docker Machine VM if it is not already running
if [[ $STATUS == 'Stopped' ]]; then
$DMCMD start $VM
fi