forked from msimerson/Mail-Toaster-6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision-elasticsearch.sh
executable file
·147 lines (123 loc) · 3.65 KB
/
provision-elasticsearch.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/sh
# shellcheck disable=1091
. mail-toaster.sh || exit
export JAIL_START_EXTRA="enforce_statfs=1"
# shellcheck disable=2016
export JAIL_CONF_EXTRA="
mount.fdescfs;
mount.procfs;
enforce_statfs = 1;
mount += \"$ZFS_DATA_MNT/elasticsearch \$path/data nullfs rw 0 0\";"
create_data_dirs()
{
for dir in etc db log plugins; do
if [ ! -d "$STAGE_MNT/data/${dir}" ]; then
tell_status "creating $STAGE_MNT/data/${dir}"
mkdir "$STAGE_MNT/data/${dir}"
chown 965:965 "$STAGE_MNT/data/${dir}"
fi
done
}
install_elasticsearch5()
{
tell_status "installing Elasticsearch"
stage_pkg_install elasticsearch5 elasticsearch5-x-pack
create_data_dirs
tell_status "installing kibana"
stage_pkg_install kibana5 kibana5-x-pack
}
install_elasticsearch6()
{
tell_status "installing Elasticsearch"
stage_pkg_install elasticsearch6
create_data_dirs
tell_status "installing kibana"
stage_pkg_install kibana6
mkdir "$STAGE_MNT/usr/local/www/kibana6/config"
#cp "$ZFS_DATA_MNT/elasticsearch/etc/kibana.yml" "$STAGE_MNT/usr/local/www/kibana6/config/"
touch "$STAGE_MNT/usr/local/www/kibana6/config/kibana.yml"
chown -R 80:80 "$STAGE_MNT/usr/local/www/kibana6"
}
install_elasticsearch()
{
# install_elasticsearch5
install_elasticsearch6
}
configure_elasticsearch()
{
local _data_conf="$STAGE_MNT/data/etc/elasticsearch.yml"
if [ -f "$_data_conf" ]; then
tell_status "preserving installed elasticsearch.yml"
return
fi
tell_status "installing elasticsearch.yml"
local _conf="$STAGE_MNT/usr/local/etc/elasticsearch/elasticsearch.yml"
mkdir -p "$STAGE_MNT/data/etc"
echo "cp $_conf $_data_conf"
cp "$_conf" "$_data_conf" || exit
chown 965 "$_data_conf"
if [ -f "$ZFS_JAIL_MNT/elasticsearch/usr/local/etc/elasticsesarch/jvm.options" ]; then
cp "$STAGE_MNT/usr/local/etc/elasticsearch/jvm.options" "$STAGE_MNT/usr/local/etc/elasticsearch/"
fi
if [ ! -f "$STAGE_MNT/data/etc/log4j2.properties" ]; then
cp "$STAGE_MNT/usr/local/etc/elasticsearch/log4j2.properties" "$STAGE_MNT/data/etc/"
chown 965 "$STAGE_MNT/data/etc/log4j2.properties"
fi
sed -i .bak \
-e '/^#network.host:/ s/#//; s/192.168.0.1/172.16.15.254/' \
-e '/^path.data: / s/var/data/' \
-e '/^path.logs: / s/var/data/' \
-e '/^path\./ s/\/elasticsearch//' \
"$_data_conf"
tee -a "$_data_conf" <<EO_ES_CONF
path.conf: /data/etc
path.plugins: /data/plugins
xpack.security.enabled: false
xpack.ml.enabled: false
EO_ES_CONF
}
configure_kibana()
{
tell_status "configuring kibana"
if [ -f "$STAGE_MNT/data/etc/kibana.yml" ]; then
tell_status "preserving kibana.yml"
return
fi
tell_status "installing kibana.yml"
cp "$STAGE_MNT/usr/local/etc/kibana.yml" "$STAGE_MNT/data/etc/"
}
start_elasticsearch()
{
tell_status "configuring Elasticsearch"
stage_sysrc elasticsearch_enable=YES
stage_sysrc elasticsearch_config=/data/etc
if jls | grep -qs elasticsearch; then
# bad things happen if two ES instances access the data dir
# so don't actually start it
tell_status "NOT starting Elasticsearch"
else
tell_status "starting Elasticsearch"
stage_exec service elasticsearch start
fi
tell_status "starting Kibana"
stage_sysrc kibana_enable=YES
stage_sysrc kibana_config=/data/etc/kibana.yml
stage_exec service kibana start
}
test_elasticsearch()
{
tell_status "testing Elasticsearch (listening 9200)"
#stage_listening 9200 10 3
tell_status "testing Kibana (listening 5601)"
echo "kibana has initial setup to do, it make take a while..."
stage_listening 5601 30 5
}
base_snapshot_exists || exit
create_staged_fs elasticsearch
start_staged_jail elasticsearch
install_elasticsearch
configure_elasticsearch
configure_kibana
start_elasticsearch
test_elasticsearch
promote_staged_jail elasticsearch