1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/grafana_ynh.git synced 2024-09-03 20:36:29 +02:00

Merge pull request #43 from YunoHost-Apps/testing

Fix Level 2
This commit is contained in:
yalh76 2022-02-06 00:40:19 +01:00 committed by GitHub
commit 8fdf9516ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 42 deletions

View file

@ -1,11 +1,6 @@
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ { location __PATH__/ {
# Force usage of https
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
proxy_redirect off; proxy_redirect off;
proxy_set_header Host $host; proxy_set_header Host $host;

View file

@ -7,7 +7,6 @@
"fr": "Tableaux de bords de supervision" "fr": "Tableaux de bords de supervision"
}, },
"version": "8.3.3~ynh1", "version": "8.3.3~ynh1",
"license": "AGPL-3.0-only",
"url": "https://grafana.com/oss/grafana/", "url": "https://grafana.com/oss/grafana/",
"upstream": { "upstream": {
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
@ -15,13 +14,13 @@
"demo": "https://play.grafana.org", "demo": "https://play.grafana.org",
"code": "https://github.com/grafana/" "code": "https://github.com/grafana/"
}, },
"license": "AGPL-3.0-only",
"maintainer": { "maintainer": {
"name": "JimboJoe", "name": "JimboJoe",
"email": "jimmy@monin.net", "email": "jimmy@monin.net"
"url": ""
}, },
"requirements": { "requirements": {
"yunohost": ">= 4.2.0" "yunohost": ">= 4.3.0"
}, },
"multi_instance": false, "multi_instance": false,
"services": [ "services": [
@ -31,8 +30,7 @@
"install": [ "install": [
{ {
"name": "domain", "name": "domain",
"type": "domain", "type": "domain"
"example": "domain.org"
}, },
{ {
"name": "path", "name": "path",
@ -42,8 +40,7 @@
}, },
{ {
"name": "admin", "name": "admin",
"type": "user", "type": "user"
"example": "homer"
}, },
{ {
"name": "is_public", "name": "is_public",

View file

@ -29,7 +29,7 @@ ynh_script_progression --message="Loading installation settings..." --weight=1
port=$(ynh_app_setting_get --app=$app --key=port) port=$(ynh_app_setting_get --app=$app --key=port)
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#================================================= #=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=4 ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=4
@ -40,7 +40,7 @@ ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. # 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" ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails # Restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -78,19 +78,19 @@ ynh_script_progression --message="Updating NGINX web server configuration..." --
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the nginx config file # Change the path in the NGINX config file
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]
then then
# Make a backup of the original nginx config file if modified # Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path" ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper # Set global variables for NGINX helper
domain="$old_domain" domain="$old_domain"
path_url="$new_path" path_url="$new_path"
# Create a dedicated nginx config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
fi fi
# Change the domain for nginx # Change the domain for NGINX
if [ $change_domain -eq 1 ] if [ $change_domain -eq 1 ]
then then
# Delete file checksum for the old conf file location # Delete file checksum for the old conf file location
@ -103,8 +103,10 @@ fi
#================================================= #=================================================
# SPECIFIC MODIFICATIONS # SPECIFIC MODIFICATIONS
#================================================= #=================================================
# UPDATE GRAFANA CONFIGURATION
#=================================================
ynh_script_progression --message="Updating Grafana configuration..." --weight=1 ynh_script_progression --message="Updating Grafana configuration..." --weight=1
grafana_conf="/etc/grafana/grafana.ini" grafana_conf="/etc/grafana/grafana.ini"
# Set domain # Set domain
sed -i "/^\[server\]$/,/^\[/ s@domain = .*@domain = $new_domain@" $grafana_conf sed -i "/^\[server\]$/,/^\[/ s@domain = .*@domain = $new_domain@" $grafana_conf

View file

@ -185,15 +185,15 @@ ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<<
# Import default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701) # Import default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701)
# Remove new lines # Remove new lines
tr -d '\n' < ../conf/netdata_dashboard.json > dashboard.json tr -d '\n' < ../conf/netdata_dashboard.json > dashboard.json
# Fill the template with the defined data source # Fill the template with the defined data source
sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json
# Escape the dashboard definition for MySQL query (source: https://stackoverflow.com/a/4383994) # Escape the dashboard definition for MySQL query (source: https://stackoverflow.com/a/4383994)
dashboard=$(cat dashboard.json) dashboard=$(cat dashboard.json)
printf -v escaped_dashboard "%q" "$dashboard" printf -v escaped_dashboard "%q" "$dashboard"
# Import dashboard into MySQL # Import dashboard into MySQL
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard (id, version, slug, title, data, org_id, created, updated, uid) VALUES ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard (id, version, slug, title, data, org_id, created, updated, uid) VALUES
(99999, 0, 'NetData', 'NetData', \"$escaped_dashboard\", 1, '2020-05-16 14:36:50', '2020-05-16 14:36:50', 'yunohost');" (99999, 0, 'NetData', 'NetData', \"$escaped_dashboard\", 1, '2020-05-16 14:36:50', '2020-05-16 14:36:50', 'yunohost');"
# Add dashboard version # Add dashboard version
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard_version (id, dashboard_id, parent_version, restored_from, version, created, created_by, message, data) VALUES (99999, 99999, 0, 0, 1, '2020-05-16 14:36:50', 1, 'YunoHost installer', \"$escaped_dashboard\");" ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard_version (id, dashboard_id, parent_version, restored_from, version, created, created_by, message, data) VALUES (99999, 99999, 0, 0, 1, '2020-05-16 14:36:50', 1, 'YunoHost installer', \"$escaped_dashboard\");"
# Enable the systemd service so that InfluxDB and Grafana start at boot # Enable the systemd service so that InfluxDB and Grafana start at boot

View file

@ -43,14 +43,6 @@ ynh_script_progression --message="Removing the MySQL database..." --weight=3
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=26
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
@ -59,6 +51,14 @@ ynh_script_progression --message="Removing NGINX web server configuration..." --
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=26
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#================================================= #=================================================
# SPECIFIC REMOVE # SPECIFIC REMOVE
#================================================= #=================================================

View file

@ -66,6 +66,11 @@ if ynh_legacy_permissions_exists; then
ynh_app_setting_delete --app=$app --key=is_public ynh_app_setting_delete --app=$app --key=is_public
fi fi
# Migration: remove old repository if defined
if [ -f "/etc/apt/sources.list.d/grafana_stable.list" ] ; then
ynh_secure_remove --file="/etc/apt/sources.list.d/grafana_stable.list"
fi
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
@ -79,13 +84,8 @@ ynh_add_nginx_config
#================================================= #=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=12 ynh_script_progression --message="Upgrading dependencies..." --weight=12
# Migration: remove old repository if defined
if [ -f "/etc/apt/sources.list.d/grafana_stable.list" ] ; then
ynh_secure_remove --file="/etc/apt/sources.list.d/grafana_stable.list"
fi
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
ynh_install_extra_app_dependencies --repo="deb https://packages.grafana.com/oss/deb stable main" --package="grafana (>=$GRAFANA_VERSION)" --key="https://packages.grafana.com/gpg.key" ynh_install_extra_app_dependencies --repo="deb https://packages.grafana.com/oss/deb stable main" --package="grafana" --key="https://packages.grafana.com/gpg.key"
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
@ -145,12 +145,12 @@ fi
# Update default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701) # Update default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701)
# Remove new lines # Remove new lines
tr -d '\n' < ../conf/netdata_dashboard.json > dashboard.json tr -d '\n' < ../conf/netdata_dashboard.json > dashboard.json
# Fill the template with the defined data source # Fill the template with the defined data source
sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json
# Escape the dashboard definition for MySQL query # Escape the dashboard definition for MySQL query
dashboard=$(cat dashboard.json) dashboard=$(cat dashboard.json)
printf -v escaped_dashboard "%q" "$dashboard" printf -v escaped_dashboard "%q" "$dashboard"
# Import dashboard into MySQL # Import dashboard into MySQL
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "UPDATE dashboard set data=\"$escaped_dashboard\" WHERE id=99999;" ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "UPDATE dashboard set data=\"$escaped_dashboard\" WHERE id=99999;"
# Insert dashboard version if non existent (for downward compatibility) # Insert dashboard version if non existent (for downward compatibility)
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard_version (id, dashboard_id, parent_version, restored_from, version, created, created_by, message, data) VALUES (99999, 99999, 0, 0, 1, '2020-05-16 14:36:50', 1, 'YunoHost installer', \"$escaped_dashboard\");" > /dev/null 2>&1 || true ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard_version (id, dashboard_id, parent_version, restored_from, version, created, created_by, message, data) VALUES (99999, 99999, 0, 0, 1, '2020-05-16 14:36:50', 1, 'YunoHost installer', \"$escaped_dashboard\");" > /dev/null 2>&1 || true