2018-01-31 16:07:43 +01:00
|
|
|
#=================================================
|
|
|
|
# SET ALL CONSTANTS
|
|
|
|
#=================================================
|
2017-07-21 22:11:45 +02:00
|
|
|
|
2023-12-09 11:10:04 +01:00
|
|
|
pkg_version="3.15.0-izzy1"
|
2023-01-22 15:32:36 +01:00
|
|
|
systemd_user=root
|
2018-01-31 16:07:43 +01:00
|
|
|
|
2023-12-09 00:35:51 +01:00
|
|
|
nginx_status_conf="/etc/nginx/conf.d/monitorix_status.conf"
|
|
|
|
|
2018-01-31 16:07:43 +01:00
|
|
|
#=================================================
|
|
|
|
# DEFINE ALL COMMON FONCTIONS
|
|
|
|
#=================================================
|
2017-01-05 23:37:07 +01:00
|
|
|
|
2023-12-09 00:35:51 +01:00
|
|
|
install_monitorix_package() {
|
|
|
|
# Create the temporary directory
|
|
|
|
tempdir="$(mktemp -d)"
|
2017-01-05 23:37:07 +01:00
|
|
|
|
2023-12-09 00:35:51 +01:00
|
|
|
# Download the deb files
|
|
|
|
ynh_setup_source --dest_dir="$tempdir" --source_id="main"
|
2017-01-31 21:26:13 +01:00
|
|
|
|
2023-12-09 00:35:51 +01:00
|
|
|
# Install the package
|
|
|
|
ynh_package_install "$tempdir/monitorix.deb"
|
2018-05-07 23:08:03 +02:00
|
|
|
|
2023-12-09 00:35:51 +01:00
|
|
|
# The doc says it should be called only once,
|
|
|
|
# but the code says multiple calls are supported.
|
|
|
|
# Also, they're already installed so that should be quasi instantaneous.
|
|
|
|
ynh_install_app_dependencies monitorix="$pkg_version"
|
2018-05-07 23:08:03 +02:00
|
|
|
|
2023-12-09 00:35:51 +01:00
|
|
|
# Mark packages as dependencies, to allow automatic removal
|
|
|
|
apt-mark auto monitorix
|
2017-07-21 22:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
config_monitorix() {
|
2020-05-13 15:19:34 +02:00
|
|
|
jail_list=$(fail2ban-client status | grep 'Jail list:' | sed 's/.*Jail list://' | sed 's/,//g')
|
2023-12-09 00:35:51 +01:00
|
|
|
f2b_additional_jail=""
|
2020-05-13 15:19:34 +02:00
|
|
|
for jail in $jail_list; do
|
|
|
|
if ! [[ "$jail" =~ (recidive|pam-generic|yunohost|postfix|postfix-sasl|dovecot|nginx-http-auth|sshd|sshd-ddos) ]]; then
|
2023-12-09 00:35:51 +01:00
|
|
|
if [ -z "$f2b_additional_jail" ]; then
|
|
|
|
f2b_additional_jail="[$jail]"
|
2020-05-13 15:19:34 +02:00
|
|
|
else
|
2023-12-09 00:35:51 +01:00
|
|
|
f2b_additional_jail+=", [$jail]"
|
2020-05-13 15:19:34 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-12-09 00:35:51 +01:00
|
|
|
ynh_add_config --template=../conf/monitorix.conf --destination="/etc/monitorix/monitorix.conf"
|
2018-01-29 18:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
set_permission() {
|
|
|
|
chown www-data:root -R /etc/monitorix
|
|
|
|
chmod u=rX,g=rwX,o= -R /etc/monitorix
|
|
|
|
chown www-data:root -R /var/lib/monitorix
|
|
|
|
chmod u=rwX,g=rwX,o= -R /var/lib/monitorix
|
2019-04-07 08:38:08 +02:00
|
|
|
}
|
2023-12-09 00:35:51 +01:00
|
|
|
|
|
|
|
_ynh_systemd_restart_monitorix() {
|
|
|
|
# Reload monitorix
|
|
|
|
# While we stop monitorix sometime the built-in web server is not stopped cleanly. So are sure that everything is cleanly stoped by that
|
|
|
|
# So this fix that
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
|
|
|
|
sleep 1
|
|
|
|
pkill -f "monitorix-httpd listening on" || true
|
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path 'systemd' --line_match ' - Ok, ready.'
|
|
|
|
}
|