blob: bd13de2821ec78c7012556041d1f17de80fb1f2b (
plain)
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
|
#!/bin/bash
is_active() {
systemctl is-active -q prometheus-node-exporter || return 0
return 1
}
tmpl_metrics_enabled() {
(
. /usr/local/etc/library.sh
local param_active="$(find_app_param metrics.sh ACTIVE)"
[[ "$param_active" == yes ]] || exit 1
)
}
install() {
# Subshell to return on failure instead of exiting (due to set -e)
(
set -e
cat > /etc/default/prometheus-node-exporter <<'EOF'
ARGS="--collector.filesystem.ignored-mount-points=\"^/(dev|proc|run|sys|mnt|var/log|var/lib/docker)($|/)\""
EOF
apt_install prometheus-node-exporter
# TODO: Docker support?
systemctl disable prometheus-node-exporter
service prometheus-node-exporter stop
)
}
configure() {
if [[ "$ACTIVE" != yes ]]
then
bash /usr/local/etc/ncp-templates/nextcloud.conf.sh --defaults > /etc/apache2/sites-available/nextcloud.conf
systemctl disable prometheus-node-exporter
service prometheus-node-exporter stop
else
[[ -n "$USER" ]] || {
echo "ERROR: User can not be empty!" >&2
return 1
}
[[ -n "$PASSWORD" ]] || {
echo "ERROR: Password can not be empty!" >&2
return 1
}
[[ ${#PASSWORD} -ge 10 ]] || {
echo "ERROR: Password must be at least 10 characters long!" >&2
return 1
}
local htpasswd_file="/usr/local/etc/metrics.htpasswd"
rm -f "${htpasswd_file}"
echo "$PASSWORD" | htpasswd -ciB "${htpasswd_file}" metrics
bash /usr/local/etc/ncp-templates/nextcloud.conf.sh > /etc/apache2/sites-available/nextcloud.conf || {
echo "An unexpected error occurred while configuring apache. Rolling back..." >&2
bash /usr/local/etc/ncp-templates/nextcloud.conf.sh --defaults > /etc/apache2/sites-available/nextcloud.conf
return 1
}
systemctl enable prometheus-node-exporter
service prometheus-node-exporter start
echo "Metric endpoint enabled. You can test it at https://nextcloudpi.local/metrics/system (or under your NC domain under the same path)"
fi
echo "Apache Test:"
apache2ctl -t
bash -c "sleep 2 && service apache2 reload" &>/dev/null &
}
|