Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[autopatch] Automatic patch attempt for helpers 2.1 #135

Open
wants to merge 1 commit into
base: testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 1 addition & 13 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
#!/bin/bash

#=================================================
# COMMON VARIABLES
#=================================================

#=================================================
# PERSONAL HELPERS
#=================================================

#=================================================
# EXPERIMENTAL HELPERS
#=================================================

#=================================================
# FUTURE OFFICIAL HELPERS
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
36 changes: 14 additions & 22 deletions scripts/backup
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
#!/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
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 ] )
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
Expand All @@ -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)."
26 changes: 8 additions & 18 deletions scripts/change_url
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
42 changes: 17 additions & 25 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -91,35 +85,33 @@ 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"

#=================================================
# 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"
20 changes: 7 additions & 13 deletions scripts/remove
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

Expand All @@ -16,27 +10,27 @@ 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

#=================================================
# 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"
Expand All @@ -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"
Loading