2017-01-05 23:37:07 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-01-31 16:07:43 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
|
2020-11-17 23:37:38 +01:00
|
|
|
# Import common cmd
|
|
|
|
source ./experimental_helper.sh
|
|
|
|
source ./_common.sh
|
|
|
|
|
2017-07-21 22:11:45 +02:00
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Stop script if errors
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
|
2017-01-05 23:37:07 +01:00
|
|
|
# Retrieve arguments
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2020-12-12 15:01:50 +01:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2017-01-05 23:37:07 +01:00
|
|
|
|
2018-05-07 23:08:03 +02:00
|
|
|
ynh_webpath_register $app $domain $path_url
|
2017-01-05 23:37:07 +01:00
|
|
|
|
2022-11-02 23:07:44 +01:00
|
|
|
if [ -e "/var/lib/monitorix" ]; then
|
|
|
|
old_data_dir_path="/var/lib/monitorix$(date '+%Y%m%d.%H%M%S')"
|
|
|
|
ynh_print_warn "A data directory already exist. Data was renamed to $old_data_dir_path"
|
|
|
|
mv "/var/lib/monitorix" "$old_data_dir_path"
|
|
|
|
fi
|
|
|
|
|
2018-01-31 16:07:43 +01:00
|
|
|
# Find a port for built-in monitorix HTTP server
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Finding available ports..."
|
|
|
|
port=$(ynh_find_port --port 8080)
|
|
|
|
nginx_status_port=$(ynh_find_port --port $(($port +1)))
|
2018-01-31 16:07:43 +01:00
|
|
|
|
2019-06-07 23:09:30 +02:00
|
|
|
# store config in yunohost
|
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
|
|
|
ynh_app_setting_set --app $app --key http_port --value $port
|
|
|
|
ynh_app_setting_set --app $app --key nginx_status_port --value $nginx_status_port
|
2018-01-31 16:07:43 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
|
2021-02-03 22:26:07 +01:00
|
|
|
# Creating the folder
|
|
|
|
mkdir -p /var/lib/monitorix/www/imgs
|
2021-02-18 19:07:39 +01:00
|
|
|
mkdir -p /etc/monitorix/conf.d/
|
|
|
|
touch /etc/monitorix/conf.d/00-debian.conf
|
2021-02-03 22:26:07 +01:00
|
|
|
|
2019-06-07 23:09:30 +02:00
|
|
|
# Install package
|
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=7
|
2017-07-21 22:11:45 +02:00
|
|
|
install_dependances
|
2017-01-05 23:37:07 +01:00
|
|
|
|
2017-10-31 23:08:23 +01:00
|
|
|
# Download package and install it
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Installing sources files..." --weight=7
|
2017-10-31 23:08:23 +01:00
|
|
|
get_install_source
|
|
|
|
|
2023-01-22 03:09:34 +01:00
|
|
|
# Configure init script
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=2
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
2017-07-21 22:11:45 +02:00
|
|
|
# # Generate MySQL user
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Configuring MySQL database..."
|
2017-01-05 23:37:07 +01:00
|
|
|
dbuser=$app
|
|
|
|
dbpass=$(ynh_string_random 12)
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_app_setting_set --app $app --key mysqlpwd --value "$dbpass"
|
2017-07-21 22:11:45 +02:00
|
|
|
ynh_mysql_create_user $dbuser $dbpass
|
2017-01-05 23:37:07 +01:00
|
|
|
|
2017-07-21 22:11:45 +02:00
|
|
|
# Config nginx
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Configuring nginx..." --weight=1
|
2017-07-21 22:11:45 +02:00
|
|
|
config_nginx
|
2017-01-05 23:37:07 +01:00
|
|
|
|
|
|
|
# Update monitorix configuration
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Configuring application..." --weight=3
|
2017-07-21 22:11:45 +02:00
|
|
|
config_monitorix
|
2017-01-05 23:37:07 +01:00
|
|
|
|
2018-04-30 21:41:07 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
2018-01-29 18:57:10 +01:00
|
|
|
# Set access
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Protecting directory..."
|
2018-01-29 18:57:10 +01:00
|
|
|
set_permission
|
|
|
|
|
2017-05-26 15:02:19 +02:00
|
|
|
# register yunohost service
|
2017-07-21 22:11:45 +02:00
|
|
|
yunohost service add monitorix
|
2017-05-26 15:02:19 +02:00
|
|
|
|
2018-05-01 21:00:07 +02:00
|
|
|
# Reload monitorix
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Starting monitorix services..." --weight=3
|
2018-05-07 23:08:03 +02:00
|
|
|
# While we stop monitorix sometime the built-in web server is not stopped cleanly. So are sure that everything is cleanly stoped by that
|
2018-05-01 21:00:07 +02:00
|
|
|
# So this fix that
|
2019-06-07 23:09:30 +02:00
|
|
|
systemctl stop monitorix.service
|
2018-05-01 21:00:07 +02:00
|
|
|
sleep 1
|
2018-05-07 23:08:03 +02:00
|
|
|
pkill -f "monitorix-httpd listening on" || true
|
2023-01-22 03:09:34 +01:00
|
|
|
ynh_systemd_action -l ' - Ok, ready.' -p 'systemd'
|
2019-06-07 23:09:30 +02:00
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|