forked from nicolargo/shinkenautoinstall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshinkenautoinstall-debian.sh
More file actions
executable file
·201 lines (184 loc) · 6.5 KB
/
shinkenautoinstall-debian.sh
File metadata and controls
executable file
·201 lines (184 loc) · 6.5 KB
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
#!/bin/sh
#
# Installation automatique de Shinken sous Debian
#
# Nicolas Hennion aka Nicolargo
# Script libre: GPLv3
#
# Syntaxe: root> ./shinkenautoinstall-debian.sh
#
# Version 0.4
# MaJ de Thruk en 1.0.2
#
# Version 0.3
# MaJ de Thruk en 1.0.1
#
# Version 0.2
# MaJ de Shinken 0.6
# MaJ de Thruk 0.94.4
#
# Version 0.1:
# Installation de Shinken 0.5.5
# Installation de Thruk 0.90
#
script_version="0.44"
### Can be modified
shinken_version="0.6" #
thruk_version="1.0.2" #
arch_version="`arch`" # i386 | i486 | x86_64
perl_version="5.10.0" # `perl -e 'use Config; print $Config{version}'`
multiprocessing_version="2.6.2.1" #
### /Can be modified
DATE=`date +"%Y%m%d%H%M%S"`
BACKUP_FILE="/tmp/shinken-backup-$DATE.tgz"
# Function: backup
backup() {
echo "----------------------------------------------------"
echo "Backup the current configuration"
echo "----------------------------------------------------"
echo ""
tar zcvf $BACKUP_FILE /etc/shinken
}
# Function: installation
installation() {
# Create the temporary directory
mkdir ~/$0.$DATE
# Pre-requisite
echo "----------------------------------------------------"
echo "Installation pre-requisites"
echo " * python-dev python-setuptools pyro wget libgd2-xpm-dev nagios-plugins"
echo " * multiprocessing version $multiprocessing_version"
echo "----------------------------------------------------"
aptitude install python-dev python-setuptools pyro wget libgd2-xpm-dev nagios-plugins
cd ~/$0.$DATE
wget http://pypi.python.org/packages/source/m/multiprocessing/multiprocessing-$multiprocessing_version.tar.gz
if [ "$?" -ne "0" ]; then
echo "Download Shinken version $multiprocessing_version [ERROR]"
exit 1
fi
tar zxvf multiprocessing-$multiprocessing_version.tar.gz
cd multiprocessing-$multiprocessing_version/
python setup.py install
# echo "----------------------------------------------------"
# echo "Install and configure Postfix"
# echo "----------------------------------------------------"
# aptitude install mailx postfix
# ln -s /usr/bin/mail /bin/mail
# Download sources
echo "----------------------------------------------------"
echo "Download sources"
echo " * Shinken version $shinken_version"
echo " * Thruk version $thruk_version"
echo "----------------------------------------------------"
cd ~/$0.$DATE
wget http://shinken-monitoring.org/pub/shinken-$shinken_version.tar.gz
if [ "$?" -ne "0" ]; then
echo "Download Shinken version $shinken_version [ERROR]"
exit 1
fi
wget http://www.thruk.org/files/Thruk-$thruk_version-$arch_version-linux-gnu-thread-multi-$perl_version.tar.gz
if [ "$?" -ne "0" ]; then
echo "Try another mirror for Thruk (archives)..."
wget http://www.thruk.org/files/archive/Thruk-$thruk_version-$arch_version-linux-gnu-thread-multi-$perl_version.tar.gz
if [ "$?" -ne "0" ]; then
echo "Download Thruk version $shinken_version [ERROR]"
exit 1
fi
fi
# Create shinken user and group
if [ ! `id -u shinken` ]
then
echo "----------------------------------------------------"
echo "Creation utilisateur shinken et groupe shinken"
echo "----------------------------------------------------"
useradd -s /bin/noshellneeded shinken
echo "Fixer un mot de passe pour l'utilisateur shinken"
passwd shinken
usermod -G shinken shinken
fi
# Installation
echo "----------------------------------------------------"
echo "Configure, compile and install..."
echo "----------------------------------------------------"
cd ~/$0.$DATE
tar zxvf shinken-$shinken_version.tar.gz
cd shinken-$shinken_version
python setup.py install --install-scripts=/usr/bin/
cp libexec/* /usr/lib/nagios/plugins/
cd ~/$0.$DATE
tar zxvf Thruk-$thruk_version-$arch_version-linux-gnu-thread-multi-$perl_version.tar.gz
cd Thruk-$thruk_version
wget http://svn.nicolargo.com/shinkenautoinstall/trunk/thruk_local.conf
cd ..
mkdir /opt/thruk
cp -R Thruk-$thruk_version/* /opt/thruk
chown -R shinken:shinken /opt/thruk
echo "----------------------------------------------------"
echo "Hack the default Shinken startup script"
echo "----------------------------------------------------"
sed -i 's/BIN="\/usr\/local\/shinken\/bin"/BIN="\/usr\/bin"/g' /etc/init.d/shinken
sed -i 's/VAR="\/usr\/local\/shinken\/var"/VAR="\/var\/lib\/shinken"/g' /etc/init.d/shinken
sed -i 's/ETC="\/usr\/local\/shinken\/etc"/ETC="\/etc\/shinken"/g' /etc/init.d/shinken
wget -O /etc/init.d/thruk http://svn.nicolargo.com/shinkenautoinstall/trunk/thruk
chown root:root /etc/init.d/thruk
chmod a+rx /etc/init.d/thruk
echo "----------------------------------------------------"
echo "Start Shinken and Thruk on boot"
echo "----------------------------------------------------"
update-rc.d shinken defaults
update-rc.d thruk defaults
rm -rf ~/$0.$DATE
}
# Fonction: Verifie si les fichiers de conf sont OK
check() {
echo "----------------------------------------------------"
echo "Check the Shinken configuration"
echo "----------------------------------------------------"
python /usr/bin/shinken-arbiter -v -c /etc/shinken/nagios.cfg -c /etc/shinken/shinken-specific.cfg
}
# Fonction: Lancement de Shinken
start() {
echo "----------------------------------------------------"
echo "Start Shinken and Thruk"
echo "----------------------------------------------------"
sleep 2
/etc/init.d/shinken start
/etc/init.d/thruk start
}
# Fonction: Arret de Shinken
stop() {
echo "----------------------------------------------------"
echo "Arret de Shinken et de Thruk"
echo "----------------------------------------------------"
sleep 2
/etc/init.d/shinken stop
/etc/init.d/thruk stop
}
# Fonction: Affiche le résumé de l'installation
end() {
echo "----------------------------------------------------"
echo "Installation is finished"
echo "----------------------------------------------------"
if [ -f $BACKUP_FILE ]; then
echo "Backup configuration file : $BACKUP_FILE"
fi
echo "Configuration file folder : /etc/shinken"
echo "Log file : /var/lib/shinken/nagios.log"
echo "Shinken startup script : /etc/init.d/shinken"
echo "Thruk startup script : /etc/init.d/thruk"
echo "Thruk web interface URL : http://`hostname`:3000"
}
# Programme principal
if [ "$(id -u)" != "0" ]; then
echo "This script should be run as root."
echo "Syntaxe: sudo $0"
exit 1
fi
if [ -d /etc/shinken ]; then
stop
backup
fi
installation
check
start
end