From 14536e3840afe02f9a29ef2f02d1a52008b8d0de Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 22 Aug 2021 16:17:29 +0200 Subject: [PATCH 1/2] Apply example_ynh --- manifest.json | 4 +--- scripts/_common.sh | 1 + scripts/backup | 37 +++++++++++++++++-------------------- scripts/change_url | 1 + scripts/install | 21 +++++++++------------ scripts/remove | 4 ++-- scripts/restore | 29 +++++++++++++++-------------- scripts/upgrade | 41 +++++++++++++++++++++++------------------ 8 files changed, 69 insertions(+), 69 deletions(-) diff --git a/manifest.json b/manifest.json index 6d9ceab..a04e6a2 100644 --- a/manifest.json +++ b/manifest.json @@ -13,8 +13,6 @@ "license": "AGPL-3.0-only", "website": "https://grafana.com/", "demo": "https://play.grafana.org", - "admindoc": "https://yunohost.org/packaging_apps", - "userdoc": "https://yunohost.org/apps", "code": "https://github.com/grafana/" }, "maintainer": { @@ -23,7 +21,7 @@ "url": "" }, "requirements": { - "yunohost": ">= 4.2.0" + "yunohost": ">= 4.2.0" }, "multi_instance": false, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh index 475ee41..f24fadf 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,6 +6,7 @@ # Debian package version for Grafana GRAFANA_VERSION="7.5.5" + # dependencies used by the app pkg_dependencies="influxdb" diff --git a/scripts/backup b/scripts/backup index 4a8ef29..7ff261f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# 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 @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= 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 @@ -32,33 +31,16 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP #================================================= ynh_print_info --message="Declaring files to be backed up..." -#================================================= -# BACKUP THE APP MAIN DIR -#================================================= - -ynh_backup --src_path="/etc/influxdb" -ynh_backup --src_path="/etc/grafana" -ynh_backup --src_path="/var/lib/grafana/plugins" - #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# BACKUP THE MYSQL DATABASE -#================================================= -ynh_print_info --message="Backing up the MySQL database..." - -# (However, things like mysql dumps *do* take some time to run, though the -# copy of the generated dump to the archive still happens later) -ynh_mysql_dump_db --database="$db_name" > db.sql - #================================================= # SPECIFIC BACKUP #================================================= @@ -86,6 +68,21 @@ if [ -d "/var/lib/influxdb/data/opentsdb" ]; then fi fi +#================================================= +# BACKUP VARIOUS FILES +#================================================= + +ynh_backup --src_path="/etc/influxdb" +ynh_backup --src_path="/etc/$app" +ynh_backup --src_path="/var/lib/grafana/plugins" + +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= +ynh_print_info --message="Backing up the MySQL database..." + +ynh_mysql_dump_db --database="$db_name" > db.sql + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index 95cfd7e..9a4369a 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -36,6 +36,7 @@ ynh_script_progression --message="Backing up the app before changing its URL (ma # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { + ynh_clean_check_starting # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" diff --git a/scripts/install b/scripts/install index c7dc5fb..bfb6ab7 100644 --- a/scripts/install +++ b/scripts/install @@ -14,8 +14,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -34,7 +33,6 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= - ynh_script_progression --message="Validating installation parameters..." --weight=1 # Register (book) web path @@ -54,7 +52,7 @@ ynh_app_setting_set --app=$app --key=admin --value=$admin #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Configuring port..." --weight=1 +ynh_script_progression --message="Finding an available port..." --weight=1 # Find an available port port=$(ynh_find_port --port=3000) @@ -78,23 +76,19 @@ db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= - -# None in this package (all APT-based) - #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 -# Create a dedicated nginx config +# Create a dedicated NGINX config ynh_add_nginx_config #================================================= # SPECIFIC SETUP #================================================= +# CONFIGURING GRAFANA AND INFLUXDB +#================================================= ynh_script_progression --message="Configuring Grafana and InfluxDB..." --weight=30 # If NetData is installed, configure it to feed InfluxDB @@ -211,6 +205,7 @@ systemctl enable grafana-server.service --quiet #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add influxdb --description="open source time series database" --log="/var/log/grafana/grafana.log" yunohost service add grafana-server --description="open source analytics and monitoring solution" --log="/var/log/grafana/grafana.log" @@ -230,7 +225,9 @@ ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary if [ $is_public -eq 1 ] then - ynh_permission_update --permission="main" --add="visitors" + # Everyone can access the app. + # The "main" permission is automatically created before the install script. + ynh_permission_update --permission="main" --add="visitors" fi #================================================= diff --git a/scripts/remove b/scripts/remove index 1108b04..15c499f 100644 --- a/scripts/remove +++ b/scripts/remove @@ -30,7 +30,7 @@ db_user=$db_name # Remove the service from the list of services known by Yunohost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status grafana-server >/dev/null then - ynh_script_progression --message="Removing grafana services..." --weight=1 + ynh_script_progression --message="Removing $app service integration..." --weight=1 yunohost service remove grafana-server yunohost service remove influxdb fi @@ -56,7 +56,7 @@ ynh_remove_app_dependencies #================================================= ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 -# Remove the dedicated nginx config +# Remove the dedicated NGINX config ynh_remove_nginx_config #================================================= diff --git a/scripts/restore b/scripts/restore index 4ae4573..aeff4d4 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# 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 @@ -15,8 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -46,6 +45,7 @@ ynh_webpath_available --domain=$domain --path_url=$path_url \ #================================================= # 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" @@ -61,9 +61,18 @@ ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://packages.grafana.com/oss/deb stable main" --package="grafana" --key="https://packages.grafana.com/gpg.key" #================================================= -# RESTORE THE APP CONFIGURATION +# RESTORE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Restoring configuration directories..." --weight=2 +ynh_script_progression --message="Restoring the MySQL database..." --weight=2 + +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 + +#================================================= +# RESTORE VARIOUS FILES +#================================================= +ynh_script_progression --message="Restoring various files..." --weight=2 ynh_restore_file --origin_path="/etc/influxdb" ynh_restore_file --origin_path="/etc/grafana" @@ -84,18 +93,10 @@ if [ "$(ls -A ./influxdb_data)" ] ; then fi fi -#================================================= -# RESTORE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Restoring the MySQL database..." --weight=2 - -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 - #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add influxdb --description="open source time series database" --log="/var/log/grafana/grafana.log" yunohost service add grafana-server --description="open source analytics and monitoring solution" --log="/var/log/grafana/grafana.log" diff --git a/scripts/upgrade b/scripts/upgrade index 69ecbba..6062c47 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,9 +27,27 @@ port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=4 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + ynh_clean_check_starting + # Restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# STANDARD UPGRADE STEPS #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -48,28 +66,12 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=4 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 -# Create a dedicated nginx config +# Create a dedicated NGINX config ynh_add_nginx_config #================================================= @@ -88,8 +90,10 @@ ynh_install_extra_app_dependencies --repo="deb https://packages.grafana.com/oss/ #================================================= # SPECIFIC UPGRADE #================================================= - +# CONFIGURING GRAFANA AND INFLUXDB +#================================================= ynh_script_progression --message="Configuring Grafana and InfluxDB..." --weight=3 + # If NetData is installed, configure it to feed InfluxDB if [ -d "/opt/netdata" ] ; then netdata_conf="/opt/netdata/etc/netdata/exporting.conf" @@ -156,6 +160,7 @@ ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add influxdb --description="open source time series database" --log="/var/log/grafana/grafana.log" yunohost service add grafana-server --description="open source analytics and monitoring solution" --log="/var/log/grafana/grafana.log" From 30f596390eea3733ef8972babc02c9bd44b50a61 Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sun, 22 Aug 2021 14:17:33 +0000 Subject: [PATCH 2/2] Auto-update README --- README.md | 2 -- README_fr.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/README.md b/README.md index 711695d..3333ff9 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,6 @@ LDAP and HTTP auth are supported. ## Documentation and resources * Official app website: https://grafana.com/ -* Official user documentation: https://yunohost.org/apps -* Official admin documentation: https://yunohost.org/packaging_apps * Upstream app code repository: https://github.com/grafana/ * YunoHost documentation for this app: https://yunohost.org/app_grafana * Report a bug: https://github.com/YunoHost-Apps/grafana_ynh/issues diff --git a/README_fr.md b/README_fr.md index 813d1fa..3b17a8f 100644 --- a/README_fr.md +++ b/README_fr.md @@ -62,8 +62,6 @@ LDAP and HTTP auth are supported. ## Documentations et ressources * Site officiel de l'app : https://grafana.com/ -* Documentation officielle utilisateur : https://yunohost.org/apps -* Documentation officielle de l'admin : https://yunohost.org/packaging_apps * Dépôt de code officiel de l'app : https://github.com/grafana/ * Documentation YunoHost pour cette app : https://yunohost.org/app_grafana * Signaler un bug : https://github.com/YunoHost-Apps/grafana_ynh/issues