mirror of
https://github.com/YunoHost-Apps/grafana_ynh.git
synced 2024-09-03 20:36:29 +02:00
[autopatch] Automatic patch attempt for helpers 2.1
This commit is contained in:
parent
9e7c0e5e6a
commit
e9bcc82e98
8 changed files with 80 additions and 147 deletions
|
@ -16,7 +16,8 @@ demo = "https://play.grafana.org"
|
|||
code = "https://github.com/grafana/grafana"
|
||||
|
||||
[integration]
|
||||
yunohost = ">= 11.2"
|
||||
yunohost = ">= 11.2.18"
|
||||
helpers_version = "2.1"
|
||||
architectures = "all"
|
||||
multi_instance = false
|
||||
|
||||
|
|
|
@ -1,17 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# FUTURE OFFICIAL HELPERS
|
||||
# COMMON VARIABLES AND CUSTOM HELPERS
|
||||
#=================================================
|
||||
|
|
|
@ -1,30 +1,21 @@
|
|||
#!/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
|
||||
|
||||
#=================================================
|
||||
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||
#=================================================
|
||||
ynh_print_info --message="Declaring files to be backed up..."
|
||||
ynh_print_info "Declaring files to be backed up..."
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC BACKUP
|
||||
#=================================================
|
||||
ynh_print_info --message="Backing up the InfluxDB database..."
|
||||
ynh_print_info "Backing up the InfluxDB database..."
|
||||
|
||||
# Backup InfluxDB data
|
||||
# Source: http://stackoverflow.com/questions/39501416/how-to-restore-data-base-using-influxd
|
||||
|
@ -32,16 +23,17 @@ mkdir influxdb_data
|
|||
# Backup only if database exists (compatible with automated tests where NetData is not present)
|
||||
# and if BACKUP_CORE_ONY/do_not_backup_data not set
|
||||
BACKUP_CORE_ONLY=${BACKUP_CORE_ONLY:-0}
|
||||
do_not_backup_data=$(ynh_app_setting_get --app=$app --key=do_not_backup_data)
|
||||
do_not_backup_data=$(ynh_app_setting_get --key=do_not_backup_data)
|
||||
|
||||
if [ -d "/var/lib/influxdb/data/opentsdb" ]; then
|
||||
if ( [ ${do_not_backup_data:-0} -eq 1 ] || [ $BACKUP_CORE_ONLY -eq 1 ] )
|
||||
|
||||
then
|
||||
if [ $BACKUP_CORE_ONLY -eq 1 ]
|
||||
then
|
||||
ynh_print_warn --message="The InfluxDB database will not be saved, because 'BACKUP_CORE_ONLY' is set."
|
||||
ynh_print_warn "The InfluxDB database will not be saved, because 'BACKUP_CORE_ONLY' is set."
|
||||
else
|
||||
ynh_print_warn --message="The InfluxDB database will not be saved, because 'do_not_backup_data' is set."
|
||||
ynh_print_warn "The InfluxDB database will not be saved, because 'do_not_backup_data' is set."
|
||||
fi
|
||||
else
|
||||
influxd backup -portable influxdb_data
|
||||
|
@ -52,19 +44,19 @@ fi
|
|||
# BACKUP VARIOUS FILES
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="/etc/influxdb"
|
||||
ynh_backup --src_path="/etc/$app"
|
||||
ynh_backup --src_path="/var/lib/grafana/plugins" --not_mandatory
|
||||
ynh_backup "/etc/influxdb"
|
||||
ynh_backup "/etc/$app"
|
||||
ynh_backup "/var/lib/grafana/plugins" || true
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE MYSQL DATABASE
|
||||
#=================================================
|
||||
ynh_print_info --message="Backing up the MySQL database..."
|
||||
ynh_print_info "Backing up the MySQL database..."
|
||||
|
||||
ynh_mysql_dump_db --database="$db_name" > db.sql
|
||||
ynh_mysql_dump_db > db.sql
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|
||||
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|
||||
|
|
|
@ -1,36 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# STOP SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping a systemd service..." --weight=2
|
||||
ynh_script_progression "Stopping $app's systemd service..."
|
||||
|
||||
ynh_systemd_action --service_name=grafana-server --action="stop" --log_path="/var/log/grafana/grafana.log"
|
||||
ynh_systemctl --service=grafana-server --action="stop" --log_path="/var/log/grafana/grafana.log"
|
||||
|
||||
#=================================================
|
||||
# MODIFY URL IN NGINX CONF
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
|
||||
ynh_script_progression "Updating NGINX web server configuration..."
|
||||
|
||||
ynh_change_url_nginx_config
|
||||
ynh_config_change_url_nginx
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC MODIFICATIONS
|
||||
#=================================================
|
||||
# UPDATE GRAFANA CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating Grafana configuration..." --weight=1
|
||||
ynh_script_progression "Updating Grafana configuration..."
|
||||
|
||||
grafana_conf="/etc/grafana/grafana.ini"
|
||||
# Set domain
|
||||
|
@ -44,18 +36,16 @@ else
|
|||
sed -i "/^\[server\]$/,/^\[/ s@serve_from_sub_path = .*@serve_from_sub_path = false@" $grafana_conf
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=2
|
||||
ynh_script_progression "Starting $app's systemd service..."
|
||||
|
||||
systemctl daemon-reload
|
||||
ynh_systemd_action --service_name=grafana-server --action="start" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
||||
ynh_systemctl --service=grafana-server --action="start" --log_path="/var/log/grafana/grafana.log" --wait_until="HTTP Server Listen" --timeout=600
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Change of URL completed for $app" --last
|
||||
ynh_script_progression "Change of URL completed for $app"
|
||||
|
|
|
@ -1,28 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
||||
ynh_script_progression "Configuring NGINX web server..."
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
ynh_config_add_nginx
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
# CONFIGURING GRAFANA AND INFLUXDB
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring Grafana and InfluxDB..." --weight=30
|
||||
ynh_script_progression "Configuring Grafana and InfluxDB..."
|
||||
|
||||
# If NetData is installed, configure it to feed InfluxDB
|
||||
if [ -d "/var/www/netdata/etc/netdata" ] ; then
|
||||
|
@ -51,36 +45,36 @@ if [ -d "/var/www/netdata/etc/netdata" ] ; then
|
|||
EOF
|
||||
fi
|
||||
# Restart NetData
|
||||
ynh_systemd_action --service_name=netdata --action="restart"
|
||||
ynh_systemctl --service=netdata --action="restart"
|
||||
fi
|
||||
|
||||
# Configure InfluxDB
|
||||
sed -i '/^\[\[opentsdb\]\]$/,/^\[/ s/^.* enabled = false/enabled = true/' /etc/influxdb/influxdb.conf
|
||||
|
||||
# Start InfluxDB server
|
||||
ynh_systemd_action --service_name=influxdb --action="restart"
|
||||
ynh_systemctl --service=influxdb --action="restart"
|
||||
|
||||
# Configure Grafana
|
||||
ynh_add_config --template="ldap.toml" --destination="/etc/grafana/ldap.toml"
|
||||
ynh_config_add --template="ldap.toml" --destination="/etc/grafana/ldap.toml"
|
||||
|
||||
ynh_add_config --template="grafana.ini" --destination="/etc/grafana/grafana.ini"
|
||||
ynh_config_add --template="grafana.ini" --destination="/etc/grafana/grafana.ini"
|
||||
|
||||
chmod 650 "/etc/grafana/grafana.ini"
|
||||
chown $app:$app "/etc/grafana/grafana.ini"
|
||||
|
||||
# Calculate and store the config file checksum into the app settings
|
||||
ynh_store_file_checksum --file="/etc/grafana/grafana.ini"
|
||||
ynh_store_file_checksum "/etc/grafana/grafana.ini"
|
||||
|
||||
# Start Grafana and wait for it to be fully started
|
||||
systemctl daemon-reload
|
||||
ynh_systemd_action --service_name=grafana-server --action="restart" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
||||
ynh_systemctl --service=grafana-server --action="restart" --log_path="/var/log/grafana/grafana.log" --wait_until="HTTP Server Listen" --timeout=600
|
||||
|
||||
# Change admin name to the specified one
|
||||
mail=$(ynh_user_get_info "$admin" 'mail')
|
||||
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "UPDATE user SET login=\"$admin\", email=\"$mail\" WHERE login=\"admin\";"
|
||||
ynh_mysql_db_shell <<< "UPDATE user SET login=\"$admin\", email=\"$mail\" WHERE login=\"admin\";"
|
||||
|
||||
# Create InfluxDB data source
|
||||
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO data_source (id, org_id, version, type, name, access, url, password, user, \`database\`, basic_auth, basic_auth_user, basic_auth_password, is_default, json_data, created, updated, with_credentials, secure_json_data) VALUES (99999, 1, 0, 'influxdb', 'InfluxDB', 'proxy', 'http://localhost:8086', '', '', 'opentsdb', 0, '', '', 0, '{\"tsdbResolution\":1,\"tsdbVersion\":1}', '2017-02-12 14:35:33', '2017-02-12 14:36:27', 0, '{}');"
|
||||
ynh_mysql_db_shell <<< "INSERT INTO data_source (id, org_id, version, type, name, access, url, password, user, \`database\`, basic_auth, basic_auth_user, basic_auth_password, is_default, json_data, created, updated, with_credentials, secure_json_data) VALUES (99999, 1, 0, 'influxdb', 'InfluxDB', 'proxy', 'http://localhost:8086', '', '', 'opentsdb', 0, '', '', 0, '{\"tsdbResolution\":1,\"tsdbVersion\":1}', '2017-02-12 14:35:33', '2017-02-12 14:36:27', 0, '{}');"
|
||||
|
||||
# Import default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701)
|
||||
# Remove new lines
|
||||
|
@ -91,21 +85,19 @@ sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json
|
|||
dashboard=$(cat dashboard.json)
|
||||
printf -v escaped_dashboard "%q" "$dashboard"
|
||||
# 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_db_shell <<< "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');"
|
||||
# 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_db_shell <<< "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
|
||||
systemctl enable influxdb.service --quiet
|
||||
systemctl enable grafana-server.service --quiet
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
ynh_script_progression "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"
|
||||
|
@ -113,13 +105,13 @@ yunohost service add grafana-server --description="open source analytics and mon
|
|||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=2
|
||||
ynh_script_progression "Starting $app's systemd service..."
|
||||
|
||||
systemctl daemon-reload
|
||||
ynh_systemd_action --service_name=grafana-server --action="restart" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
||||
ynh_systemctl --service=grafana-server --action="restart" --log_path="/var/log/grafana/grafana.log" --wait_until="HTTP Server Listen" --timeout=600
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Installation of $app completed" --last
|
||||
ynh_script_progression "Installation of $app completed"
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
|
@ -16,9 +10,9 @@ source /usr/share/yunohost/helpers
|
|||
#=================================================
|
||||
|
||||
# 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
|
||||
if ynh_hide_warnings yunohost service status grafana-server >/dev/null
|
||||
then
|
||||
ynh_script_progression --message="Removing $app service integration..." --weight=1
|
||||
ynh_script_progression "Removing $app service integration..."
|
||||
yunohost service remove grafana-server
|
||||
yunohost service remove influxdb
|
||||
fi
|
||||
|
@ -26,17 +20,17 @@ fi
|
|||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
|
||||
ynh_script_progression "Removing NGINX web server configuration..."
|
||||
|
||||
# Remove the dedicated NGINX config
|
||||
ynh_remove_nginx_config
|
||||
ynh_config_remove_nginx
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC REMOVE
|
||||
#=================================================
|
||||
# REMOVE VARIOUS FILES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing various files..."
|
||||
ynh_script_progression "Removing various files..."
|
||||
|
||||
# If NetData is installed, configure it not to feed InfluxDB any more
|
||||
netdata_conf="/var/www/netdata/etc/netdata/exporting.conf"
|
||||
|
@ -47,10 +41,10 @@ if [[ -f "$netdata_conf" ]] ; then
|
|||
}' $netdata_conf
|
||||
fi
|
||||
|
||||
ynh_secure_remove --file="/etc/grafana/grafana.ini"
|
||||
ynh_safe_rm "/etc/grafana/grafana.ini"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Removal of $app completed" --last
|
||||
ynh_script_progression "Removal of $app completed"
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
#!/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
|
||||
|
@ -13,36 +7,36 @@ source /usr/share/yunohost/helpers
|
|||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
#ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
||||
#ynh_script_progression "Validating restoration parameters..."
|
||||
#
|
||||
# This old test doesn't seem to make sense in packaging v2 anymore, because at this stage the apt dependencies are already installed, so yes /etc/influxdb exists ...
|
||||
# it's not clear what was really the intent
|
||||
#test ! -d "/etc/influxdb" || ynh_die --message="InfluxDB/Grafana are already installed"
|
||||
#test ! -d "/etc/influxdb" || ynh_die "InfluxDB/Grafana are already installed"
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the NGINX web server configuration..."
|
||||
ynh_script_progression "Restoring the NGINX web server configuration..."
|
||||
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the MySQL database..." --weight=2
|
||||
ynh_script_progression "Restoring the MySQL database..."
|
||||
|
||||
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
||||
ynh_mysql_db_shell < ./db.sql
|
||||
|
||||
#=================================================
|
||||
# RESTORE VARIOUS FILES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring various files..." --weight=2
|
||||
ynh_script_progression "Restoring various files..."
|
||||
|
||||
ynh_restore_file --origin_path="/etc/influxdb"
|
||||
ynh_restore_file --origin_path="/etc/grafana"
|
||||
ynh_restore_file --origin_path="/var/lib/grafana/plugins" --not_mandatory
|
||||
ynh_restore "/etc/influxdb"
|
||||
ynh_restore "/etc/grafana"
|
||||
ynh_restore "/var/lib/grafana/plugins" || true
|
||||
|
||||
# Set permission with the new grafana user (id could have been changed)
|
||||
chown -R root:grafana "/etc/grafana"
|
||||
|
@ -53,11 +47,11 @@ fi
|
|||
#=================================================
|
||||
# RESTORE THE INFLUXDB DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the InfluxDB database..." --weight=10
|
||||
ynh_script_progression "Restoring the InfluxDB database..."
|
||||
|
||||
# Restore InfluxDB data (only if backup not empty)
|
||||
# That happens when passing automated tests (NetData not present)
|
||||
ynh_systemd_action --service_name=influxdb --action="stop"
|
||||
ynh_systemctl --service=influxdb --action="stop"
|
||||
if [ "$(ls -A ./influxdb_data)" ] ; then
|
||||
influxd restore -portable ./influxdb_data
|
||||
fi
|
||||
|
@ -65,7 +59,7 @@ fi
|
|||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
ynh_script_progression "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"
|
||||
|
@ -73,27 +67,25 @@ yunohost service add grafana-server --description="open source analytics and mon
|
|||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
ynh_script_progression "Starting $app's systemd service..."
|
||||
|
||||
# Enable the systemd service so that InfluxDB and Grafana start at boot
|
||||
systemctl enable influxdb.service --quiet
|
||||
systemctl enable grafana-server.service --quiet
|
||||
|
||||
systemctl daemon-reload
|
||||
ynh_systemd_action --service_name=influxdb --action="start"
|
||||
ynh_systemd_action --service_name=grafana-server --action="start" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
||||
ynh_systemctl --service=influxdb --action="start"
|
||||
ynh_systemctl --service=grafana-server --action="start" --log_path="/var/log/grafana/grafana.log" --wait_until="HTTP Server Listen" --timeout=600
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX AND PHP-FPM
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
ynh_script_progression "Reloading NGINX web server..."
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
ynh_systemctl --service=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoration completed for $app" --last
|
||||
ynh_script_progression "Restoration completed for $app"
|
||||
|
|
|
@ -1,24 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# CHECK 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
|
||||
ynh_script_progression "Backing up the app before upgrading (may take a while)..."
|
||||
|
||||
# Workaround for missing "/var/lib/grafana/plugins"
|
||||
mkdir -p "/var/lib/grafana/plugins"
|
||||
|
@ -27,17 +15,15 @@ chown -R $app:$app "/var/lib/grafana/plugins"
|
|||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
||||
ynh_script_progression "Upgrading NGINX web server configuration..."
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
ynh_config_add_nginx
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
# CONFIGURING GRAFANA AND INFLUXDB
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring Grafana and InfluxDB..." --weight=3
|
||||
ynh_script_progression "Configuring Grafana and InfluxDB..."
|
||||
|
||||
# If NetData is installed, configure it to feed InfluxDB
|
||||
if [ -d "/var/www/netdata" ] ; then
|
||||
|
@ -84,14 +70,14 @@ EOF
|
|||
fi
|
||||
fi
|
||||
# Restart NetData
|
||||
ynh_systemd_action --service_name=netdata --action="restart"
|
||||
ynh_systemctl --service=netdata --action="restart"
|
||||
fi
|
||||
|
||||
# Fix configuration for Grafana instances existing prior to version 10
|
||||
sed -i "/^\[server\]$/,/^\[/ s@serve_from_sub_path = .*@serve_from_sub_path = false@" "/etc/grafana/grafana.ini"
|
||||
|
||||
# Update Grafana LDAP authentication configuration
|
||||
ynh_add_config --template="ldap.toml" --destination="/etc/grafana/ldap.toml"
|
||||
ynh_config_add --template="ldap.toml" --destination="/etc/grafana/ldap.toml"
|
||||
|
||||
# Update default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701)
|
||||
# Remove new lines
|
||||
|
@ -102,16 +88,14 @@ sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json
|
|||
dashboard=$(cat dashboard.json)
|
||||
printf -v escaped_dashboard "%q" "$dashboard"
|
||||
# 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_db_shell <<< "UPDATE dashboard set data=\"$escaped_dashboard\" WHERE id=99999;"
|
||||
# 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_db_shell <<< "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
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
||||
ynh_script_progression "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"
|
||||
|
@ -119,13 +103,13 @@ yunohost service add grafana-server --description="open source analytics and mon
|
|||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restarting a systemd service..." --weight=2
|
||||
ynh_script_progression "Restarting a systemd service..."
|
||||
|
||||
systemctl daemon-reload
|
||||
ynh_systemd_action --service_name=grafana-server --action="restart" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
||||
ynh_systemctl --service=grafana-server --action="restart" --log_path="/var/log/grafana/grafana.log" --wait_until="HTTP Server Listen" --timeout=600
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Upgrade of $app completed" --last
|
||||
ynh_script_progression "Upgrade of $app completed"
|
||||
|
|
Loading…
Reference in a new issue