forked from amonapp/amon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller
271 lines (209 loc) · 6.83 KB
/
installer
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/env bash
# The one-line installer for Amon Lite
# Author: Martin Rusev <[email protected]>
set -e
file_exists() {
[ -f "$1" ]
}
command_exists() {
type "$1" &> /dev/null ;
}
function die(){
echo $1
exit 1
}
ARCH=
DISTRO=
UBUNTU=0
VERSION=1.1
PYTHON=python
VERBOSE=0
# Debian based distros - Tested and supported on : Debian, Ubuntu
if file_exists /etc/debian_version ; then
DISTRO='debian'
# RPM based distros - Tested and supported on : Fedora, CentOS, Amazon Linux AMI
elif file_exists /etc/redhat-release ; then
DISTRO='rpm'
elif file_exists /etc/system-release ; then
DISTRO='rpm'
else
echo "Your operating system is not supported at the moment"
exit
fi
if file_exists "/etc/lsb-release"; then
if cat /etc/lsb-release | grep 'buntu' >> /dev/null; then
UBUNTU=1
fi
fi
# Check if it is 32 or 64 bit machine
MACHINE_TYPE=`uname -m`
if [ "$MACHINE_TYPE" == 'i686' ]; then
# 32-bit
ARCH='32bit'
else
# 64-bit
ARCH='64bit'
fi
# Set variables for the installation
#set -e # Exit the installer on error
mongo_check=$(ps aux | grep -c mongo) # Check if mongo is running
bash_script_dir="$( cd "$( dirname "$0" )" && pwd )"
amon_install_dir="/usr/local/amonlite"
echo "*** Installing Amon Lite $VERSION ..."
# Install easy_install if necessary
if ! command_exists easy_install ; then
wget "http://peak.telecommunity.com/dist/ez_setup.py"
sudo $PYTHON ez_setup.py
rm -f ez_setup.py
fi
# Install Amon Lite
# Cleans up the directory from old amon installations
rm -rf amonlite-* # Cleans up old archives from previous installs, that could break the updating process
wget --no-check-certificate "https://github.com/downloads/martinrusev/amonlite/amonlite-$VERSION.tar.gz"
tar -zxf "amonlite-$VERSION.tar.gz" > /dev/null
if [ "$DISTRO" == 'debian' ]; then
# Ensure that we have the pymongo driver dependecies
# Skip installing python and gcc if they are already installed.
if dpkg-query -s python-dev gcc sysstat >> /dev/null ; then
echo "*** Amon Lite requirements already satisfied"
else
echo "** Installing Amon Lite requirements"
sudo apt-get -y install gcc python-dev sysstat
fi
if dpkg-query -W python-dev gcc sysstat ; then
echo "** success!"
fi
elif [ "$DISTRO" == 'rpm' ]; then
if rpm --quiet -q gcc python-devel sysstat ; then
echo "*** Amon Lite requirements already satisfied"
else
echo "** Installing Amon Lite requirements"
sudo yum -t -y install gcc python-devel sysstat
fi
if rpm --quiet -q gcc python-devel sysstat ; then
echo "** success!"
fi
fi
cd "amonlite"
sudo $PYTHON setup.py install # Install Amon and all the dependecies
$PYTHON generate_config.py || die # Generate the configuration file
# Copy the generated configuration file from the current directory
# If Amon was previously installed, the generator will just a secret_key
sudo cp amonlite.conf /etc/amonlite.conf
# Copy the collector daemon
sudo cp contrib/amond /etc/init.d/amond
# make the collector daemon executable
sudo chmod +x /etc/init.d/amond
# Add the collector daemon to the startup list
if [ "$DISTRO" == 'debian' ]; then
sudo update-rc.d amond defaults > /dev/null
elif [ "$DISTRO" == 'rpm' ]; then
sudo chkconfig --add amond > /dev/null
sudo chkconfig amond on
fi
# Copy the web application daemon
sudo cp contrib/amonlite /etc/init.d/amonlite
# make the web app daemon executable
sudo chmod +x /etc/init.d/amonlite
# Copy the ZeroMQ daemon
sudo cp contrib/amonmq /etc/init.d/amonmq
# make the ZeroMQ daemon executable
sudo chmod +x /etc/init.d/amonmq
# Create a directory for the log files
sudo mkdir -p "$amon_install_dir"
cd "$bash_script_dir"
# Install MongoDB
install_mongodb() {
if [ "$DISTRO" == 'debian' ]; then
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
if ! file_exists "/etc/apt/sources.list.d/10gen.list"; then
if [ "$UBUNTU" == 1 ]; then
cat <<EOL > 10gen.list
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
EOL
else # debian
cat <<EOL > 10gen.list
deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen
EOL
fi # is_ubuntu END
sudo cp 10gen.list /etc/apt/sources.list.d/10gen.list
sudo apt-get update
fi # file exists
sudo apt-get install mongodb-10gen
fi # DISTRO = debian
if [ "$DISTRO" == 'rpm' ]; then
if ! file_exists "/etc/yum.repos.d/10gen.repo"; then
if [ "$ARCH" == '64bit' ]; then
cat <<EOL > 10gen.repo
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
enabled=1
EOL
# 32 bit
else
cat <<EOL > 10gen.repo
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0
enabled=1
EOL
fi # ARCH END
sudo cp 10gen.repo /etc/yum.repos.d/10gen.repo
fi # file exists
yum install mongo-10gen mongo-10gen-server
chkconfig mongod on
fi # DISTRO = rpm
}
#Start Mongo
start_mongodb()
{
sudo /etc/init.d/mongodb start
if [ "$DISTRO" == 'rpm' ]; then
sudo service mongod start
else
sudo /etc/init.d/mongodb start
fi
sleep 5 # Wait for Mongo to write the journal files
}
echo ""
# Install MongoDB if it is not installed on the system
if ! command_exists mongo ; then
# Check one more time, the value should be 1
if [ $mongo_check = '1' ]; then
install_mongodb
configure_mongodb
start_mongodb
fi
fi
# Show a message about where to go for help.
print_troubleshooting_instructions() {
echo
echo "For troubleshooting instructions, please see the Amon User Guide :"
echo "http://amon.cx/guide/"
echo
echo "To uninstall Amon, \`curl uninstall.amon.cx | bash\`"
}
# All done!
CHECK_AMOND=$(pgrep amond)
# The amond process doesn't exist
if [[ -z "$CHECK_AMOND" ]]; then
echo "*** Amon Lite succesfully installed"
sudo /etc/init.d/amond start
echo "*** Starting Amon Lite "
echo "*** The web application is not running by default, you can start with \`sudo /etc/init.d/amonlite start\`"
else
echo "*** Amon Lite succesfully updated"
sudo /etc/init.d/amond restart
fi
# If the web application is running - restart it
if pgrep -x amonlite > /dev/null; then
sudo /etc/init.d/amonlite restart
fi
# Cleanup
cd $bash_script_dir # Go back to the root directory
sudo rm -rf amonlite # Delete the directory with the install files
rm amonlite-$VERSION.tar.gz # Delete the archive
print_troubleshooting_instructions