forked from kamermans/docker-openmanage
-
Notifications
You must be signed in to change notification settings - Fork 1
/
openmanage.sh
executable file
·102 lines (90 loc) · 2.48 KB
/
openmanage.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
#!/bin/sh -e
usage() {
cat << EOF
OpenManage Server Administrator in a Docker Container
Usage: ./$(basename $0) <start|stop|restart|status|update> [snmp_community] [snmp_trap_dest]
snmp_community The SNMP community string to use (default: public)
snmp_trap_dest The SNMP trap destination - this is normally the IP
or hostname to the OpenManage Essentials server
(default: 192.168.0.1)
Note that OpenManage Server Administrator will still work without
either arguments, but will not be detected by OpenManage Essentials.
EOF
exit 1
}
start() {
case "$(status)" in
Running)
echo "Error: Container '$CONTAINER_NAME' is already running"
exit 1
;;
Stopped)
echo "Removing stopped container"
docker rm -fv "$CONTAINER_NAME"
;;
esac
docker run -d \
--name="$CONTAINER_NAME" \
--privileged \
--net="host" \
-v /lib/modules/$(uname -r):/lib/modules/$(uname -r) \
-e "SNMP_COMMUNITY=$SNMP_COMMUNITY" \
-e "SNMP_TRAP_DEST=$SNMP_TRAP_DEST" \
$DOCKER_IMAGE
}
stop() {
case "$(status)" in
Running)
echo "Stopping container"
docker stop "$CONTAINER_NAME"
echo "Removing stopped container"
docker rm -fv "$CONTAINER_NAME"
exit 1
;;
Stopped)
echo "Removing stopped container"
docker rm -fv "$CONTAINER_NAME"
;;
*)
echo "Container is already stopped"
;;
esac
}
status() {
STATUS=$(docker inspect --format='{{ .State.Running }}' "$CONTAINER_NAME" 2>/dev/null || echo "Nonexistent")
echo $STATUS | sed -e 's/true/Running/' -e 's/false/Stopped/g'
}
update() {
echo "Updating openmanage.sh"
curl -sSL https://raw.githubusercontent.com/kamermans/docker-openmanage/master/openmanage.sh > $0
echo "Updating Docker image $DOCKER_IMAGE"
docker pull "$DOCKER_IMAGE"
}
if [ "$#" -eq 0 ] || [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ]; then
usage
fi
ACTION="$1"
SNMP_COMMUNITY=${2:-"public"}
SNMP_TRAP_DEST=${3:-"192.168.0.1"}
CONTAINER_NAME="openmanage"
DOCKER_IMAGE="kamermans/docker-openmanage"
case "$ACTION" in
start)
start
;;
stop)
stop
;;
restart)
stop && start
;;
status)
status
;;
update)
update
;;
*)
usage
;;
esac