-
Notifications
You must be signed in to change notification settings - Fork 20
/
bootstrap.sh
executable file
·57 lines (39 loc) · 1.44 KB
/
bootstrap.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
#!/bin/bash
BASE_OMD="/opt/omd/sites"
# Init check_mk instance
if [ ! -d "${BASE_OMD}/${CMK_SITE}" ] ; then
# Create new site
omd create ${CMK_SITE}
omd config ${CMK_SITE} set APACHE_TCP_ADDR 0.0.0.0
htpasswd -b -m /omd/sites/${CMK_SITE}/etc/htpasswd cmkadmin ${CMK_PASSWORD}
/opt/redirector.sh ${CMK_SITE} > /omd/sites/${CMK_SITE}/var/www/index.html
# Save omd record about tmpfs for second use
grep omd /etc/fstab > ${BASE_OMD}/${CMK_SITE}/.fstab.tmpfs
else
# Create user and group for using existing site with new container
useradd -M -c "OMD site ${CMK_SITE}" -b "/omd/sites" -U -G omd ${CMK_SITE}
usermod -aG ${CMK_SITE} apache
chown -R ${CMK_SITE}:${CMK_SITE} ${BASE_OMD}/${CMK_SITE}
# Restore tmpfs
cat ${BASE_OMD}/${CMK_SITE}/.fstab.tmpfs >> /etc/fstab
mount tmpfs
omd enable ${CMK_SITE}
fi
# This link is always needed
ln -s "/omd/sites/${CMK_SITE}/var/log/nagios.log" /var/log/nagios.log
# Create SSMTP config
CFGFILE=/etc/ssmtp/ssmtp.conf
cat >$CFGFILE <<CONFIG
root=root
mailhub=${MAILHUB}
FromLineOverride=YES
CONFIG
[ "${MAILHUBAUTHUSER}" ] && echo AuthUser=${MAILHUBAUTHUSER} >> $CFGFILE
[ "${MAILHUBAUTHPASS}" ] && echo AuthPass=${MAILHUBAUTHPASS} >> $CFGFILE
[ "${MAILHUBSTARTTLS}" ] && echo UseSTARTSSL=${MAILHUBSTARTTLS} >> $CFGFILE
chmod 640 $CFGFILE
chown root:mail $CFGFILE
# Start cron daemon
/usr/sbin/crond
# Start check_mk
omd start && tail -f /var/log/nagios.log