1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/monitorix_ynh.git synced 2024-09-03 19:46:06 +02:00
monitorix_ynh/scripts/install
2022-11-02 23:07:44 +01:00

93 lines
2.8 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Import common cmd
source ./experimental_helper.sh
source ./_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
ynh_script_progression --message="Validating installation parameters..."
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
ynh_webpath_register $app $domain $path_url
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
# Find a port for built-in monitorix HTTP server
ynh_script_progression --message="Finding available ports..."
port=$(ynh_find_port --port 8080)
nginx_status_port=$(ynh_find_port --port $(($port +1)))
# 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
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# Creating the folder
mkdir -p /var/lib/monitorix/www/imgs
mkdir -p /etc/monitorix/conf.d/
touch /etc/monitorix/conf.d/00-debian.conf
# Install package
ynh_script_progression --message="Installing dependencies..." --weight=7
install_dependances
# Download package and install it
ynh_script_progression --message="Installing sources files..." --weight=7
get_install_source
# # Generate MySQL user
ynh_script_progression --message="Configuring MySQL database..."
dbuser=$app
dbpass=$(ynh_string_random 12)
ynh_app_setting_set --app $app --key mysqlpwd --value "$dbpass"
ynh_mysql_create_user $dbuser $dbpass
# Config nginx
ynh_script_progression --message="Configuring nginx..." --weight=1
config_nginx
# Update monitorix configuration
ynh_script_progression --message="Configuring application..." --weight=3
config_monitorix
#=================================================
# GENERIC FINALIZATION
#=================================================
# Set access
ynh_script_progression --message="Protecting directory..."
set_permission
# register yunohost service
yunohost service add monitorix
# Reload monitorix
ynh_script_progression --message="Starting monitorix services..." --weight=3
# 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
systemctl stop monitorix.service
sleep 1
pkill -f "monitorix-httpd listening on" || true
ynh_systemd_action -l ' - Ok, ready.' -p '/var/log/monitorix'
ynh_script_progression --message="Installation of $app completed" --last