forked from TritonDataCenter/sdc-agents-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·131 lines (110 loc) · 2.92 KB
/
install.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
123
124
125
126
127
128
129
130
131
#!/bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#
# Copyright (c) 2015, Joyent, Inc.
#
set -e
set -o xtrace
TMP=/var/tmp
AGENTS="$(ls *.tgz *.tar.gz *.tar.bz2 || /bin/true)"
AGENTS_DIR=/opt/smartdc/agents
export PATH="$PATH:$AGENTS_DIR/bin"
export PATH=$AGENTS_DIR/modules/.npm/agents_core/active/package/local/bin:$PATH
message() {
echo "==> $*" >&2
}
agents-install() {
WHAT=$1
$INSTALLER install "$WHAT"
}
rm-agent-dirs() {
for dir in $(ls "$AGENTS_DIR"); do
case "$dir" in
db|smf)
continue
;;
*)
rm -fr $AGENTS_DIR/$dir
;;
esac
done
}
cleanup-lime() {
message "Upgrading agents from Lime-era release."
TOREMOVE="$(agents-npm --no-registry ls installed | grep -v '^atropos@') atropos"
for agent in "$TOREMOVE"; do
log "Attempting to uninstall $agent"
agents-npm uninstall $agent;
done
rm-agent-dirs
}
cleanup-npm-agents() {
message "Updating existing agents install."
TOREMOVE="$(agents-npm --no-registry ls installed | awk '{ print $1 }')"
for agent in "$TOREMOVE"; do
if (echo "$agent" | grep '^atropos@'); then
continue
fi
agents-npm uninstall $agent;
done
rm-agent-dirs
}
cleanup-apm() {
# no_rabbit is now the best rabbit (AGENT-950)
message "Removing agents from rabbit era."
if [[ -d /opt/smartdc/agents/lib/node_modules/provisioner ]]; then
${AGENTS_DIR}/bin/apm uninstall provisioner
fi
if [[ -d /opt/smartdc/agents/lib/node_modules/heartbeater ]]; then
${AGENTS_DIR}/bin/apm uninstall heartbeater
fi
}
cleanup-existing() {
if [ -f "$AGENTS_DIR/bin/agents-npm" ] && agents-npm --no-registry ls atropos | grep 'installed'; then
cleanup-lime
elif [ -f "$AGENTS_DIR/bin/agents-npm" ]; then
cleanup-npm-agents
elif [ -f "$AGENTS_DIR/bin/apm" ]; then
cleanup-apm
fi
}
bootstrap() {
# Run the bootstrap script
if [ ! -f $AGENTS_DIR/bin/agents-npm ] || $AGENTS_DIR/bin/agents-npm --no-registry ls agents_core | awk '{ print $1 }' | grep 'installed'; then
# Install the actual atropos agent
tar -zxvf agents_core-*.tgz
(cd agents_core && ./bootstrap/bootstrap.sh "$AGENTS_DIR")
fi
}
install-agents() {
# Install the agents locally
for tarball in $AGENTS; do
case "$tarball" in
agents_core-*.tgz)
;;
*)
agents-install "./$tarball"
;;
esac
done
}
restart-cn-agents() {
svcadm restart cn-agent
}
# The 6.5 upgrade agent shar does not contain the agents_core-* tarball
if [ -z "`ls agents_core-*.tgz 2>/dev/null`" ]; then
# This is the installer for the 6.5 upgrade agents
INSTALLER=agents-npm
else
INSTALLER=apm
cleanup-existing
bootstrap
fi
install-agents
# restart cn-agent to force an update of installed agent versions
restart-cn-agents
exit 0