From bf4875323abc2a173daf1f36fa991723ab6600c2 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 13 Dec 2018 12:07:33 +0100 Subject: [PATCH 1/7] Update install --- scripts/install | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/install b/scripts/install index 414c01b..e561e95 100644 --- a/scripts/install +++ b/scripts/install @@ -1,5 +1,3 @@ -apt #!/bin/bash - #================================================= # GENERIC START #================================================= From ddc9551c810b632e39b2a12a0c40beee33b6c1f4 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 13 Dec 2018 12:15:01 +0100 Subject: [PATCH 2/7] Update restore --- scripts/restore | 213 ++++++++++++++++++++++++++++++------------------ 1 file changed, 132 insertions(+), 81 deletions(-) diff --git a/scripts/restore b/scripts/restore index 92c999d..2149a48 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,127 +1,178 @@ -#!/bin/bash - #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= -source ../settings/scripts/_common.sh +source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true -} # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= -# LOAD SETTINGS +# RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH +admin=$YNH_APP_ARG_ADMIN +is_public=$YNH_APP_ARG_IS_PUBLIC +language=$YNH_APP_ARG_LANGUAGE + +### If it's a multi-instance app, meaning it can be installed several times independently +### The id of the app as stated in the manifest is available as $YNH_APP_ID +### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) +### The app instance name is available as $YNH_APP_INSTANCE_NAME +### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample +### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 +### - ynhexample__{N} for the subsequent installations, with N=3,4, ... +### The app instance name is probably what interests you most, since this is +### guaranteed to be unique. This is a good unique identifier to define installation path, +### db names, ... app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) - #================================================= -# CHECK IF THE APP CAN BE RESTORED +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" -test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " +### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". +### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" +rm -fr /var/www/zabbix + +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url #================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION +# STORE SETTINGS FROM MANIFEST #================================================= -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_app_setting_set $app domain $domain +ynh_app_setting_set $app path $path_url +ynh_app_setting_set $app admin $admin +ynh_app_setting_set $app is_public $is_public +ynh_app_setting_set $app language $language #================================================= -# RESTORE THE APP MAIN DIR +# INSTALL DEPENDENCIES #================================================= -ynh_restore_file "$final_path" +wget "https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2+stretch_all.deb" +dpkg -i zabbix-release_*.deb +rm zabbix-release_*.deb +echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list +ynh_package_update +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 snmp-mibs-downloader libjs-prototype +yunohost service add snmpd -d "Management of SNMP Daemon" +DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php +ar x *.deb +tar xzf control.tar.gz +sed -i 's/apache2 | httpd, //' control +tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control +ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz + +dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb + +rm -fr zabbix-*.deb +ynh_package_install zabbix-server-mysql zabbix-agent +DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php + +sed -i "s/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/g" /etc/locale.gen +locale-gen + +ln -s /usr/share/zabbix $final_path +rm $final_path/conf/zabbix.conf.php + +ynh_app_setting_set $app final_path $final_path #================================================= -# RESTORE THE MYSQL DATABASE +# NGINX CONFIGURATION #================================================= -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_mysql_setup_db $db_name $db_name $db_pwd -ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql +### `ynh_add_nginx_config` will use the file conf/nginx.conf + +# Create a dedicated nginx config +ynh_add_nginx_config #================================================= -# RECREATE THE DEDICATED USER +# CREATE DEDICATED USER #================================================= -# Create the dedicated user (if not existing) -ynh_system_user_create $app +# Create a system user +#ynh_system_user_create $app #================================================= -# RESTORE USER RIGHTS +# PHP-FPM CONFIGURATION #================================================= -# Restore permissions on app files -chown -R root: $final_path +ynh_add_fpm_config -#================================================= -# RESTORE THE PHP-FPM CONFIGURATION -#================================================= +# Reload SSOwat config +yunohost app ssowatconf -ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" -ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini" - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= - -# Define and install dependencies -ynh_install_app_dependencies deb1 deb2 - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -yunohost service add $app --log "/var/log/$app/APP.log" - -#================================================= -# RESTORE SYSTEMD -#================================================= - -ynh_restore_file "/etc/systemd/system/$app.service" -systemctl enable $app.service - -#================================================= -# RESTORE THE CRON FILE -#================================================= - -ynh_restore_file "/etc/cron.d/$app" - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file "/etc/logrotate.d/$app" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX AND PHP-FPM -#================================================= - -systemctl reload php5-fpm +# Reload Nginx systemctl reload nginx + +# Remove the public access +if [ $is_public -eq 0 ] +then + ynh_app_setting_delete $app skipped_uris +fi + +#================================================= +# Restore configs files +#================================================= + +### `ynh_replace_string` is used to replace a string in a file. +### (It's compatible with sed regular expressions syntax) + +ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php" + +chown -R www-data. /usr/share/zabbix + +ynh_restore_file "/etc/zabbix" + +systemctl enable zabbix-server && systemctl start zabbix-server + + +#================================================= +# SETUP LOGROTATE +#================================================= + +### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. +### Use this helper only if there is effectively a log file for this app. +### If you're not using this helper: +### - Remove the section "BACKUP LOGROTATE" in the backup script +### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script +### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script +### - And the section "SETUP LOGROTATE" in the upgrade script + +# Use logrotate to manage application logfile(s) +ynh_use_logrotate + +#================================================= +# SETUP SSOWAT +#================================================= + +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set $app unprotected_uris "/" +fi + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx + From d189bf501c921e6673e9f231cf7c7d2ca67d0c8a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 13 Dec 2018 12:22:15 +0100 Subject: [PATCH 3/7] Update restore --- scripts/restore | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/restore b/scripts/restore index 2149a48..dd10c19 100644 --- a/scripts/restore +++ b/scripts/restore @@ -128,6 +128,17 @@ then ynh_app_setting_delete $app skipped_uris fi +#================================================= +# Restore db +#================================================= + +db_name=$(ynh_app_setting_get $app db_name) +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 +ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql + #================================================= # Restore configs files #================================================= @@ -144,6 +155,8 @@ ynh_restore_file "/etc/zabbix" systemctl enable zabbix-server && systemctl start zabbix-server + + #================================================= # SETUP LOGROTATE #================================================= From 64cb1f53b59e572f8c7aadca1dea0f3a978c4536 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 13 Dec 2018 12:28:36 +0100 Subject: [PATCH 4/7] Update restore --- scripts/restore | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/restore b/scripts/restore index dd10c19..8ae81f0 100644 --- a/scripts/restore +++ b/scripts/restore @@ -34,7 +34,7 @@ language=$YNH_APP_ARG_LANGUAGE ### The app instance name is probably what interests you most, since this is ### guaranteed to be unique. This is a good unique identifier to define installation path, ### db names, ... -app=$YNH_APP_INSTANCE_NAME +app=ynhzabbix #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS @@ -56,11 +56,11 @@ ynh_webpath_register $app $domain $path_url # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app admin $admin -ynh_app_setting_set $app is_public $is_public -ynh_app_setting_set $app language $language +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +admin=$(ynh_app_setting_get $app admin) +is_public=$(ynh_app_setting_get $app is_public) +language=$(ynh_app_setting_get $app language) #================================================= # INSTALL DEPENDENCIES From 602c0e0680183d38788ab2f73ec795ddea8b6b0a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 13 Dec 2018 13:33:04 +0100 Subject: [PATCH 5/7] Update restore --- scripts/restore | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/scripts/restore b/scripts/restore index 8ae81f0..166ef64 100644 --- a/scripts/restore +++ b/scripts/restore @@ -4,7 +4,7 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh +#source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -12,17 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -domain=$YNH_APP_ARG_DOMAIN -path_url=$YNH_APP_ARG_PATH -admin=$YNH_APP_ARG_ADMIN -is_public=$YNH_APP_ARG_IS_PUBLIC -language=$YNH_APP_ARG_LANGUAGE +#ynh_abort_if_errors ### If it's a multi-instance app, meaning it can be installed several times independently ### The id of the app as stated in the manifest is available as $YNH_APP_ID @@ -34,7 +24,7 @@ language=$YNH_APP_ARG_LANGUAGE ### The app instance name is probably what interests you most, since this is ### guaranteed to be unique. This is a good unique identifier to define installation path, ### db names, ... -app=ynhzabbix +app="ynhzabbix" #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS From eb51998e8ebc4cf5dcf0b633d85b8fadb9c290e9 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 13 Dec 2018 14:10:00 +0100 Subject: [PATCH 6/7] Update restore --- scripts/restore | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/scripts/restore b/scripts/restore index 166ef64..b5649ad 100644 --- a/scripts/restore +++ b/scripts/restore @@ -79,7 +79,7 @@ DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend sed -i "s/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/g" /etc/locale.gen locale-gen -ln -s /usr/share/zabbix $final_path +ln -s /usr/share/zabbix /var/www/zabbix rm $final_path/conf/zabbix.conf.php ynh_app_setting_set $app final_path $final_path @@ -91,20 +91,15 @@ ynh_app_setting_set $app final_path $final_path ### `ynh_add_nginx_config` will use the file conf/nginx.conf # Create a dedicated nginx config -ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= - -# Create a system user -#ynh_system_user_create $app +ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php" #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_add_fpm_config +ynh_restore_file "/etc/php/7.0/fpm/pool.d/ynhzabbix.conf" + # Reload SSOwat config yunohost app ssowatconf @@ -178,4 +173,6 @@ fi #================================================= systemctl reload nginx +systemctl reload php7.0-fpm + From 1ee5d7f328efb9b99844ed7753aceeeedf7147d8 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 13 Dec 2018 14:13:49 +0100 Subject: [PATCH 7/7] Update restore --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index b5649ad..333e105 100644 --- a/scripts/restore +++ b/scripts/restore @@ -92,7 +92,7 @@ ynh_app_setting_set $app final_path $final_path # Create a dedicated nginx config -ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php" +ynh_restore_file "/etc/nginx/conf.d/mike.test.d/ynhzabbix.conf" #================================================= # PHP-FPM CONFIGURATION