-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathminio.sh
executable file
·122 lines (110 loc) · 3.27 KB
/
minio.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
# min.io script to stand up docker-ized mini.io server on localhost and have the endpoint exposed as http://IP:9000
# will create a minio directory for the data directory.
# find IP
if [ "`uname -s`" != "Darwin" ]; then
IP=`hostname -I | awk '{ print $1 }'`
else
IP=`ifconfig | grep inet | grep -v inet6 | grep -v 127.0.0.1 | awk '{ print $2 }'`
fi
help() {
echo -e "./`basename $0` command"
echo -e "\tCOMMANDS"
echo -e "\t\tbuild - Fresh install - it will build a new minio docker instance named myminio"
echo -e "\t\t\t\tmyminio directory will be created in your homedir"
echo -e "\t\tstart - Start myminio container if stopped"
echo -e "\t\tstop - Stop myminio container"
echo -e "\t\tcleanup - Stops myminio container and delete it and delete ${HOME}/myminio"
}
checkdocker() {
# check to ensure docker is running and you can run docker commands
docker info >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "[DEBUG] Docker is not running or you are not part of the docker group"
exit
fi
}
makehome() {
# check for minio directory and create if there is none.
if [ -f ${HOME}/myminio ]; then
mkdir -p ${HOME}/myminio
echo "Created minio directory"
fi
}
pullminio() {
# checking for image - minio
docker image inspect minio/minio:latest > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "[DEBUG] Pulling minio image.. might take a while"
docker pull minio/minio:latest
else
echo "[DEBUG] Using existing minio image"
fi
}
build() {
makehome
docker run -d -p 9000:9000 \
--user $(id -u):$(id -g) \
--name myminio \
-e "MINIO_ROOT_USER=minio" \
-e "MINIO_ROOT_PASSWORD=minio123" \
-v ${HOME}/myminio:/data \
minio/minio server /data
if [ $? -eq 0 ]; then
echo "[DEBUG] mmyinio started. http://localhost:9000 or http://${IP}:9000. access_key: minio secret_key: minio123"
echo ""
echo "[DEBUG] Please visit https://dl.minio.io/client/mc/release/ and download the mc client for your machine and chmod a+x mc and place it in your path"
echo "[DEBUG] Add myminio server into mc: mc config host add myminio http://127.0.0.1:9000 minio minio123"
echo "[DEBUG] mc commands are located on https://dl.minio.io/client/mc/release/"
echo "[DEBUG] For quick use: Create Bucket: mc mb myminio/bucketname"
echo "[DEBUG] You can use s3cmd as well."
fi
}
start() {
# check to see if container exists and if not build it and start it
if [ "$(docker ps | grep -c myminio)" -eq 1 ]; then
echo "[DEBUG] myminio is already running"
elif [ "$(docker ps -a | grep -c myminio)" -eq 1 ]; then
echo "[DEBUG] myminio found and starting container"
docker start myminio
else
echo "[DEBUG] myminio container doesnt exist. Building"
build
fi
}
stop() {
if [ "$(docker ps | grep myminio)" ]; then
docker stop myminio
echo "[DEBUG] Stopping myminio container"
else
echo "[DEBUG] myminio was not running"
fi
}
cleanup() {
stop
if [ "$(docker ps -aq -f status=exited -f name=myminio)" ]; then
docker rm myminio
fi
rm -rf ${HOME}/myminio
echo "[DEBUG] Deleted ${HOME}/myminio"
}
# modes
case $1 in
build)
checkdocker
build
;;
start)
checkdocker
start
;;
stop)
stop
;;
cleanup)
cleanup
;;
*)
help
;;
esac