-
Notifications
You must be signed in to change notification settings - Fork 0
/
container
executable file
·144 lines (130 loc) · 5.32 KB
/
container
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
set -e
export WORKDIR=$(cd $(dirname $0) && pwd)
. "$WORKDIR/common"
cli_help() {
cli_name=${0##*/}
echo "
Fork Service
Version: $(cat $WORKDIR/VERSION)
Usage: $cli_name [service] [operation]
Commands:
./container rabbitmq start Starts rabbitmq container
#Example
./container rabbitmq start
./container rabbitmq stop Stops rabbitmq container
#Example
./container rabbitmq stop
./container redis start Starts redis container
#Example
./container redis start
./container redis stop Stops redis container
#Example
./container redis stop
./container redis-cli start Starts redis-cli container
#Example
./container redis-cli start
./container elastic-search start Starts elastic search container
#Example
./container elastic-search start
./container elastic-search stop Stops elastic-search container
#Example
./container elastic-search stop
./container kibana start Starts kibana container
#Example
./container kibana start
./container kibana stop Stops kibana container
#Example
./container kibana stop
./container help Help
"
exit 1
}
cli_log "Exporting environment variables..."
export $(cat "$WORKDIR/env" | xargs)
service=$(echo "$1" | tr '[:upper:]' '[:lower:]')
operation=$(echo "$2" | tr '[:upper:]' '[:lower:]')
case "$service" in
rabbitmq)
case "$operation" in
start)
cli_log "Starting RabbitMQ Service"
docker run -d --hostname rabbitmq --name rabbitmq -p 5672:5672 rabbitmq:$RABBITMQ_VERSION
docker run -d --hostname rabbitmq --name rabbitmq-management -p 15672:15672 rabbitmq:$RABBITMQ_MANAGEMENT_VERSION
;;
stop)
cli_log "Stopping RabbitMQ Service"
docker rm --force rabbitmq
docker rm --force rabbitmq-management
;;
*)
cli_help "Invalid operation provided. Use either one of these: start, stop"
;;
esac
;;
redis)
case "$operation" in
start)
cli_log "Starting Redis Service"
docker run -d --name redis --mount source=$REDIS_VOLUME_NAME,target=/data -p 6379:6379 redis:$REDIS_VERSION --appendonly yes
;;
stop)
cli_log "Stopping Redis Service"
docker rm --force redis
delete_volume $REDIS_VOLUME_NAME $REDIS_PERSIST_VOLUME
;;
*)
cli_help "Invalid operation provided. Use either one of these: start, stop"
;;
esac
;;
redis-cli)
case "$operation" in
start)
cli_log "Starting Redis CLI Service"
[ ! "$(docker ps -a | grep redis)" ] && ./container redis start
docker exec -it redis redis-cli
;;
*)
cli_help "Invalid operation provided. Use either one of these: start, stop"
;;
esac
;;
elastic-search)
case "$operation" in
start)
cli_log "Starting Elastic Search Service"
config=$(echo $(cat $(pwd)/config/elastic-search.config))
sudo sysctl -w vm.max_map_count=262144
docker run -d --name elastic-search $config --env-file $(pwd)/config/elastic-search.env docker.elastic.co/elasticsearch/elasticsearch:$ELASTICSEARCH_VERSION
;;
stop)
cli_log "Stopping Elastic Search Service"
docker rm --force elastic-search
sudo sysctl -w vm.max_map_count=65530
;;
*)
cli_help "Invalid operation provided. Use either one of these: start, stop"
;;
esac
;;
kibana)
case "$operation" in
start)
cli_log "Starting Kibana Service"
elasticSearchHost=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' elastic-search)
docker run -d --name kibana --link elastic-search --env ELASTICSEARCH_HOSTS=http://$elasticSearchHost:9200 -p 5601:5601 docker.elastic.co/kibana/kibana:$KIBANA_VERSION
;;
stop)
cli_log "Stopping Kibana Service"
docker rm --force kibana
;;
*)
cli_help "Invalid operation provided. Use either one of these: start, stop"
;;
esac
;;
help|h)
cli_help
;;
esac