diff --git a/conf/nginx.conf b/conf/nginx.conf index 10ca335..47ce140 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -18,7 +18,7 @@ location __PATH__/ { try_files $uri $uri/ index.php; location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock; + fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; fastcgi_index index.php; include fastcgi_params; diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index 7cc3a17..1d45298 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -18,5 +18,5 @@ catch_workers_output = yes php_value[post_max_size] = 16M php_value[max_execution_time] = 300 php_value[max_input_time] = 300 -php_value[open_basedir] = /var/www/zabbix/:/usr/share/fonts/:/tmp +php_value[open_basedir] = /var/www/zabbix/:/usr/share/fonts/:/tmp:/etc/zabbix/web php_value[date.timezone] = Europe/Paris \ No newline at end of file diff --git a/manifest.json b/manifest.json index aa859f1..cbcb46a 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "A monitoring tool for diverse IT components, including networks, servers, VMs and cloud services.", "fr": "Un outil pour monitorer des réseaux, des serveurs, des VMs et autres services en ligne" }, - "version": "3.1", + "version": "3.2", "url": "https://www.zabbix.com", "license": "free", "maintainer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 44276f0..41029d9 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -178,4 +178,33 @@ remove_zabbix_repo(){ ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ /etc/yunohost/apps/zabbix/ -name "ynh_add_extra_apt_repos__3" | tail -n 1) source "$ynh_add_extra_apt_repos__3_path" ynh_remove_extra_repo --name=zabbix +} + +update_initZabbixConf(){ + if [ ! -d /etc/zabbix/web ] ;then mkdir -p /etc/zabbix/web ;fi + cp $(find /var/cache/yunohost/ -name "etc_zabbix_web_init.zabbix.conf.php.sh") /etc/zabbix/web/init.zabbix.conf.php.sh + chmod 700 /etc/zabbix/web/init.zabbix.conf.php.sh + cp $(find /var/cache/yunohost/ -name "etc_apt_apt.conf.d_100update_force_init_zabbix_frontend_config") /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config +} +delete_initZabbixConf(){ + if [ -f /etc/zabbix/web/init.zabbix.conf.php.sh ] ; then ynh_secure_remove /etc/zabbix/web/init.zabbix.conf.php.sh;fi + if [ -f /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config ] ;then ynh_secure_remove /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config ;fi +} + +#Patch timeout too short for zabbix agent if needed +change_timeoutAgent(){ + timeout_ok=$(grep "^Timeout" /etc/zabbix/zabbix_agentd.conf 2>/dev/null || true;) + if [ -z "$timeout_ok" ] ;then + ynh_replace_string --match_string="# Timeout=3" --replace_string="Timeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf + grep -C 2 "Timeout" /etc/zabbix/zabbix_agentd.conf + systemctl restart zabbix-agent + fi +} + +convert_ZabbixDB(){ + mysql --user=$db_user --password=$db_pwd --database=zabbix -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;" + for t in $(mysql -B -N --user=$db_user --password=$db_pwd --database=$db_name -e "show tables";) + do + mysql --user=$db_user --password=$db_pwd --database=$db_name -e "ALTER TABLE $t CONVERT TO character set utf8 collate utf8_bin;" + done } \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 29016eb..0d2ea7f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -39,31 +39,42 @@ nonfree=$(ynh_app_setting_get $app nonfree) #================================================= #backup frontend config +ynh_print_info "Backup $final_path conf/zabbix.conf.php" ynh_backup "$final_path/conf/zabbix.conf.php" +ynh_print_info "Backup /etc/zabbix/web" +ynh_backup "/etc/zabbix/web" +#ynh_print_info "Backup /etc/zabbix/web/init.zabbix.conf.php.sh" +#ynh_backup "/etc/zabbix/web/init.zabbix.conf.php.sh" +ynh_print_info "Backup /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config" +ynh_backup "/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config" #backup server confif +ynh_print_info "Backup /etc/zabbix/zabbix_server.conf" ynh_backup "/etc/zabbix/zabbix_server.conf" #backup agent config +ynh_print_info "Backup /etc/zabbix/zabbix_agentd.conf" ynh_backup "/etc/zabbix/zabbix_agentd.conf" +ynh_print_info "Backup /etc/zabbix/zabbix_agentd.d" ynh_backup "/etc/zabbix/zabbix_agentd.d" #backup sudo file +ynh_print_info "Backup /etc/sudoers.d/zabbix" ynh_backup "/etc/sudoers.d/zabbix" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= - +ynh_print_info "Backup /etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= - +ynh_print_info "Backup /etc/php/7.0/fpm/pool.d/$app.conf" ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE #================================================= - +ynh_print_info "Backup Zabbix database" ynh_mysql_dump_db "$db_name" > db.sql \ No newline at end of file diff --git a/scripts/install b/scripts/install index 6c567f1..3c459cd 100644 --- a/scripts/install +++ b/scripts/install @@ -57,7 +57,7 @@ ynh_webpath_register "$app" "$domain" "$path_url" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_print_info "Get infos from manifest" +ynh_script_progression --message="Get infos from manifest" -w 1 ynh_app_setting_set "$app" domain "$domain" ynh_app_setting_set "$app" path "$path_url" @@ -95,14 +95,14 @@ ynh_app_setting_set "$app" language "$language" ### - Remove the section "REMOVE DEPENDENCIES" in the remove script ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script -ynh_print_info "Remove Zabbix if already installed" -apt purge zabbix* -y +ynh_script_progression --message="Remove Zabbix if already installed" -w 1 +apt-get purge zabbix* -y rm -fr /var/cache/apt/archives/zabbix-server-mysql* -ynh_print_info "Install Zabbix repository" +ynh_script_progression --message="Install Zabbix repository" -w 3 install_zabbix_repo -ynh_print_info "Update and install dependencies" +ynh_script_progression --message="Update and install dependencies" -w 5 #ynh_package_update no need cause ynh_install_app_dependencies after ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq zabbix-server-mysql zabbix-agent zabbix-frontend-php dpkg -i --force-confmiss /var/cache/apt/archives/zabbix-server-mysql* @@ -116,7 +116,7 @@ rm "$final_path/conf/zabbix.conf.php" #================================================= # CREATE A MYSQL DATABASE #================================================= -ynh_print_info "Create and add default data in db" +ynh_script_progression --message="Creation of database " -w 10 ### Use these lines if you need a database for the application. ### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. @@ -133,11 +133,15 @@ db_user="$db_name" ynh_app_setting_set "$app" db_name "$db_name" ynh_app_setting_set "$app" db_user "$db_user" ynh_mysql_setup_db "$db_user" "$db_name" - export mysqlconn="mysql -u$db_user -p$db_pwd $db_name" +mysql --user=$db_user --password=$db_pwd --database=zabbix -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;" + +ynh_script_progression --message="Import default data in database..." -w 25 zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn +convert_ZabbixDB + #sso integration $mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;" @@ -180,7 +184,7 @@ ynh_app_setting_set "$app" final_path "$final_path" # Download, check integrity, uncompress and patch the source from app.src #ynh_setup_source "$final_path" -ynh_print_info "Generate web config" +ynh_script_progression --message="Generate web config" -w 5 #================================================= # NGINX CONFIGURATION @@ -274,7 +278,9 @@ systemctl reload nginx ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) -ynh_print_info "Generate zabbix config files" + +ynh_script_progression -m "Generate zabbix config files" -w 5 + confServerPath=$(find /var/cache/yunohost/ -name "usr_share_zabbix_conf_zabbix.conf.php") cp "$confServerPath" /usr/share/zabbix/conf/zabbix.conf.php ynh_replace_string --match_string="db_name" --replace_string="$db_name" --target_file=/usr/share/zabbix/conf/zabbix.conf.php @@ -287,10 +293,14 @@ ynh_replace_string --match_string="DBName=zabbix" --replace_string="DBName=$db_n ynh_replace_string --match_string="DBUser=zabbix" --replace_string="DBUser=$db_user" --target_file=/etc/zabbix/zabbix_server.conf ynh_replace_string --match_string="# DBPassword=" --replace_string="# DBPassword=\nDBPassword=$db_pwd" --target_file=/etc/zabbix/zabbix_server.conf -ynh_replace_string --match_string="# Timeout=3" --replace_string="# Timeout=3\nTimeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf +systemctl enable zabbix-agent --quiet && systemctl restart zabbix-agent +change_timeoutAgent +systemctl enable zabbix-server --quiet && systemctl restart zabbix-server -systemctl enable zabbix-agent && systemctl restart zabbix-agent -systemctl enable zabbix-server && systemctl restart zabbix-server +#================================================= +# INSTALL hook to verify if conf file is broken (after an update for example) +#================================================= +update_initZabbixConf #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -365,11 +375,13 @@ yunohost app ssowatconf #================================================= # Import Yunohost template #================================================= +ynh_script_progression -m "Importing last template Yunohost in Zabbix" -w 5 import_template #================================================= # Link Yunohost template to the ZAbbix Server Host #================================================= +ynh_script_progression -m "Importing last template Yunohost in Zabbix" -w 5 link_template #================================================= @@ -402,3 +414,9 @@ check_proc_zabbixagent #test if zabbix agent is started check_proc_zabbixserver + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" --last \ No newline at end of file diff --git a/scripts/remove b/scripts/remove index 9f5ea71..a1ac0e5 100644 --- a/scripts/remove +++ b/scripts/remove @@ -42,20 +42,23 @@ ynh_remove_fpm_config #================================================= timeout 5 systemctl stop zabbix-server || killall zabbix_server -systemctl disable zabbix-server +systemctl disable zabbix-server --quiet killall zabbix_server timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd -systemctl disable zabbix-agent +systemctl disable zabbix-agent --quiet killall zabbix_agentd -DEBIAN_FRONTEND=noninteractive apt purge zabbix-release -y +#Remove config file detection +delete_initZabbixConf + +DEBIAN_FRONTEND=noninteractive apt-get purge zabbix-release -y ynh_remove_app_dependencies #force removing if ynh_remove_app_dependencies not work (old zabbix version) for zabbix_pkg in $(apt list --installed | grep -Po "\K(zabbix-.*)(?=/)") do - DEBIAN_FRONTEND=noninteractive apt purge --allow-change-held-packages "$zabbix_pkg" -y + DEBIAN_FRONTEND=noninteractive apt-get purge --allow-change-held-packages "$zabbix_pkg" -y done #================================================= @@ -97,20 +100,20 @@ fi remove_zabbix_repo -#remove symlink -rm /var/www/zabbix +if [ -d /var/www/zabbix ] ;then ynh_secure_remove /var/www/zabbix;fi # Remove a directory securely -ynh_secure_remove "/etc/zabbix" +if [ -d /etc/zabbix ] ;then ynh_secure_remove "/etc/zabbix";fi # Remove the log files -ynh_secure_remove "/var/log/zabbix" +if [ -d /var/log/zabbix ] ;then ynh_secure_remove "/var/log/zabbix";fi # Remove the pid/socket files -ynh_secure_remove "/run/zabbix" +if [ -d /run/zabbix ] ;then ynh_secure_remove "/run/zabbix";fi # Remove the sudoers file -ynh_secure_remove "/etc/sudoers.d/zabbix" +if [ -f /etc/sudoers.d/zabbix ] ;then ynh_secure_remove "/etc/sudoers.d/zabbix";fi + #REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1) nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free) diff --git a/scripts/restore b/scripts/restore index d72d507..4cb49ba 100644 --- a/scripts/restore +++ b/scripts/restore @@ -96,8 +96,10 @@ db_user=$(ynh_app_setting_get $app db_user) db_pwd=$(ynh_app_setting_get $app mysqlpwd) ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd" +convert_ZabbixDB ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql + #================================================= # Restore configs files #================================================= @@ -110,13 +112,20 @@ ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php" chown -R www-data. /usr/share/zabbix ynh_restore_file "/etc/zabbix" - -# systemd and yunohost service management -systemctl enable zabbix-server && systemctl start zabbix-server +ls -Rail "/etc/zabbix" +#ynh_restore_file "/etc/zabbix/web" +#ynh_restore_file "/etc/zabbix/web/init.zabbix.conf.php.sh" +ynh_restore_file "/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config" +if [ ! -L /etc/zabbix/zabbix_agentd.d ];then + ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d +fi +systemctl enable zabbix-agent && systemctl restart zabbix-agent +change_timeoutAgent +systemctl enable zabbix-server && systemctl restart zabbix-server yunohost service add snmpd -d "Management of SNMP Daemon" yunohost service add zabbix-server -d "Management Zabbix server daemon : Collect, agregate, compute and notify" -yunohost service add zabbix-client -d "Management Zabbix client daemon : send informations about this host to the server" +yunohost service add zabbix-agent -d "Management Zabbix agent daemon : send informations about this host to the server" #================================================= # SETUP LOGROTATE diff --git a/scripts/upgrade b/scripts/upgrade index 33a2869..6af4e0f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -93,25 +93,8 @@ disable_guest_user # Normalize the URL path syntax path_url=$(ynh_normalize_url_path "$path_url") -#REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1) -nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free) -if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ] ;then - ynh_print_info "Removing snmp-mibs-downloader (non-free package)" - #want backup file , cannot use ynh_replace_string - cp /var/lib/dpkg/status{,.$(date "+%m%d%y")} - ynh_replace_string --match_string=" snmp-mibs-downloader," --replace_string="" --target_file=/var/lib/dpkg/status - DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y - if [ -f /etc/apt/sources.list.d/non-free.list ];then - ynh_secure_remove /etc/apt/sources.list.d/non-free.list - fi -fi - #Patch timeout too short for zabbix agent if needed -timeout_ok=$(grep -c "^Timeout" /etc/zabbix/zabbix_agentd.conf 2>/dev/null) -if [ $timeout_ok -ne 1 ] ;then - ynh_replace_string --match_string="# Timeout=3" --replace_string="# Timeout=3\nTimeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf - systemctl enable zabbix-agent && systemctl restart zabbix-agent -fi +change_timeoutAgent #patch if zabbix-release installed if [ "$(dpkg -l zabbix-release 2>/dev/null | wc -l)" -ne 0 ];then @@ -189,6 +172,35 @@ else ynh_print_info "No repo update ! (Trusted version)" fi +#================================================= +# INSTALL hook to verify if conf file is broken (after an update for example) +#================================================= +update_initZabbixConf + +#================================================= +# Update db to utf8 +#================================================= +convert_ZabbixDB + +#================================================= +# Update php-fpm confi +#================================================= +ynh_print_info "Update php-fpm config" +# Remove the dedicated php-fpm config +ynh_remove_fpm_config +# Create a dedicated php-fpm config +ynh_add_fpm_config + +#================================================= +# Update nginx config +#================================================= +ynh_print_info "Update nginx config" +# Remove the dedicated nginx config +ynh_remove_nginx_config +# Create a dedicated nginx config +ynh_add_nginx_config + + #================================================= # RE-ENABLE SSOWAT #================================================= diff --git a/sources/extra_files/app/Template_Yunohost.xml b/sources/extra_files/app/Template_Yunohost.xml index 6094add..9013459 100644 --- a/sources/extra_files/app/Template_Yunohost.xml +++ b/sources/extra_files/app/Template_Yunohost.xml @@ -1,7 +1,7 @@ 4.4 - 2020-01-13T12:25:26Z + 2020-04-22T11:49:47Z Templates/Applications @@ -545,4 +545,4 @@ fi - \ No newline at end of file + diff --git a/sources/extra_files/app/etc_apt_apt.conf.d_100update_force_init_zabbix_frontend_config b/sources/extra_files/app/etc_apt_apt.conf.d_100update_force_init_zabbix_frontend_config new file mode 100644 index 0000000..70c2808 --- /dev/null +++ b/sources/extra_files/app/etc_apt_apt.conf.d_100update_force_init_zabbix_frontend_config @@ -0,0 +1 @@ +DPkg::Post-Invoke {"/etc/zabbix/web/init.zabbix.conf.php.sh;"}; \ No newline at end of file diff --git a/sources/extra_files/app/etc_zabbix_web_init.zabbix.conf.php.sh b/sources/extra_files/app/etc_zabbix_web_init.zabbix.conf.php.sh new file mode 100644 index 0000000..196c850 --- /dev/null +++ b/sources/extra_files/app/etc_zabbix_web_init.zabbix.conf.php.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +if [ ! -e "/var/www/zabbix/conf/zabbix.conf.php" ] ; then + if [ ! -f /etc/zabbix/web/zabbix.conf.php ];then + cp /usr/share/zabbix/conf/zabbix.conf.php.example /etc/zabbix/web/zabbix.conf.php + fi + + ln -s /etc/zabbix/web/zabbix.conf.php /usr/share/zabbix/conf/zabbix.conf.php + source /usr/share/yunohost/helpers + echo "/etc/zabbix/web/zabbix.conf.php + + echo "Frontend Zabbix Configuration fixed !" +fi \ No newline at end of file