| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- #!/bin/bash
- #=================================================
- # GENERIC START
- #=================================================
- # IMPORT GENERIC HELPERS
- #=================================================
- # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
- source ../settings/scripts/_common.sh
- source /usr/share/yunohost/helpers
- #=================================================
- # MANAGE SCRIPT FAILURE
- #=================================================
- ynh_clean_setup () {
- ynh_clean_check_starting
- }
- # Exit if an error occurs during the execution of the script
- ynh_abort_if_errors
- #=================================================
- # LOAD SETTINGS
- #=================================================
- ynh_script_progression --message="Loading installation settings..."
- app=$YNH_APP_INSTANCE_NAME
- domain=$(ynh_app_setting_get --app=$app --key=domain)
- path_url=$(ynh_app_setting_get --app=$app --key=path)
- final_path=$(ynh_app_setting_get --app=$app --key=final_path)
- db_name=$(ynh_app_setting_get --app=$app --key=db_name)
- db_user=$db_name
- phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
- language=$(ynh_app_setting_get --app=$app --key=language)
- #=================================================
- # CHECK IF THE APP CAN BE RESTORED
- #=================================================
- ynh_script_progression --message="Validating restoration parameters..."
- remove_previous_zabbix
- test ! -d $final_path \
- || ynh_die --message="There is already a directory: $final_path "
- #=================================================
- # STANDARD RESTORATION STEPS
- #=================================================
- # SPECIFIC RESTORATION
- #=================================================
- # REINSTALL DEPENDENCIES
- #=================================================
- ynh_script_progression --message="Reinstalling dependencies..."
- # Define and install dependencies
- ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
- ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="http://repo.zabbix.com/zabbix/5.0/debian $(lsb_release -sc) main" --package="$zabbix_pkg_dependencies" --key="https://repo.zabbix.com/zabbix-official-repo.key"
- ynh_replace_string --match_string="# $language.UTF-8 UTF-8" --replace_string="$language.UTF-8 UTF-8" --target_file=/etc/locale.gen
- locale-gen
- #=================================================
- # RESTORE THE APP MAIN DIR
- #=================================================
- ynh_script_progression --message="Restoring the app main directory..."
- ln -s /usr/share/zabbix "$final_path"
- chmod 750 "/usr/share/zabbix"
- chmod -R o-rwx "/usr/share/zabbix"
- chown -R $app:www-data "/usr/share/zabbix"
- #=================================================
- # RESTORE THE PHP-FPM CONFIGURATION
- #=================================================
- ynh_script_progression --message="Restoring the PHP-FPM configuration..."
- ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
- #=================================================
- # RESTORE THE NGINX CONFIGURATION
- #=================================================
- ynh_script_progression --message="Restoring the NGINX web server configuration..."
- ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
- #=================================================
- # RESTORE THE MYSQL DATABASE
- #=================================================
- ynh_script_progression --message="Restoring the MySQL database..."
- db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
- ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
- ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
- export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
- convert_ZabbixDB
- #=================================================
- # RESTORE VARIOUS FILES
- #=================================================
- ynh_script_progression --message="Restoring various files..."
- if [ -f "/etc/zabbix/web/zabbix.conf.php" ]
- then
- ynh_secure_remove --file="/etc/zabbix/web/zabbix.conf.php"
- fi
- ynh_restore_file --origin_path="/etc/zabbix/web/zabbix.conf.php"
- chmod 400 "/etc/zabbix/web/zabbix.conf.php"
- chown $app:www-data "/etc/zabbix/web/zabbix.conf.php"
- ynh_restore_file --origin_path="/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
- ynh_restore_file --origin_path="/etc/zabbix/zabbix_server.conf"
- ynh_restore_file --origin_path="/etc/zabbix/zabbix_agentd.conf"
- if [ ! -L /etc/zabbix/zabbix_agentd.d ]
- then
- ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d
- fi
- # Restore sudo file
- ynh_restore_file --origin_path="/etc/sudoers.d/zabbix"
- #=================================================
- # RESTORE SYSTEMD
- #=================================================
- ynh_script_progression --message="Restoring the systemd configuration..."
- change_timeoutAgent
- systemctl enable zabbix-agent --quiet
- systemctl enable zabbix-server --quiet
- #=================================================
- # INTEGRATE SERVICE IN YUNOHOST
- #=================================================
- ynh_script_progression --message="Integrating service in YunoHost..."
- yunohost service add snmpd --description="Management of SNMP Daemon"
- yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
- yunohost service add zabbix-agent --description="Management Zabbix agent daemon : send informations about this host to the server" --log="/var/log/$app/${app}_agent.log"
- #=================================================
- # START SYSTEMD SERVICE
- #=================================================
- ynh_script_progression --message="Starting a systemd service..."
- # Start a systemd service
- ynh_systemd_action --service_name=$app-server --action="restart" --log_path="/var/log/$app/${app}_server.log"
- ynh_systemd_action --service_name=$app-agent --action="restart" --log_path="/var/log/$app/${app}_agent.log"
- #=================================================
- # GENERIC FINALIZATION
- #=================================================
- # RELOAD NGINX AND PHP-FPM
- #=================================================
- ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..."
- ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
- ynh_systemd_action --service_name=nginx --action=reload
- #=================================================
- # END OF SCRIPT
- #=================================================
- ynh_script_progression --message="Restoration completed for $app"
|