-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminion
executable file
·102 lines (87 loc) · 2.21 KB
/
minion
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
#!/bin/bash
DOCKER_IMAGE_NAME="splunk/splunk"
DOCKER_IMAGE_TAG="latest"
CONTAINER_NAME="docker-splunk-nrql-minion"
SPLUNK_APP_NAME="newrelic_nrql_command_for_splunk"
SPLUNK_USERNAME="admin"
SPLUNK_PASSWORD="password"
help() {
echo "usage: minion [option]"
echo " minion help"
echo " minion run [TAG]"
echo " minion start | stop | restart"
echo " minion status"
echo " minion splunk [command]"
echo " minion shell | bash"
echo " minion exec [command]"
echo " minion remove | rm"
echo " minion rmi [TAG]"
}
run() {
if [[ $1 != "" ]]; then
DOCKER_IMAGE_TAG=$1
fi
docker run -d --name ${CONTAINER_NAME} \
-p 8000:8000 -p 8089:8089 -p 9997:9997 \
-v `pwd`/${SPLUNK_APP_NAME}:/opt/splunk/etc/apps/${SPLUNK_APP_NAME}:rw \
-e 'SPLUNK_START_ARGS=--accept-license' \
-e 'SPLUNK_PASSWORD='${SPLUNK_PASSWORD} \
${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}
}
setup() {
splunk edit user ${SPLUNK_USERNAME} -defaultApp ${SPLUNK_APP_NAME}
}
splunk() {
if [[ $# == 0 ]]; then
docker exec -u splunk -it ${CONTAINER_NAME} \
/opt/splunk/bin/splunk help
elif [[ $1 =~ ^(start|stop|restart)$ ]]; then
echo "Cannot Execute: splunk $1"
else
docker exec -u splunk -it ${CONTAINER_NAME} \
/opt/splunk/bin/splunk login -auth ${SPLUNK_USERNAME}:${SPLUNK_PASSWORD}
docker exec -u splunk -it ${CONTAINER_NAME} \
/opt/splunk/bin/splunk $*
fi
}
exec() {
docker exec -u splunk -it ${CONTAINER_NAME} $*
}
shell() {
docker exec -u splunk -it ${CONTAINER_NAME} /bin/bash
}
logs() {
docker logs $* ${CONTAINER_NAME}
}
status() {
splunk status
}
start() {
docker start ${CONTAINER_NAME}
}
stop() {
docker stop ${CONTAINER_NAME}
}
restart() {
stop
start
}
remove() {
docker rm -fv ${CONTAINER_NAME}
}
rmi() {
if [[ $1 != "" ]]; then
DOCKER_IMAGE_TAG=$1
fi
docker rmi ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}
}
if [[ $1 =~ ^(run|setup|splunk|status|start|stop|restart|exec|logs|rmi|help)$ ]]; then
"$@"
elif [[ $1 =~ ^(shell|bash|sh)$ ]]; then
shell
elif [[ $1 =~ ^(remove|rm)$ ]]; then
remove
else
help
exit 1
fi