mirror of
https://github.com/YunoHost-Apps/grafana_ynh.git
synced 2024-09-03 20:36:29 +02:00
Complete refactoring + buster support
This commit is contained in:
parent
a6403c4481
commit
8832989ef4
17 changed files with 5664 additions and 548 deletions
19
CHANGELOG.md
Normal file
19
CHANGELOG.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
Changelog
|
||||||
|
=========
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
- Nothing for now...
|
||||||
|
|
||||||
|
## [6.7.3~ynh1](https://github.com/YunoHost-Apps/grafana_ynh/pull/21) - 2020-05-15
|
||||||
|
|
||||||
|
#### Added
|
||||||
|
* Add changelog
|
||||||
|
* Add issue template
|
||||||
|
|
||||||
|
#### Fixed
|
||||||
|
* fix buster support
|
||||||
|
|
||||||
|
#### Changed
|
||||||
|
* Use latest package guidelines
|
||||||
|
* Update default netdata dashboard
|
||||||
|
* Use Grafana official Debian repository for x86 and ARM
|
128
README.md
128
README.md
|
@ -1,15 +1,30 @@
|
||||||
Grafana for YunoHost
|
# Grafana app for YunoHost
|
||||||
-----------------------------
|
|
||||||
[![Install Grafana with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=grafana)
|
|
||||||
|
|
||||||
[![Integration level](https://dash.yunohost.org/integration/grafana.svg)](https://ci-apps.yunohost.org/jenkins/job/grafana%20%28Community%29/lastBuild/consoleFull)
|
[![Integration level](https://dash.yunohost.org/integration/grafana.svg)](https://dash.yunohost.org/appci/app/grafana)
|
||||||
|
[![Install grafana with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=grafana)
|
||||||
|
|
||||||
|
> *This package allows you to install grafana quickly and simply on a YunoHost server.
|
||||||
|
If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.*
|
||||||
|
|
||||||
|
## Overview
|
||||||
**Important: This package is designed to be fed by the NetData application for monitoring measures, so please make sure the YunoHost [NetData package](https://github.com/YunoHost-Apps/netdata_ynh/) is installed before installing it!**
|
**Important: This package is designed to be fed by the NetData application for monitoring measures, so please make sure the YunoHost [NetData package](https://github.com/YunoHost-Apps/netdata_ynh/) is installed before installing it!**
|
||||||
|
|
||||||
NetData only collects, displays and sets alarms based on data from the last hour; this packages allows to archive every metrics and put up statistics and dashboards on the long term.
|
NetData only collects, displays and sets alarms based on data from the last hour; this packages allows to archive every metrics and put up statistics and dashboards on the long term.
|
||||||
|
|
||||||
Note: You can use it without NetData, but you'll have to install a collection application (e.g. collectd) to gather data.
|
Note: You can use it without NetData, but you'll have to install a collection application (e.g. collectd) to gather data.
|
||||||
|
|
||||||
|
**Shipped version:** 6.7.3
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|
![](https://grafana.com/api/dashboards/1295/images/838/image)
|
||||||
|
|
||||||
|
## Demo
|
||||||
|
|
||||||
|
* [Official demo](https://play.grafana.org)
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
**Important at first login:**
|
**Important at first login:**
|
||||||
|
|
||||||
* you have to go the Grafana Menu (Grafana icon), select your account menu and select *Switch to Main Org.*
|
* you have to go the Grafana Menu (Grafana icon), select your account menu and select *Switch to Main Org.*
|
||||||
|
@ -17,13 +32,13 @@ Note: You can use it without NetData, but you'll have to install a collection ap
|
||||||
|
|
||||||
**Don't hesitate to create new dashboards**: the default dashboard contains metrics from NetData, but only generic ones that are generated on every machine. NetData dynamically detects services and applications (e.g.redis, nginx, etc.) and enriches its dashboard and generated metrics. Many NetData metrics don't appear in the provided default Grafana dashboard!
|
**Don't hesitate to create new dashboards**: the default dashboard contains metrics from NetData, but only generic ones that are generated on every machine. NetData dynamically detects services and applications (e.g.redis, nginx, etc.) and enriches its dashboard and generated metrics. Many NetData metrics don't appear in the provided default Grafana dashboard!
|
||||||
|
|
||||||
**Warnings**:
|
## Documentation
|
||||||
|
|
||||||
* The default dashboard may be updated in a further release of this package, so please make sure you create your own dashboards!
|
* Official Grafana documentation: https://grafana.com/docs/grafana/latest/
|
||||||
* Organizations creation doesn't play well with LDAP integration; it is disabled for standard users, but can't be disabled for administrators: **please do not create organizations**!
|
* Official InfluxdB documentation: https://docs.influxdata.com/influxdb/
|
||||||
|
* YunoHost documentation: If specific documentation is needed, feel free to contribute.
|
||||||
|
|
||||||
---
|
## YunoHost specific features
|
||||||
# Package description:
|
|
||||||
|
|
||||||
* installs InfluxDB as time series database
|
* installs InfluxDB as time series database
|
||||||
* if the NetData package is installed, configures NetData to feed InfluxDB every minute
|
* if the NetData package is installed, configures NetData to feed InfluxDB every minute
|
||||||
|
@ -31,83 +46,48 @@ Note: You can use it without NetData, but you'll have to install a collection ap
|
||||||
* creates a Grafana Data Source to fetch data from InfluxDB (and hence NetData!)
|
* creates a Grafana Data Source to fetch data from InfluxDB (and hence NetData!)
|
||||||
* creates a default dashboard to plot some data from NetData (doesn't cover every metric, can be greatly enhanced!)
|
* creates a default dashboard to plot some data from NetData (doesn't cover every metric, can be greatly enhanced!)
|
||||||
|
|
||||||
It has been tested on x86_64 and ARM.
|
#### General architecture
|
||||||
|
|
||||||
## General architecture
|
|
||||||
|
|
||||||
![image](https://cloud.githubusercontent.com/assets/2662304/20649711/29f182ba-b4ce-11e6-97c8-ab2c0ab59833.png)
|
![image](https://cloud.githubusercontent.com/assets/2662304/20649711/29f182ba-b4ce-11e6-97c8-ab2c0ab59833.png)
|
||||||
|
|
||||||
|
#### Multi-users support
|
||||||
|
|
||||||
---
|
LDAP and HTTP auth are supported.
|
||||||
# InfluxDB
|
|
||||||
InfluxDB is an open source **time series database** with
|
|
||||||
**no external dependencies**. It's useful for recording metrics,
|
|
||||||
events, and performing analytics.
|
|
||||||
|
|
||||||
**Shipped version:** versions from Debian repositories (updated with the system)
|
#### Supported architectures
|
||||||
|
|
||||||
## Features
|
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/grafana%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/grafana/)
|
||||||
|
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/grafana%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/grafana/)
|
||||||
|
|
||||||
* Built-in [HTTP API](https://docs.influxdata.com/influxdb/latest/guides/writing_data/) so you don't have to write any server side code to get up and running.
|
## Limitations
|
||||||
* Data can be tagged, allowing very flexible querying.
|
|
||||||
* SQL-like query language.
|
|
||||||
* Simple to install and manage, and fast to get data in and out.
|
|
||||||
* It aims to answer queries in real-time. That means every data point is
|
|
||||||
indexed as it comes in and is immediately available in queries that
|
|
||||||
should return in < 100ms.
|
|
||||||
|
|
||||||
---
|
* The default dashboard may be updated in a further release of this package, so please make sure you create your own dashboards!
|
||||||
# Grafana
|
* Organizations creation doesn't play well with LDAP integration; it is disabled for standard users, but can't be disabled for administrators: **please do not create organizations**!
|
||||||
|
|
||||||
Grafana is an open source, feature rich metrics dashboard and graph editor for
|
## Additional information
|
||||||
Graphite, Elasticsearch, OpenTSDB, Prometheus and InfluxDB.
|
|
||||||
|
|
||||||
![](http://grafana.org/assets/img/features/dashboard_ex1.png)
|
None.
|
||||||
|
|
||||||
## Features
|
## Links
|
||||||
### Graphite Target Editor
|
|
||||||
- Graphite target expression parser
|
|
||||||
- Feature rich query composer
|
|
||||||
- Quickly add and edit functions & parameters
|
|
||||||
- Templated queries
|
|
||||||
- [See it in action](http://docs.grafana.org/datasources/graphite/)
|
|
||||||
|
|
||||||
### Graphing
|
|
||||||
- Fast rendering, even over large timespans
|
|
||||||
- Click and drag to zoom
|
|
||||||
- Multiple Y-axis, logarithmic scales
|
|
||||||
- Bars, Lines, Points
|
|
||||||
- Smart Y-axis formatting
|
|
||||||
- Series toggles & color selector
|
|
||||||
- Legend values, and formatting options
|
|
||||||
- Grid thresholds, axis labels
|
|
||||||
- [Annotations](http://docs.grafana.org/reference/annotations/)
|
|
||||||
- Any panel can be rendered to PNG (server side using phantomjs)
|
|
||||||
|
|
||||||
### Dashboards
|
|
||||||
- Create, edit, save & search dashboards
|
|
||||||
- Change column spans and row heights
|
|
||||||
- Drag and drop panels to rearrange
|
|
||||||
- [Templating](http://docs.grafana.org/reference/templating/)
|
|
||||||
- [Scripted dashboards](http://docs.grafana.org/reference/scripting/)
|
|
||||||
- [Dashboard playlists](http://docs.grafana.org/reference/playlist/)
|
|
||||||
- [Time range controls](http://docs.grafana.org/reference/timerange/)
|
|
||||||
- [Share snapshots publicly](http://docs.grafana.org/v2.0/reference/sharing/)
|
|
||||||
|
|
||||||
### Elasticsearch
|
|
||||||
- Feature rich query editor UI
|
|
||||||
|
|
||||||
### InfluxDB
|
|
||||||
- Use InfluxDB as a metric data source, annotation source
|
|
||||||
- Query editor with series and column typeahead, easy group by and function selection
|
|
||||||
|
|
||||||
### OpenTSDB
|
|
||||||
- Use as metric data source
|
|
||||||
- Query editor with metric name typeahead and tag filtering
|
|
||||||
|
|
||||||
# Links
|
|
||||||
|
|
||||||
* Report a bug: https://github.com/YunoHost-Apps/grafana_ynh/issues
|
* Report a bug: https://github.com/YunoHost-Apps/grafana_ynh/issues
|
||||||
|
* Grafana website: https://grafana.com/
|
||||||
|
* Grafana upstream app repository: https://github.com/grafana/
|
||||||
* InfluxDB website: https://www.influxdata.com/
|
* InfluxDB website: https://www.influxdata.com/
|
||||||
* Grafana website: http://grafana.org/
|
* InfluxDB upstream app repository: https://github.com/influxdata/influxdb
|
||||||
* YunoHost website: https://yunohost.org/
|
* YunoHost website: https://yunohost.org/
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Developers info
|
||||||
|
----------------
|
||||||
|
|
||||||
|
**Only if you want to use a testing branch for coding, instead of merging directly into master.**
|
||||||
|
Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/grafana_ynh/tree/testing).
|
||||||
|
|
||||||
|
To try the testing branch, please proceed like that.
|
||||||
|
```
|
||||||
|
sudo yunohost app install https://github.com/YunoHost-Apps/grafana_ynh/tree/testing --debug
|
||||||
|
or
|
||||||
|
sudo yunohost app upgrade grafana -u https://github.com/YunoHost-Apps/grafana_ynh/tree/testing --debug
|
||||||
|
```
|
||||||
|
|
|
@ -18,20 +18,9 @@
|
||||||
multi_instance=0
|
multi_instance=0
|
||||||
incorrect_path=1
|
incorrect_path=1
|
||||||
port_already_use=1
|
port_already_use=1
|
||||||
change_url=0
|
change_url=1
|
||||||
;;; Levels
|
;;; Levels
|
||||||
Level 1=auto
|
Level 5=auto
|
||||||
Level 2=auto
|
|
||||||
Level 3=auto
|
|
||||||
# https://github.com/YunoHost-Apps/grafana_ynh/issues/4
|
|
||||||
Level 4=1
|
|
||||||
# https://github.com/YunoHost-Apps/grafana_ynh/issues/5
|
|
||||||
Level 5=1
|
|
||||||
Level 6=auto
|
|
||||||
Level 7=auto
|
|
||||||
Level 8=0
|
|
||||||
Level 9=0
|
|
||||||
Level 10=0
|
|
||||||
;;; Options
|
;;; Options
|
||||||
Email=
|
Email=
|
||||||
Notification=none
|
Notification=none
|
||||||
|
|
File diff suppressed because one or more lines are too long
4806
conf/netdata_dashboard.json
Normal file
4806
conf/netdata_dashboard.json
Normal file
File diff suppressed because it is too large
Load diff
28
conf/nginx.conf
Normal file
28
conf/nginx.conf
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
|
||||||
|
location __PATH__/ {
|
||||||
|
|
||||||
|
# Force usage of https
|
||||||
|
if ($scheme = http) {
|
||||||
|
rewrite ^ https://$server_name$request_uri? permanent;
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy_redirect off;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
|
||||||
|
proxy_set_header X-Forwarded-Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Server $host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-WEBAUTH-USER $remote_user;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_pass_request_headers on;
|
||||||
|
proxy_set_header Connection "keep-alive";
|
||||||
|
proxy_store off;
|
||||||
|
proxy_pass http://127.0.0.1:__PORT__/;
|
||||||
|
|
||||||
|
gzip on;
|
||||||
|
gzip_proxied any;
|
||||||
|
gzip_types *;
|
||||||
|
|
||||||
|
# Include SSOWAT user panel.
|
||||||
|
include conf.d/yunohost_panel.conf.inc;
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
location / {
|
|
||||||
proxy_set_header X-Forwarded-Host $host;
|
|
||||||
proxy_set_header X-Forwarded-Server $host;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-WEBAUTH-USER $remote_user;
|
|
||||||
proxy_pass http://127.0.0.1:YNH_WWW_PORT;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_pass_request_headers on;
|
|
||||||
proxy_set_header Connection "keep-alive";
|
|
||||||
proxy_store off;
|
|
||||||
|
|
||||||
# Include SSOWAT user panel.
|
|
||||||
include conf.d/yunohost_panel.conf.inc;
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
location YNH_WWW_PATH {
|
|
||||||
return 301 YNH_WWW_PATH/;
|
|
||||||
}
|
|
||||||
|
|
||||||
location ~ YNH_WWW_PATH/(?<ndpath>.*) {
|
|
||||||
proxy_redirect off;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
|
|
||||||
proxy_set_header X-Forwarded-Host $host;
|
|
||||||
proxy_set_header X-Forwarded-Server $host;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-WEBAUTH-USER $remote_user;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_pass_request_headers on;
|
|
||||||
proxy_set_header Connection "keep-alive";
|
|
||||||
proxy_store off;
|
|
||||||
proxy_pass http://127.0.0.1:YNH_WWW_PORT/$ndpath$is_args$args;
|
|
||||||
|
|
||||||
gzip on;
|
|
||||||
gzip_proxied any;
|
|
||||||
gzip_types *;
|
|
||||||
|
|
||||||
# Include SSOWAT user panel.
|
|
||||||
include conf.d/yunohost_panel.conf.inc;
|
|
||||||
}
|
|
46
issue_template.md
Normal file
46
issue_template.md
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us debug, it would be nice to fill the template as much as you can to help us, help you and help us all.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**How to post a meaningful bug report**
|
||||||
|
1. *Read this whole template first.*
|
||||||
|
2. *Determine if you are on the right place:*
|
||||||
|
- *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change url...), you are on the right place!*
|
||||||
|
- *Otherwise, the issue may be due to Grafana or InfluxDB themselves. Refer to its documentation or repository for help.*
|
||||||
|
- *If you have a doubt, post here, we will figure it out together.*
|
||||||
|
3. *Delete the italic comments as you write over them below, and remove this guide.*
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
*A clear and concise description of what the bug is.*
|
||||||
|
|
||||||
|
**Versions**
|
||||||
|
- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...*
|
||||||
|
- YunoHost version: x.x.x
|
||||||
|
- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...*
|
||||||
|
- Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?: *no / yes*
|
||||||
|
- If yes, please explain:
|
||||||
|
- Using, or trying to install package version/branch:
|
||||||
|
- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`*
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
*Steps to reproduce the behavior.*
|
||||||
|
- *If you performed a command from the CLI, the command itself is enough. For example:*
|
||||||
|
```sh
|
||||||
|
sudo yunohost app install grafana
|
||||||
|
```
|
||||||
|
- *If you used the webadmin, please perform the equivalent command from the CLI first.*
|
||||||
|
- *If the error occurs in your browser, explain what you did:*
|
||||||
|
1. *Go to '...'*
|
||||||
|
2. *Click on '....'*
|
||||||
|
3. *Scroll down to '....'*
|
||||||
|
4. *See error*
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.*
|
||||||
|
|
||||||
|
**Logs**
|
||||||
|
*After a failed command, YunoHost makes the log available to you, but also to others, thanks to `yunohost log display [log name] --share`. The actual command, with the correct log name, is displayed at the end of the failed attempt in the CLI. Execute it and copy here the share link it outputs.*
|
||||||
|
*If applicable and useful, add screenshots to help explain your problem.*
|
|
@ -6,7 +6,7 @@
|
||||||
"en": "Beautiful metric & analytic dashboards for monitoring",
|
"en": "Beautiful metric & analytic dashboards for monitoring",
|
||||||
"fr": "Tableaux de bords de supervision"
|
"fr": "Tableaux de bords de supervision"
|
||||||
},
|
},
|
||||||
"version": "1.2.0~ynh1",
|
"version": "6.7.3~ynh1",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"url": "http://grafana.org/",
|
"url": "http://grafana.org/",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
"url": ""
|
"url": ""
|
||||||
},
|
},
|
||||||
"requirements": {
|
"requirements": {
|
||||||
"yunohost": ">= 3.0.0"
|
"yunohost": ">= 3.8.1"
|
||||||
},
|
},
|
||||||
"multi_instance": false,
|
"multi_instance": false,
|
||||||
"services": [
|
"services": [
|
||||||
|
@ -43,15 +43,6 @@
|
||||||
"example": "/grafana",
|
"example": "/grafana",
|
||||||
"default": "/grafana"
|
"default": "/grafana"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "port",
|
|
||||||
"ask": {
|
|
||||||
"en": "Choose a port for your server. Let as default if you don't want to change it",
|
|
||||||
"fr": "Entrez un port pour votre serveur. Laissez par défaut si vous ne voulez pas en changer"
|
|
||||||
},
|
|
||||||
"example": "3000",
|
|
||||||
"default": "3000"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "admin",
|
"name": "admin",
|
||||||
"type": "user",
|
"type": "user",
|
||||||
|
|
|
@ -1,131 +1,20 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
|
||||||
# Common variables
|
|
||||||
#
|
|
||||||
GRAFANA_REPOSITORY="/etc/apt/sources.list.d/grafana_stable.list"
|
|
||||||
|
|
||||||
#
|
#=================================================
|
||||||
# Common helpers
|
# COMMON VARIABLES
|
||||||
#
|
#=================================================
|
||||||
|
|
||||||
# Fix path if needed
|
# dependencies used by the app
|
||||||
# usage: fix_patch PATH_TO_FIX
|
pkg_dependencies="influxdb"
|
||||||
fix_path() {
|
|
||||||
local path=$1
|
|
||||||
if [ "${path:0:1}" != "/" ] && [ ${#path} -gt 0 ]; then
|
|
||||||
path="/$path"
|
|
||||||
fi
|
|
||||||
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then
|
|
||||||
path="${path:0:${#path}-1}"
|
|
||||||
fi
|
|
||||||
echo "$path"
|
|
||||||
}
|
|
||||||
# Install needed repositories and install dependencies
|
|
||||||
# usage: install_dependencies
|
|
||||||
install_dependencies() {
|
|
||||||
# Install needed dependency for HTTPS apt access
|
|
||||||
# (that dependency could be handled upstream in YunoHost)
|
|
||||||
ynh_package_install apt-transport-https
|
|
||||||
|
|
||||||
# Test repositories existence, in case of failed installation
|
#=================================================
|
||||||
grafana_repository_present=""
|
# PERSONAL HELPERS
|
||||||
[[ -f $GRAFANA_REPOSITORY ]] && grafana_repository_present="true"
|
#=================================================
|
||||||
|
|
||||||
# Install needed apt repository for Grafana
|
#=================================================
|
||||||
machine=$(uname -m)
|
# EXPERIMENTAL HELPERS
|
||||||
# Add the repos depending on processor architecture
|
#=================================================
|
||||||
|
|
||||||
if [[ "$machine" =~ "armv6" ]] ; then
|
#=================================================
|
||||||
# For ARM, use fg2it repository
|
# FUTURE OFFICIAL HELPERS
|
||||||
# https://github.com/fg2it/grafana-on-raspberry
|
#=================================================
|
||||||
curl https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
|
|
||||||
echo "deb http://dl.bintray.com/fg2it/deb-rpi-1b stretch main" | sudo tee $GRAFANA_REPOSITORY
|
|
||||||
else
|
|
||||||
# x86 processor --> we use the official repository
|
|
||||||
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
|
|
||||||
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee $GRAFANA_REPOSITORY
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install packages
|
|
||||||
# We install them as dependencies as they may already be installed and used for other purposes
|
|
||||||
ynh_install_app_dependencies influxdb, grafana \
|
|
||||||
|| {
|
|
||||||
# Remove apt repositories if they were added
|
|
||||||
[[ -n "$grafana_repository_present" ]] && sudo rm $GRAFANA_REPOSITORY
|
|
||||||
ynh_die "Unable to install Debian packages"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# ======== Future YunoHost helpers ========
|
|
||||||
|
|
||||||
# Delete a file checksum from the app settings
|
|
||||||
#
|
|
||||||
# $app should be defined when calling this helper
|
|
||||||
#
|
|
||||||
# usage: ynh_remove_file_checksum file
|
|
||||||
# | arg: file - The file for which the checksum will be deleted
|
|
||||||
ynh_delete_file_checksum () {
|
|
||||||
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
|
|
||||||
ynh_app_setting_delete $app $checksum_setting_name
|
|
||||||
}
|
|
||||||
|
|
||||||
# Start or restart a service and follow its booting
|
|
||||||
#
|
|
||||||
# usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name]
|
|
||||||
#
|
|
||||||
# | arg: Line to match - The line to find in the log to attest the service have finished to boot.
|
|
||||||
# | arg: Log file - The log file to watch; specify "systemd" to read systemd journal for specified service
|
|
||||||
# /var/log/$app/$app.log will be used if no other log is defined.
|
|
||||||
# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds.
|
|
||||||
# | arg: Service name
|
|
||||||
ynh_check_starting () {
|
|
||||||
local line_to_match="$1"
|
|
||||||
local service_name="${4:-$app}"
|
|
||||||
local app_log="${2:-/var/log/$service_name/$service_name.log}"
|
|
||||||
local timeout=${3:-300}
|
|
||||||
|
|
||||||
echo "Starting of $service_name" >&2
|
|
||||||
systemctl stop $service_name
|
|
||||||
local templog="$(mktemp)"
|
|
||||||
# Following the starting of the app in its log
|
|
||||||
if [ "$app_log" == "systemd" ] ; then
|
|
||||||
# Read the systemd journal
|
|
||||||
journalctl -u $service_name -f --since=-45 > "$templog" &
|
|
||||||
else
|
|
||||||
# Read the specified log file
|
|
||||||
tail -F -n0 "$app_log" > "$templog" &
|
|
||||||
fi
|
|
||||||
# Get the PID of the last command
|
|
||||||
local pid_tail=$!
|
|
||||||
systemctl start $service_name
|
|
||||||
|
|
||||||
local i=0
|
|
||||||
for i in `seq 1 $timeout`
|
|
||||||
do
|
|
||||||
# Read the log until the sentence is found, which means the app finished starting. Or run until the timeout.
|
|
||||||
if grep --quiet "$line_to_match" "$templog"
|
|
||||||
then
|
|
||||||
echo "The service $service_name has correctly started." >&2
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
echo -n "." >&2
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
if [ $i -eq $timeout ]
|
|
||||||
then
|
|
||||||
echo "The service $service_name didn't fully start before the timeout." >&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
ynh_clean_check_starting
|
|
||||||
}
|
|
||||||
# Clean temporary process and file used by ynh_check_starting
|
|
||||||
# (usually used in ynh_clean_setup scripts)
|
|
||||||
#
|
|
||||||
# usage: ynh_clean_check_starting
|
|
||||||
|
|
||||||
ynh_clean_check_starting () {
|
|
||||||
# Stop the execution of tail.
|
|
||||||
kill -s 15 $pid_tail 2>&1
|
|
||||||
ynh_secure_remove "$templog" 2>&1
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,48 +1,91 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if [ ! -e _common.sh ]; then
|
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
# Fetch helpers file if not in current directory
|
source ../settings/scripts/_common.sh
|
||||||
cp ../settings/scripts/_common.sh ./_common.sh
|
|
||||||
chmod a+rx _common.sh
|
|
||||||
fi
|
|
||||||
source _common.sh
|
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# MANAGE SCRIPT FAILURE
|
# 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
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Source YunoHost helpers
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
source /usr/share/yunohost/helpers
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
|
|
||||||
# Backup configuration files
|
#=================================================
|
||||||
ynh_backup "/etc/influxdb" "conf_influxdb"
|
# STANDARD BACKUP STEPS
|
||||||
ynh_backup "/etc/grafana" "conf_grafana"
|
#=================================================
|
||||||
ynh_backup "/var/lib/grafana/plugins" "conf_grafana_plugins"
|
# STOP SYSTEMD SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name="grafana-server" --action="stop" --log_path="/var/log/grafana/grafana.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Backing up configuration directories..." --weight=1
|
||||||
|
|
||||||
|
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_script_progression --message="Backing up nginx web server configuration..." --weight=1
|
||||||
|
|
||||||
|
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Backing up the MySQL database..." --weight=2
|
||||||
|
|
||||||
|
ynh_mysql_dump_db --database="$db_name" > db.sql
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC BACKUP
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Backing up the InfluxDB database..." --weight=10
|
||||||
# Backup InfluxDB data
|
# Backup InfluxDB data
|
||||||
# Source: http://stackoverflow.com/questions/39501416/how-to-restore-data-base-using-influxd
|
# Source: http://stackoverflow.com/questions/39501416/how-to-restore-data-base-using-influxd
|
||||||
mkdir influxdb_data
|
mkdir influxdb_data
|
||||||
influxd backup -database opentsdb influxdb_data
|
# Backup only if database exists
|
||||||
|
# That happens when passing automated tests (NetData not present)
|
||||||
|
if [ -d "/var/lib/influxdb/data/opentsdb" ]; then
|
||||||
|
influxd backup -database opentsdb influxdb_data
|
||||||
|
fi
|
||||||
|
|
||||||
# Dump the Grafana database
|
#=================================================
|
||||||
dbname=$app
|
# START SYSTEMD SERVICE
|
||||||
dbuser=$app
|
#=================================================
|
||||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||||
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
|
|
||||||
|
|
||||||
# Copy NGINX configuration
|
ynh_systemd_action --service_name="grafana-server" --action="start" --log_path="/var/log/grafana/grafana.log"
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
|
||||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last
|
||||||
|
|
139
scripts/change_url
Normal file
139
scripts/change_url
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC STARTING
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RETRIEVE ARGUMENTS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
old_domain=$YNH_APP_OLD_DOMAIN
|
||||||
|
old_path=$YNH_APP_OLD_PATH
|
||||||
|
|
||||||
|
new_domain=$YNH_APP_NEW_DOMAIN
|
||||||
|
new_path=$YNH_APP_NEW_PATH
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||||
|
|
||||||
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --weight=4
|
||||||
|
|
||||||
|
# Backup the current version of the app
|
||||||
|
ynh_backup_before_upgrade
|
||||||
|
ynh_clean_setup () {
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
# restore it if the upgrade fails
|
||||||
|
ynh_restore_upgradebackup
|
||||||
|
}
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHECK WHICH PARTS SHOULD BE CHANGED
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
change_domain=0
|
||||||
|
if [ "$old_domain" != "$new_domain" ]
|
||||||
|
then
|
||||||
|
change_domain=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
change_path=0
|
||||||
|
if [ "$old_path" != "$new_path" ]
|
||||||
|
then
|
||||||
|
change_path=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD MODIFICATIONS
|
||||||
|
#=================================================
|
||||||
|
# STOP SYSTEMD SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Stopping a systemd service..." --weight=2
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=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
|
||||||
|
|
||||||
|
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||||
|
|
||||||
|
# Change the path in the nginx config file
|
||||||
|
if [ $change_path -eq 1 ]
|
||||||
|
then
|
||||||
|
# Make a backup of the original nginx config file if modified
|
||||||
|
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
|
||||||
|
# Set global variables for nginx helper
|
||||||
|
domain="$old_domain"
|
||||||
|
path_url="$new_path"
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Change the domain for nginx
|
||||||
|
if [ $change_domain -eq 1 ]
|
||||||
|
then
|
||||||
|
# Delete file checksum for the old conf file location
|
||||||
|
ynh_delete_file_checksum --file="$nginx_conf_path"
|
||||||
|
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||||
|
# Store file checksum for the new config file location
|
||||||
|
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC MODIFICATIONS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Updating Grafana configuration..." --weight=1
|
||||||
|
grafana_conf="/etc/grafana/grafana.ini"
|
||||||
|
# Set domain
|
||||||
|
sed -i "/^\[server\]$/,/^\[/ s@domain = .*@domain = $new_domain@" $grafana_conf
|
||||||
|
# Set final URL
|
||||||
|
sed -i "/^\[server\]$/,/^\[/ s@root_url = .*@root_url = https://$new_domain$new_path@" $grafana_conf
|
||||||
|
# Specify if using sub_path
|
||||||
|
if [ "$new_path" != "/" ]; then
|
||||||
|
sed -i "/^\[server\]$/,/^\[/ s@serve_from_sub_path = .*@serve_from_sub_path = true@" $grafana_conf
|
||||||
|
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_systemd_action --service_name=grafana-server --action="start" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Change of URL completed for $app" --last
|
244
scripts/install
244
scripts/install
|
@ -1,9 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
shopt -s extglob # sets extended pattern matching options in the bash shell
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC STARTING
|
# GENERIC START
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -15,50 +13,100 @@ source /usr/share/yunohost/helpers
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_abort_if_errors # Stop script if an error is detected
|
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
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
|
||||||
|
|
||||||
# Retrieve arguments
|
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path=$YNH_APP_ARG_PATH
|
path_url=$YNH_APP_ARG_PATH
|
||||||
port=$(ynh_find_port $YNH_APP_ARG_PORT)
|
|
||||||
admin=$YNH_APP_ARG_ADMIN
|
admin=$YNH_APP_ARG_ADMIN
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
|
|
||||||
# Source YunoHost helpers
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
source /usr/share/yunohost/helpers
|
|
||||||
|
|
||||||
# Fix path if needed
|
#=================================================
|
||||||
path=$(fix_path $path)
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Check domain/path availability
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
|
||||||
|
|
||||||
# Save app settings
|
# Register (book) web path
|
||||||
ynh_app_setting_set "$app" admin "$admin"
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
||||||
ynh_app_setting_set "$app" is_public "$is_public"
|
|
||||||
ynh_app_setting_set "$app" port "$port"
|
|
||||||
|
|
||||||
# Install dependencies
|
#=================================================
|
||||||
install_dependencies
|
# STORE SETTINGS FROM MANIFEST
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Storing installation settings..." --weight=2
|
||||||
|
|
||||||
# Declare services for YunoHost monitoring
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
||||||
sudo yunohost service add influxdb
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
||||||
sudo yunohost service add grafana-server --log "/var/log/grafana/grafana.log"
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
||||||
|
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD MODIFICATIONS
|
||||||
|
#=================================================
|
||||||
|
# FIND AND OPEN A PORT
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring port..." --weight=1
|
||||||
|
|
||||||
|
# Find an available port
|
||||||
|
port=$(ynh_find_port --port=3000)
|
||||||
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# INSTALL DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Installing dependencies..." --weight=44
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE A MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Creating a MySQL database..." --weight=2
|
||||||
|
|
||||||
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
||||||
|
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
|
||||||
|
|
||||||
|
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
||||||
|
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC SETUP
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring Grafana and InfluxDB..." --weight=30
|
||||||
# If NetData is installed, configure it to feed InfluxDB
|
# If NetData is installed, configure it to feed InfluxDB
|
||||||
netdata_conf="/opt/netdata/etc/netdata/netdata.conf"
|
netdata_conf="/opt/netdata/etc/netdata/netdata.conf"
|
||||||
if [[ -f "$netdata_conf" ]] ; then
|
if [ -f "$netdata_conf" ] ; then
|
||||||
# If there is already a [backend] section
|
# If there is already a [backend] section
|
||||||
if [ -n "$(sudo cat $netdata_conf | grep '\[backend\]')" ] ; then
|
if [ -n "$(cat $netdata_conf | grep '\[backend\]')" ] ; then
|
||||||
# These regexps replaces patterns inside ini [sections] ([backend] section, here)
|
# These regexps replaces patterns inside ini [sections] ([backend] section, here)
|
||||||
sudo sed -i '/^\[backend\]$/,/^\[/ {
|
# (source: https://stackoverflow.com/a/16987794)
|
||||||
|
sed -i '/^\[backend\]$/,/^\[/ {
|
||||||
s/# enabled = no/enabled = yes/
|
s/# enabled = no/enabled = yes/
|
||||||
s/# type = graphite/type = opentsdb/
|
s/# type = graphite/type = opentsdb/
|
||||||
s/# destination = localhost/destination = localhost:4242/
|
s/# destination = localhost/destination = localhost:4242/
|
||||||
|
@ -69,104 +117,134 @@ if [[ -f "$netdata_conf" ]] ; then
|
||||||
echo "[backend]
|
echo "[backend]
|
||||||
enabled = yes
|
enabled = yes
|
||||||
type = opentsdb
|
type = opentsdb
|
||||||
destination = localhost:4242" | sudo tee -a $netdata_conf
|
destination = localhost:4242" | tee -a $netdata_conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Restart NetData
|
# Restart NetData
|
||||||
sudo systemctl restart netdata
|
ynh_systemd_action --service_name=netdata --action="restart"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate MySQL password and create database
|
|
||||||
dbuser=$app
|
|
||||||
dbname=$app
|
|
||||||
dbpass=$(ynh_string_random 12)
|
|
||||||
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
|
||||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
||||||
|
|
||||||
# Configure InfluxDB
|
# Configure InfluxDB
|
||||||
if [ -f /etc/influxdb/influxdb.conf ] ; then
|
if [ -f /etc/influxdb/influxdb.conf ] ; then
|
||||||
sudo sed -i '/^\[\[opentsdb\]\]$/,/^\[/ s/enabled = false/enabled = true/' /etc/influxdb/influxdb.conf
|
sed -i '/^\[\[opentsdb\]\]$/,/^\[/ s/enabled = false/enabled = true/' /etc/influxdb/influxdb.conf
|
||||||
else
|
else
|
||||||
[ -d /etc/influxdb ] || sudo mkdir /etc/influxdb
|
[ -d /etc/influxdb ] || mkdir /etc/influxdb
|
||||||
sudo cp ../conf/influxdb.conf /etc/influxdb
|
cp ../conf/influxdb.conf /etc/influxdb
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start InfluxDB server
|
# Start InfluxDB server
|
||||||
sudo systemctl restart influxdb
|
ynh_systemd_action --service_name=influxdb --action="restart"
|
||||||
|
|
||||||
# Configure Grafana
|
# Configure Grafana
|
||||||
sudo cp ../conf/ldap.toml /etc/grafana
|
cp ../conf/ldap.toml /etc/grafana
|
||||||
|
|
||||||
grafana_conf="/etc/grafana/grafana.ini"
|
grafana_conf="/etc/grafana/grafana.ini"
|
||||||
# Set final port
|
# Set final port
|
||||||
sudo sed -i "/^\[server\]$/,/^\[/ s@;http_port = .*@http_port = $port@" $grafana_conf
|
sed -i "/^\[server\]$/,/^\[/ s@;http_port = .*@http_port = $port@" $grafana_conf
|
||||||
# Set domain
|
# Set domain
|
||||||
sudo sed -i "/^\[server\]$/,/^\[/ s@;domain = .*@domain = $domain@" $grafana_conf
|
sed -i "/^\[server\]$/,/^\[/ s@;domain = .*@domain = $domain@" $grafana_conf
|
||||||
# Set final URL
|
# Set final URL
|
||||||
sudo sed -i "/^\[server\]$/,/^\[/ s@;root_url = .*@root_url = %(protocol)s://%(domain)s$path@" $grafana_conf
|
sed -i "/^\[server\]$/,/^\[/ s@;root_url = .*@root_url = https://$domain$path_url@" $grafana_conf
|
||||||
|
# Specify if using sub_path
|
||||||
|
if [ "$path_url" != "/" ]; then
|
||||||
|
sed -i "/^\[server\]$/,/^\[/ s@;serve_from_sub_path = .*@serve_from_sub_path = true@" $grafana_conf
|
||||||
|
else
|
||||||
|
sed -i "/^\[server\]$/,/^\[/ s@;serve_from_sub_path = .*@serve_from_sub_path = false@" $grafana_conf
|
||||||
|
fi
|
||||||
# Disable check for updates
|
# Disable check for updates
|
||||||
sudo sed -i '/^\[analytics\]$/,/^\[/ s/;check_for_updates = .*/check_for_updates = false/' $grafana_conf
|
sed -i '/^\[analytics\]$/,/^\[/ s/;check_for_updates = .*/check_for_updates = false/' $grafana_conf
|
||||||
|
# Disable analytics reporting
|
||||||
|
sed -i '/^\[analytics\]$/,/^\[/ s/;reporting_enabled = .*/reporting_enabled = false/' $grafana_conf
|
||||||
# Disable organization creation
|
# Disable organization creation
|
||||||
sudo sed -i '/^\[users\]$/,/^\[/ s/;allow_org_create = .*/allow_org_create = false/' $grafana_conf
|
sed -i '/^\[users\]$/,/^\[/ s/;allow_org_create = .*/allow_org_create = false/' $grafana_conf
|
||||||
# Enable HTTP and LDAP authentication
|
# Enable HTTP and LDAP authentication
|
||||||
sudo sed -i '/^\[auth.basic\]$/,/^\[/ s/;enabled = .*/enabled = false/' $grafana_conf
|
sed -i '/^\[auth.basic\]$/,/^\[/ s/;enabled = .*/enabled = false/' $grafana_conf
|
||||||
sudo sed -i '/^\[auth.proxy\]$/,/^\[/ s/;enabled = .*/enabled = true/' $grafana_conf
|
sed -i '/^\[auth.proxy\]$/,/^\[/ s/;enabled = .*/enabled = true/' $grafana_conf
|
||||||
sudo sed -i '/^\[auth.ldap\]$/,/^\[/ {
|
sed -i '/^\[auth.ldap\]$/,/^\[/ {
|
||||||
s/;enabled = .*/enabled = true/
|
s/;enabled = .*/enabled = true/
|
||||||
s/;allow_sign_up = .*/allow_sign_up = true/
|
s/;allow_sign_up = .*/allow_sign_up = true/
|
||||||
}' $grafana_conf
|
}' $grafana_conf
|
||||||
# Set log level to debug
|
# Set log level to debug
|
||||||
sudo sed -i '/^\[log\]$/,/^\[/ s/;level = .*/level = debug/' $grafana_conf
|
sed -i '/^\[log\]$/,/^\[/ s/;level = .*/level = debug/' $grafana_conf
|
||||||
|
|
||||||
# Change URL and database credentials
|
# Change URL and database credentials
|
||||||
sudo sed -i "/^\[database\]$/,/^\[/ {
|
sed -i "/^\[database\]$/,/^\[/ {
|
||||||
s/;type = .*/type = mysql/
|
s/;type = .*/type = mysql/
|
||||||
s/;name = .*/name = $dbname/
|
s/;name = .*/name = $db_name/
|
||||||
s/;user = .*/user = $dbuser/
|
s/;user = .*/user = $db_user/
|
||||||
s/;\?password =.*/password = $dbpass/
|
s/;\?password =.*/password = $db_pwd/
|
||||||
}" $grafana_conf
|
}" $grafana_conf
|
||||||
|
|
||||||
|
# Calculate and store the config file checksum into the app settings
|
||||||
|
ynh_store_file_checksum --file="$grafana_conf"
|
||||||
|
|
||||||
# Start Grafana and wait for it to be fully started
|
# Start Grafana and wait for it to be fully started
|
||||||
ynh_check_starting "HTTP Server Listen" "/var/log/grafana/grafana.log" "240" "grafana-server"
|
ynh_systemd_action --service_name=grafana-server --action="restart" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
||||||
|
|
||||||
# Change admin name to the specified one
|
# Change admin name to the specified one
|
||||||
mail=$(ynh_user_get_info "$admin" 'mail')
|
mail=$(ynh_user_get_info "$admin" 'mail')
|
||||||
ynh_mysql_connect_as $dbuser $dbpass $dbname <<< "UPDATE user SET login=\"$admin\", email=\"$mail\" WHERE login=\"admin\";"
|
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "UPDATE user SET login=\"$admin\", email=\"$mail\" WHERE login=\"admin\";"
|
||||||
|
|
||||||
# Import default dashboard for NetData
|
# Create InfluxDB data source
|
||||||
hostname=$(hostname)
|
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, '{}');"
|
||||||
sed -i "s@yunohost.yunohost.org@$hostname@g" ../conf/grafana_init_data.sql
|
|
||||||
ynh_mysql_connect_as $dbuser $dbpass $dbname < ../conf/grafana_init_data.sql
|
|
||||||
|
|
||||||
# Restart grafana server to take db change into account
|
# Import default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701)
|
||||||
sudo systemctl restart grafana-server
|
# Remove new lines
|
||||||
|
tr -d '\n' < ../conf/netdata_dashboard.json > dashboard.json
|
||||||
|
# Fill the template with the defined data source
|
||||||
|
sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json
|
||||||
|
# Escape the dashboard definition for MySQL query (source: https://stackoverflow.com/a/4383994)
|
||||||
|
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
|
||||||
|
(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\");"
|
||||||
|
|
||||||
# Enable the systemd service so that InfluxDB and Grafana start at boot
|
# Enable the systemd service so that InfluxDB and Grafana start at boot
|
||||||
sudo systemctl enable influxdb.service
|
systemctl enable influxdb.service
|
||||||
sudo systemctl enable grafana-server.service
|
systemctl enable grafana-server.service
|
||||||
|
|
||||||
# Store useful files for backup/restore scripts
|
#=================================================
|
||||||
sudo cp _common.sh /etc/grafana
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
#=================================================
|
||||||
if [[ "$path" == "/" ]] ; then
|
# INTEGRATE SERVICE IN YUNOHOST
|
||||||
nginx_conf=../conf/nginx_root.conf
|
#=================================================
|
||||||
else
|
|
||||||
nginx_conf=../conf/nginx_sub_dir.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
|
yunohost service add influxdb --description "open source time series database" --log "/var/log/grafana/grafana.log"
|
||||||
sed -i "s@YNH_WWW_PORT@$port@g" $nginx_conf
|
yunohost service add grafana-server --description "open source analytics and monitoring solution" --log "/var/log/grafana/grafana.log"
|
||||||
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
|
|
||||||
# If app is public, add url to SSOWat conf as skipped_uris
|
#=================================================
|
||||||
if [[ $is_public -eq 1 ]]; then
|
# START SYSTEMD SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Starting a systemd service..." --weight=2
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=grafana-server --action="restart" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SSOWAT
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring SSOwat..." --weight=1
|
||||||
|
|
||||||
|
# Make app public if necessary
|
||||||
|
if [ $is_public -eq 1 ]
|
||||||
|
then
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start Grafana and wait for it to be fully started
|
#=================================================
|
||||||
ynh_check_starting "HTTP Server Listen" "/var/log/grafana/grafana.log" "240" "grafana-server"
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
||||||
|
|
||||||
# Reload services
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
sudo systemctl reload nginx
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Installation of $app completed" --last
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC STARTING
|
# GENERIC START
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -12,44 +12,61 @@ source /usr/share/yunohost/helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||||
|
|
||||||
# See comments in install script
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Source local helpers
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
source ./_common.sh
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||||
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
|
db_user=$db_name
|
||||||
|
|
||||||
# Source YunoHost helpers
|
#=================================================
|
||||||
source /usr/share/yunohost/helpers
|
# STANDARD REMOVE
|
||||||
|
#=================================================
|
||||||
|
# REMOVE SERVICE INTEGRATION IN YUNOHOST
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Retrieve app settings
|
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
if ynh_exec_warn_less yunohost service status grafana-server >/dev/null
|
||||||
|
then
|
||||||
# Stop services
|
ynh_script_progression --message="Removing grafana services..." --weight=1
|
||||||
sudo systemctl stop grafana-server
|
yunohost service remove grafana-server
|
||||||
sudo systemctl stop influxdb
|
yunohost service remove influxdb
|
||||||
|
|
||||||
# Remove app dependencies
|
|
||||||
ynh_remove_app_dependencies || true
|
|
||||||
|
|
||||||
# If packages deinstalled (weren't installed priorly to package installation)
|
|
||||||
# purge remaining files
|
|
||||||
if [[ -n "$(dpkg-query --status grafana | grep -E "Status|deinstall")" ]] ; then
|
|
||||||
sudo dpkg --purge grafana
|
|
||||||
sudo rm $GRAFANA_REPOSITORY
|
|
||||||
fi
|
|
||||||
if [[ -n "$(dpkg-query --status influxdb | grep -E "Status|deinstall")" ]] ; then
|
|
||||||
sudo dpkg --purge influxdb
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove services from YunoHost monitoring
|
#=================================================
|
||||||
sudo yunohost service remove influxdb
|
# REMOVE THE MYSQL DATABASE
|
||||||
sudo yunohost service remove grafana-server
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing the MySQL database..." --weight=3
|
||||||
|
|
||||||
|
# Remove a database if it exists, along with the associated user
|
||||||
|
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
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Removing nginx web server configuration..." --weight=1
|
||||||
|
|
||||||
|
# Remove the dedicated nginx config
|
||||||
|
ynh_remove_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC REMOVE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# If NetData is installed, configure it not to feed InfluxDB any more
|
# If NetData is installed, configure it not to feed InfluxDB any more
|
||||||
netdata_conf="/opt/netdata/etc/netdata/netdata.conf"
|
netdata_conf="/opt/netdata/etc/netdata/netdata.conf"
|
||||||
if [[ -f "$netdata_conf" ]] ; then
|
if [[ -f "$netdata_conf" ]] ; then
|
||||||
sudo sed -i '/^\[backend\]$/,/^\[/ {
|
sed -i '/^\[backend\]$/,/^\[/ {
|
||||||
s/enabled = yes/# enabled = no/
|
s/enabled = yes/# enabled = no/
|
||||||
s/type = opentsdb/# type = graphite/
|
s/type = opentsdb/# type = graphite/
|
||||||
s/destination = localhost:4242/# destination = localhost/
|
s/destination = localhost:4242/# destination = localhost/
|
||||||
|
@ -57,16 +74,14 @@ if [[ -f "$netdata_conf" ]] ; then
|
||||||
}' $netdata_conf
|
}' $netdata_conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove nginx configuration file
|
ynh_secure_remove --file="/etc/grafana/grafana.ini"
|
||||||
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
sudo rm -rf /home/yunohost.app/$app
|
|
||||||
|
|
||||||
# Drop MySQL database and user
|
#=================================================
|
||||||
dbname=$app
|
# GENERIC FINALIZATION
|
||||||
dbuser=$app
|
#=================================================
|
||||||
ynh_mysql_drop_db "$dbname" || true
|
|
||||||
ynh_mysql_drop_user "$dbuser" || true
|
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Reload nginx service
|
ynh_script_progression --message="Removal of $app completed" --last
|
||||||
sudo systemctl reload nginx
|
|
||||||
|
|
134
scripts/restore
134
scripts/restore
|
@ -1,86 +1,124 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if [ ! -e _common.sh ]; then
|
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
# Fetch helpers file if not in current directory
|
source ../settings/scripts/_common.sh
|
||||||
cp ../settings/scripts/_common.sh ./_common.sh
|
|
||||||
chmod a+rx _common.sh
|
|
||||||
fi
|
|
||||||
source _common.sh
|
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# MANAGE SCRIPT FAILURE
|
# 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
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading settings..." --weight=1
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Source YunoHost helpers
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
source /usr/share/yunohost/helpers
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||||
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
|
db_user=$db_name
|
||||||
|
|
||||||
# Retrieve old app settings
|
#=================================================
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
#=================================================
|
||||||
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
||||||
|
|
||||||
# Fix permissions
|
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
||||||
sudo chmod a+r ./conf_grafana/_common.sh
|
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
||||||
|
|
||||||
# Source local helpers
|
#=================================================
|
||||||
source ./conf_grafana/_common.sh
|
# STANDARD RESTORATION STEPS
|
||||||
SRCPATH=$(pwd)
|
#=================================================
|
||||||
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Fix path if needed
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
path=$(fix_path $path)
|
|
||||||
|
|
||||||
# Check domain/path availability
|
#=================================================
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
# SPECIFIC RESTORATION
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
#=================================================
|
||||||
|
# REINSTALL DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=24
|
||||||
|
|
||||||
# Install dependencies
|
# Define and install dependencies
|
||||||
install_dependencies
|
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"
|
||||||
|
|
||||||
# Create and restore Grafana database
|
#=================================================
|
||||||
dbname=$app
|
# RESTORE THE APP CONFIGURATION
|
||||||
dbuser=$app
|
#=================================================
|
||||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
ynh_script_progression --message="Restoring configuration directories..." --weight=2
|
||||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
||||||
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
|
|
||||||
|
|
||||||
|
ynh_restore_file --origin_path="/etc/influxdb"
|
||||||
|
ynh_restore_file --origin_path="/etc/grafana"
|
||||||
|
ynh_restore_file --origin_path="/var/lib/grafana/plugins"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE INFLUXDB DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Restoring the InfluxDB database..." --weight=10
|
||||||
# Restore InfluxDB data (only if backup not empty)
|
# Restore InfluxDB data (only if backup not empty)
|
||||||
# That happens when passing automated tests (NetData not present)
|
# That happens when passing automated tests (NetData not present)
|
||||||
sudo systemctl stop influxdb
|
ynh_systemd_action --service_name=influxdb --action="stop"
|
||||||
if [ "$(ls -A $SRCPATH/influxdb_data)" ] ; then
|
if [ "$(ls -A ./influxdb_data)" ] ; then
|
||||||
sudo influxd restore -metadir /var/lib/influxdb/meta $SRCPATH/influxdb_data
|
influxd restore -metadir /var/lib/influxdb/meta ./influxdb_data
|
||||||
if [ "$(ls -A $SRCPATH/influxdb_data/opentsdb*)" ] ; then
|
if [ "$(ls -A ./influxdb_data/opentsdb*)" ] ; then
|
||||||
sudo influxd restore -database opentsdb -datadir /var/lib/influxdb/data $SRCPATH/influxdb_data
|
influxd restore -database opentsdb -datadir /var/lib/influxdb/data ./influxdb_data
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# Restore configuration files
|
|
||||||
sudo cp -a $SRCPATH/conf_influxdb/* /etc/influxdb
|
|
||||||
sudo cp -a $SRCPATH/conf_grafana/* /etc/grafana
|
|
||||||
[ "$(sudo ls -A $SRCPATH/conf_grafana_plugins)" ] && sudo cp -a $SRCPATH/conf_grafana_plugins/* /var/lib/grafana/plugins
|
|
||||||
|
|
||||||
# Start InfluxDB server
|
#=================================================
|
||||||
sudo systemctl start influxdb
|
# RESTORE THE MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Restoring the MySQL database..." --weight=2
|
||||||
|
|
||||||
# Restart grafana server
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
||||||
sudo systemctl restart grafana-server
|
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
|
||||||
|
|
||||||
# Restart NetData if present
|
#=================================================
|
||||||
sudo systemctl restart netdata || true
|
# INTEGRATE SERVICE IN YUNOHOST
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Restore NGINX configuration
|
yunohost service add influxdb --description "open source time series database" --log "/var/log/grafana/grafana.log"
|
||||||
sudo cp -a $SRCPATH/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
yunohost service add grafana-server --description "open source analytics and monitoring solution" --log "/var/log/grafana/grafana.log" --timeout=600
|
||||||
|
|
||||||
# Restart webserver
|
#=================================================
|
||||||
sudo systemctl reload nginx
|
# START SYSTEMD SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=influxdb --action="start"
|
||||||
|
ynh_systemd_action --service_name=grafana-server --action="start" --log_path="/var/log/grafana/grafana.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX AND PHP-FPM
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Restoration completed for $app" --last
|
||||||
|
|
196
scripts/upgrade
196
scripts/upgrade
|
@ -1,75 +1,177 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
set -eu
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
shopt -s extglob # sets extended pattern matching options in the bash shell
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Source local helpers
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
source ./_common.sh
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||||
SRCPATH=$(pwd)
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
||||||
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||||
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
|
db_user=$db_name
|
||||||
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
||||||
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||||
|
|
||||||
# Source YunoHost helpers
|
#=================================================
|
||||||
source /usr/share/yunohost/helpers
|
# CHECK VERSION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Retrieve app settings
|
upgrade_type=$(ynh_check_app_version_changed)
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
|
||||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
|
||||||
port=$(ynh_app_setting_get "$app" port)
|
|
||||||
|
|
||||||
# test port settings
|
#=================================================
|
||||||
if [[ -z "$port" ]]; then
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
port=3000
|
#=================================================
|
||||||
ynh_app_setting_set $app port $port
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
||||||
|
|
||||||
|
# Fix is_public as a boolean value
|
||||||
|
if [ "$is_public" = "Yes" ]; then
|
||||||
|
ynh_app_setting_set --app=$app --key=is_public --value=1
|
||||||
|
is_public=1
|
||||||
|
elif [ "$is_public" = "No" ]; then
|
||||||
|
ynh_app_setting_set --app=$app --key=is_public --value=0
|
||||||
|
is_public=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fix path if needed
|
# If db_name doesn't exist, create it
|
||||||
path=$(fix_path $path)
|
if [ -z "$db_name" ]; then
|
||||||
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
||||||
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# MANAGE SCRIPT FAILURE
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=4
|
||||||
|
|
||||||
# Use prior backup and restore on error only if backup feature
|
# Backup the current version of the app
|
||||||
# exists on installed instance
|
ynh_backup_before_upgrade
|
||||||
ynh_backup_before_upgrade # Backup the current version of the app
|
|
||||||
ynh_clean_setup () {
|
ynh_clean_setup () {
|
||||||
|
# restore it if the upgrade fails
|
||||||
ynh_restore_upgradebackup
|
ynh_restore_upgradebackup
|
||||||
}
|
}
|
||||||
ynh_abort_if_errors # Stop script if an error is detected
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
# There's currently nothing else to upgrade than packaging files
|
#=================================================
|
||||||
# as InfluxDB/Grafana updates are managed through APT
|
# CHECK THE PATH
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Restart service
|
# Normalize the URL path syntax
|
||||||
sudo systemctl restart grafana-server
|
path_url=$(ynh_normalize_url_path --path_url=$path_url)
|
||||||
|
|
||||||
# Declare services for YunoHost monitoring
|
#=================================================
|
||||||
sudo yunohost service add influxdb
|
# STANDARD UPGRADE STEPS
|
||||||
sudo yunohost service add grafana-server --log "/var/log/grafana/grafana.log"
|
#=================================================
|
||||||
|
|
||||||
# Upgrade dependencies if needed
|
#=================================================
|
||||||
install_dependencies
|
# NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
|
||||||
|
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
# Create a dedicated nginx config
|
||||||
if [[ "$path" == "/" ]] ; then
|
ynh_add_nginx_config
|
||||||
nginx_conf=$SRCPATH/../conf/nginx_root.conf
|
|
||||||
else
|
#=================================================
|
||||||
nginx_conf=$SRCPATH/../conf/nginx_sub_dir.conf
|
# UPGRADE DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
sed -i "s@YNH_WWW_PATH@${path}@g" $nginx_conf
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
sed -i "s@YNH_WWW_PORT@$port@g" $nginx_conf
|
ynh_install_extra_app_dependencies --repo="deb https://packages.grafana.com/oss/deb stable main" --package="grafana" --key="https://packages.grafana.com/gpg.key"
|
||||||
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
|
|
||||||
# If app is public, add url to SSOWat conf as skipped_uris
|
#=================================================
|
||||||
if [[ $is_public -eq 1 ]]; then
|
# SPECIFIC UPGRADE
|
||||||
# See install script
|
#=================================================
|
||||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
|
||||||
|
ynh_script_progression --message="Configuring Grafana and InfluxDB..." --weight=3
|
||||||
|
# If NetData is installed, configure it to feed InfluxDB
|
||||||
|
netdata_conf="/opt/netdata/etc/netdata/netdata.conf"
|
||||||
|
if [ -f "$netdata_conf" ] ; then
|
||||||
|
# If there is already a [backend] section
|
||||||
|
if [ -n "$(cat $netdata_conf | grep '\[backend\]')" ] ; then
|
||||||
|
# These regexps replaces patterns inside ini [sections] ([backend] section, here)
|
||||||
|
sed -i '/^\[backend\]$/,/^\[/ {
|
||||||
|
s/# enabled = no/enabled = yes/
|
||||||
|
s/# type = graphite/type = opentsdb/
|
||||||
|
s/# destination = localhost/destination = localhost:4242/
|
||||||
|
s/# update every = 10/update every = 60/
|
||||||
|
}' $netdata_conf
|
||||||
|
else
|
||||||
|
# Otherwise create the section
|
||||||
|
echo "[backend]
|
||||||
|
enabled = yes
|
||||||
|
type = opentsdb
|
||||||
|
destination = localhost:4242" | tee -a $netdata_conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restart NetData
|
||||||
|
ynh_systemd_action --service_name=netdata --action="restart"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reload nginx service
|
# Update default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701)
|
||||||
sudo systemctl reload nginx
|
# Remove new lines
|
||||||
|
tr -d '\n' < ../conf/netdata_dashboard.json > dashboard.json
|
||||||
|
# Fill the template with the defined data source
|
||||||
|
sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json
|
||||||
|
# Escape the dashboard definition for MySQL query
|
||||||
|
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;"
|
||||||
|
# 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
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SSOWAT
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1
|
||||||
|
|
||||||
|
# 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=$app --key=unprotected_uris --value="/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# START SYSTEMD SERVICE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Restarting a systemd service..." --weight=2
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=grafana-server --action="restart" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Upgrade of $app completed" --last
|
||||||
|
|
Loading…
Reference in a new issue