forked from msimerson/Mail-Toaster-6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision-elasticsearch.sh
executable file
·131 lines (108 loc) · 3.46 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
#!/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\";"
install_elasticsearch()
{
tell_status "installing Elasticsearch"
stage_pkg_install elasticsearch2
tell_status "installing kopf plugin"
stage_exec /usr/local/lib/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
if [ ! -d "$ZFS_DATA_MNT/elasticsearch/etc" ]; then
tell_status "creating $ZFS_DATA_MNT/elasticsearch/etc"
mkdir "$ZFS_DATA_MNT/elasticsearch/etc"
fi
if [ ! -d "$ZFS_DATA_MNT/elasticsearch/db" ]; then
tell_status "creating $ZFS_DATA_MNT/elasticsearch/db"
mkdir "$ZFS_DATA_MNT/elasticsearch/db" || exit
chown 965:965 "$ZFS_DATA_MNT/elasticsearch/db"
fi
if [ ! -d "$ZFS_DATA_MNT/elasticsearch/log" ]; then
tell_status "creating $ZFS_DATA_MNT/elasticsearch/log"
mkdir "$ZFS_DATA_MNT/elasticsearch/log" || exit
chown 965:965 "$ZFS_DATA_MNT/elasticsearch/log"
fi
if [ ! -d "$ZFS_DATA_MNT/elasticsearch/plugins" ]; then
tell_status "creating $ZFS_DATA_MNT/elasticsearch/plugins"
mkdir "$ZFS_DATA_MNT/elasticsearch/plugins"
fi
tell_status "installing kibana"
stage_pkg_install kibana45
}
configure_elasticsearch()
{
local _data_conf="$ZFS_DATA_MNT/elasticsearch/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"
cp "$_conf" "$_data_conf"
chown 965 "$_data_conf"
cp "$STAGE_MNT/usr/local/etc/elasticsearch/logging.yml" "$ZFS_DATA_MNT/elasticsearch/etc/"
sed -i .bak \
-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
EO_ES_CONF
}
configure_kibana()
{
tell_status "configuring kibana"
if [ -f "$ZFS_DATA_MNT/elasticsearch/etc/kibana.yml" ]; then
tell_status "preserving kibana.yml"
return
fi
tell_status "installing kibana.yml"
cp "$STAGE_MNT/usr/local/etc/kibana.yml" "$ZFS_DATA_MNT/elasticsearch/etc/"
}
start_elasticsearch()
{
tell_status "starting Elasticsearch"
stage_sysrc elasticsearch_enable=YES
stage_sysrc elasticsearch_config=/data/etc
stage_sysrc elasticsearch_min_mem=4g
stage_sysrc elasticsearch_max_mem=4g
stage_sysrc elasticsearch_heap_newsize=4g
stage_exec service elasticsearch start
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 "waiting 10 seconds for ES to start"
sleep 10
tell_status "testing Elasticsearch (listening 9200)"
stage_listening 9200
tell_status "waiting 10 seconds for kibana to start"
sleep 10
tell_status "testing Kibana (listening 5601)"
stage_listening 5601
echo "it worked"
# not so good things can happen if two ES instances access the data dir
# so wait until just before promotion to switch the active config
stage_sysrc elasticsearch_config=/data/etc
stage_sysrc kibana_config=/data/etc/kibana.yml
}
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