1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/monitorix_ynh.git synced 2024-09-03 19:46:06 +02:00

Apply last example_ynh

This commit is contained in:
yalh76 2022-06-19 21:05:33 +02:00
parent c09953008a
commit b9df8d5905
19 changed files with 849 additions and 323 deletions

View file

@ -150,13 +150,13 @@ priority = 5
# -----------------------------------------------------------------------------
<fs>
<list>
0 = /, /home, /var, /tmp, swap
0 = /, /home, /var, /$tempdir, swap
</list>
<desc>
/ = Root FS
/home = home
/var = var
/tmp = tmp
/$tempdir = tmp
</desc>
<devmap>
</devmap>
@ -166,7 +166,7 @@ priority = 5
/ = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_rootfs.sh
/home = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_home.sh
/var = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_var.sh
/tmp = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_tmp.sh
/$tempdir = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_tmp.sh
swap = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_swap.sh
</alerts>
</fs>

View file

@ -1,24 +1,21 @@
;; General
auto_remove=1
# Commentaire ignoré
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=0
setup_public=0
upgrade=1
backup_restore=1
multi_instance=0
wrong_user=0
wrong_path=1
incorrect_path=1
corrupt_source=1
fail_download_source=1
port_already_use=1 (8080)
final_path_already_use=1
change_url=1
;; Test complet
; Manifest
domain="domain.tld"
path="/path"
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=0
setup_public=0
upgrade=1
# 3.12.0~ynh1
upgrade=1 from_commit=c09953008a913b5e1d46be561a10a746eab6d23e
backup_restore=1
multi_instance=0
port_already_use=0
change_url=1
;;; Options
Email=
Notification=none

View file

@ -1,17 +1,7 @@
SOURCE_URL=http://www.monitorix.org/old-versions/monitorix_3.12.0-izzy1_all.deb
SOURCE_SUM=4fb9fa233463e036020e71aa2e545f5dc2c1106f2c8397017de5c3cb17de1263
# (Optional) Program to check the integrity (sha256sum, md5sum...)
# default: sha256
SOURCE_URL=http://www.monitorix.org/old-versions/monitorix_3.13.1-izzy1_all.deb
SOURCE_SUM=17a48021c46bf5656caeacbcf2da6bff63816496bf1d4f4926daa64c76a4733f
SOURCE_SUM_PRG=sha256sum
# (Optional) Archive format
# default: tar.gz
SOURCE_FORMAT=deb
# (Optional) Put false if sources are directly in the archive root
# default: true
# Instead of true, SOURCE_IN_SUBDIR could be the number of sub directories
# to remove.
SOURCE_IN_SUBDIR=false
# (Optional) If it set as false don't extract the source.
# (Useful to get a debian package or a python wheel.)
# default: true
SOURCE_FILENAME=
SOURCE_EXTRACT=false

View file

@ -21,13 +21,13 @@ include_dir = /etc/monitorix/conf.d
base_dir = /var/lib/monitorix/www/
base_lib = /var/lib/monitorix/
base_url = __YNH_WWW_PATH__
base_cgi = __YNH_WWW_PATH__/cgi
base_url = __PATH_URL__
base_cgi = __PATH_URL_SLASH_LESS__/cgi
<httpd_builtin>
enabled = y
host = localhost
port = __SERVICE_PORT__
port = __PORT__
user = www-data
group = nogroup
log_file = /var/log/monitorix-httpd
@ -289,7 +289,7 @@ secure_log_date_format = %b %e
<du>
list = System, Users
<desc>
0 = /var/spool/mail, /var/spool/mqueue, /etc, /var/ftp, /tmp
0 = /var/spool/mail, /var/spool/mqueue, /etc, /var/ftp, /$tempdir
1 = /home/ace, /home/gene, /home/paul, /home/peter
</desc>
<dirmap>
@ -475,7 +475,7 @@ secure_log_date_format = %b %e
conn_type = socket
list = /run/mysqld/mysqld.sock
<desc>
/run/mysqld/mysqld.sock = 3306, __MYSQL_USER__, __MYSQL_PASSWORD__
/run/mysqld/mysqld.sock = 3306, __DB_USER__, __DB_PWD__
</desc>
rigid = 0, 2, 0, 0, 0, 0
limit = 100, 100, 100, 100, 100, 100
@ -591,7 +591,7 @@ secure_log_date_format = %b %e
2 = [postfix], [postfix-sasl], [dovecot]
3 = [nginx-http-auth]
4 = [sshd], [sshd-ddos]
5 = __F2B_ADDITIONAL_JAIL__
5 = __ADDITIONAL_JAIL__
</desc>
graphs_per_row = 2
rigid = 0
@ -743,9 +743,9 @@ secure_log_date_format = %b %e
# -----------------------------------------------------------------------------
<emailreports>
enabled = n
url_prefix = http://127.0.0.1:__SERVICE_PORT____YNH_WWW_PATH__
url_prefix = http://127.0.0.1:__PORT____PATH_URL__
smtp_hostname = localhost
from_address = noreply@__YNH_DOMAIN__
from_address = noreply@__DOMAIN__
hour = 0
minute = 0
<daily>

View file

@ -1,21 +1,21 @@
location __PATH__ {
proxy_pass http://127.0.0.1:__PORT____PATH__;
allow 127.0.0.0/8;
proxy_pass http://127.0.0.1:__PORT____PATH__;
allow 127.0.0.0/8;
location ~ ^__PATH__/(.+\.png)$ {
alias /var/lib/monitorix/www/$1;
}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
location ~ ^__PATH__/(.+\.png)$ {
alias /var/lib/monitorix/www/$1;
}
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}

View file

@ -1,15 +1,15 @@
server {
listen __PORT__;
listen [::]:__PORT__;
listen __NGINX_STATUS_PORT__;
listen [::]:__NGINX_STATUS_PORT__;
access_log /var/log/nginx/localhost-nginx_status_monitorix.lan-access.log;
error_log /var/log/nginx/localhost-nginx_status_monitorix.lan-error.log;
access_log /var/log/nginx/localhost-nginx_status_monitorix.lan-access.log;
error_log /var/log/nginx/localhost-nginx_status_monitorix.lan-error.log;
location /nginx_status_monitorix {
stub_status on;
access_log off;
allow 127.0.0.1;
allow ::1;
deny all;
}
}
location /nginx_status_monitorix {
stub_status on;
access_log off;
allow 127.0.0.1;
allow ::1;
deny all;
}
}

1
doc/DESCRIPTION.md Normal file
View file

@ -0,0 +1 @@
Monitorix is a free, open source, lightweight system monitoring tool designed to monitor as many services and system resources as possible. It has been created to be used under production Linux/UNIX servers, but due to its simplicity and small size can be used on embedded devices as well.

214
doc/DISCLAIMER.md Normal file
View file

@ -0,0 +1,214 @@
### More sensor
If you want to see the temperature of some sensor you can install the `lm-sensor` packet. For disk temperature you can instal the `hddtemp` packet.
### Custom config
If you want do custom the monitorix config for more personnal information you can add a file in `/etc/monitorix/conf.d/`. This config file will be overwritte the original config in `/etc/monitorix/monitorix.conf`.
You will have a full complete documentation for monitorix config here : https://www.monitorix.org/documentation.html
By example you can extends the basic config by this :
```
priority = 5
<graph_enable>
disk = y
lmsens = y
gensens = y
mail = y
</graph_enable>
# LMSENS graph
# -----------------------------------------------------------------------------
<lmsens>
<list>
core0 = temp1
core1 =
mb0 =
cpu0 =
fan0 =
fan1 =
fan2 =
volt0 =
volt1 =
volt2 =
volt3 =
volt4 =
volt5 =
volt6 =
volt7 =
</list>
</lmsns>
# GENSENS graph
# -----------------------------------------------------------------------------
<gensens>
<list>
0 = cpu_temp
1 = cpu0_freq, cpu1_freq, cpu2_freq, cpu3_freq
</list>
<desc>
cpu_temp = /sys/class/thermal/thermal_zone0/temp
cpu0_freq = /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
cpu1_freq = /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq
cpu2_freq = /sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq
cpu3_freq = /sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_cur_freq
</desc>
<unit>
cpu_temp = 1000
cpu0_freq = 0.001
cpu1_freq = 0.001
cpu2_freq = 0.001
cpu3_freq = 0.001
</unit>
<map>
cpu_temp = CPU Temperature
cpu0_freq = CPU 0 Frequency
cpu1_freq = CPU 1 Frequency
cpu2_freq = CPU 2 Frequency
cpu3_freq = CPU 3 Frequency
</map>
<alerts>
cpu_temp = 300, 65, /etc/monitorix/monitorix_alerts_scripts/cpu_temp.sh
</alerts>
</gensens>
# DISK graph
# -----------------------------------------------------------------------------
<disk>
<list>
0 = /dev/sda
</list>
<alerts>
realloc_enabled = y
realloc_timeintvl = 0
realloc_threshold = 1
realloc_script = /etc/monitorix/monitorix_alerts_scripts/disk_realloc.sh
pendsect_enabled = y
pendsect_timeintvl = 0
pendsect_threshold = 1
pendsect_script = /etc/monitorix/monitorix_alerts_scripts/disk_pendsect.sh
</alerts>
</disk>
# FS graph
# -----------------------------------------------------------------------------
<fs>
<list>
0 = /, /home, /var, /$tempdir, swap
</list>
<desc>
/ = Root FS
/home = home
/var = var
/$tempdir = tmp
</desc>
<devmap>
</devmap>
rigid = 2, 0, 2, 0
limit = 100, 1000, 100, 1000
<alerts>
/ = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_rootfs.sh
/home = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_home.sh
/var = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_var.sh
/$tempdir = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_tmp.sh
swap = 3600, 98, /etc/monitorix/monitorix_alerts_scripts/fs_swap.sh
</alerts>
</fs>
# MAIL graph
# -----------------------------------------------------------------------------
<mail>
mta = postfix
greylist = postgrey
stats_rate = real
rigid = 0, 0, 0, 0, 0
limit = 1, 1000, 1000, 1000, 1000
<alerts>
delvd_enabled = y
delvd_timeintvl = 60
delvd_threshold = 100
delvd_script = /etc/monitorix/monitorix_alerts_scripts/mail_delvd.sh
mqueued_enabled = y
mqueued_timeintvl = 3600
mqueued_threshold = 100
mqueued_script = /etc/monitorix/monitorix_alerts_scripts/mail_mqueued.sh
</alerts>
</mail>
# NET graph
# -----------------------------------------------------------------------------
<net>
list = eth0,lo
<desc>
eth0 = FastEthernet LAN, 0, 10000000
lo = loopback, 0, 10000000
</desc>
gateway = eth0
</net>
# PROCESS graph
# -----------------------------------------------------------------------------
<process>
<list>
0 = sshd, ntpd, monitorix, monitorix-httpd
1 = openvpn, ...
...
6 = mysqld, slapd, postgresql
</list>
<desc>
master = Postfix
imap = Dovecot
</desc>
rigid = 2, 0, 0, 0, 0, 0, 0, 0
limit = 100, 1000, 1000, 1000, 1000, 1000, 1000, 1000
</process>
<emailreports>
enabled = y
url_prefix = http://127.0.0.1:8081/monitorix
smtp_hostname = localhost
from_address = noreply@domain.tld
hour = 2
minute = 7
<daily>
enabled = y
graphs = system, fs, gensens, disk, netstat, port, nginx
to = user@domain.tld
</daily>
<weekly>
enabled = y
graphs = system, fs, gensens, disk, kern, proc, net, netstat, process, serv, port, user, nginx, mysql, fail2ban, int
to = user@domain.tld
</weekly>
<monthly>
enabled = y
graphs = system, fs, gensens, disk, kern, proc, net, netstat, process, serv, port, user, nginx, mysql, fail2ban, int
to = user@domain.tld
</monthly>
<yearly>
enabled = y
graphs = system, fs, gensens, disk, kern, proc, net, netstat, process, serv, port, user, nginx, mysql, fail2ban, int
to = user@domain.tld
</yearly>
</emailreports>
```
In this config we have :
- We set the process priority to 5 (which mean that it will be lower priority than the other process).
- We get the lmsensor sensor data.
- We get some sensors data not accessible with lmsensor (with gensens)
- We check the disk health and send an email if any error happens. For that you need to make some script. An example is available in `/usr/share/doc/monitorix/monitorix-alert.sh`.
- We check the filesystem.
- We check the traffic in the network card.
- We check some process.
- We send every day, week, month and year a rapport.

0
doc/screenshots/.gitkeep Normal file
View file

BIN
doc/screenshots/mail.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

View file

@ -6,15 +6,22 @@
"en": "A monitoring tools",
"fr": "Un outils de monitoring"
},
"version": "3.12.0~ynh1",
"version": "3.13.1~ynh1",
"url": "http://monitorix.org",
"upstream": {
"license": "GPL-2.0",
"website": "http://monitorix.org",
"demo": "https://www.fibranet.cat/monitorix/",
"admindoc": "https://www.monitorix.org/documentation.html",
"code": "https://github.com/mikaku/Monitorix"
},
"license": "GPL-2.0",
"maintainer": {
"name": "Josué Tille",
"email": "josue@familletille.ch"
},
"requirements": {
"yunohost": ">= 4.0.0"
"yunohost": ">= 4.3.0"
},
"multi_instance": false,
"services": [
@ -22,23 +29,14 @@
"mysql"
],
"arguments": {
"install" : [
"install": [
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain name for Monitorix",
"fr": "Choisissez un nom de domaine pour Monitorix"
},
"example": "example.com"
"type": "domain"
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for Monitorix",
"fr": "Choisissez un chemin pour Monitorix"
},
"example": "/monitorix",
"default": "/monitorix"
}

View file

@ -1,22 +1,21 @@
#!/bin/bash
#=================================================
# SET ALL CONSTANTS
# COMMON VARIABLES
#=================================================
app=$YNH_APP_INSTANCE_NAME
# dependencies used by the app
pkg_dependencies="rrdtool perl libwww-perl libmailtools-perl libmime-lite-perl librrds-perl libdbi-perl libxml-simple-perl libhttp-server-simple-perl libconfig-general-perl pflogsumm libxml-libxml-perl"
#=================================================
# DEFINE ALL COMMON FONCTIONS
#=================================================
install_dependances() {
ynh_install_app_dependencies rrdtool perl libwww-perl libmailtools-perl libmime-lite-perl librrds-perl libdbi-perl libxml-simple-perl libhttp-server-simple-perl libconfig-general-perl pflogsumm libxml-libxml-perl
}
get_install_source() {
ynh_setup_source --dest_dir /tmp
ynh_setup_source --dest_dir /$tempdir
ynh_package_update
dpkg --force-confdef --force-confold -i /tmp/app.deb
dpkg --force-confdef --force-confold -i /$tempdir/app.deb
ynh_secure_remove --file=/etc/monitorix/conf.d/00-debian.conf
ynh_package_install -f
}
@ -45,16 +44,8 @@ config_monitorix() {
fi
done
monitorix_conf=/etc/monitorix/monitorix.conf
cp ../conf/monitorix.conf $monitorix_conf
ynh_replace_string --match_string __SERVICE_PORT__ --replace_string $port --target_file $monitorix_conf
ynh_replace_string --match_string __YNH_DOMAIN__ --replace_string $domain --target_file $monitorix_conf
ynh_replace_string --match_string __NGINX_STATUS_PORT__ --replace_string $nginx_status_port --target_file $monitorix_conf
ynh_replace_string --match_string __YNH_WWW_PATH__/ --replace_string "${path_url%/}/" --target_file $monitorix_conf
ynh_replace_string --match_string __YNH_WWW_PATH__ --replace_string $path_url --target_file $monitorix_conf
ynh_replace_string --match_string __MYSQL_USER__ --replace_string $dbuser --target_file $monitorix_conf
ynh_replace_string --match_string __MYSQL_PASSWORD__ --replace_string $dbpass --target_file $monitorix_conf
ynh_replace_string --match_string __F2B_ADDITIONAL_JAIL__ --replace_string "$additional_jail" --target_file $monitorix_conf
path_url_slash_less=${path_url%/}
ynh_add_config --template="../conf/monitorix.conf" --destination="/etc/monitorix/monitorix.conf"
}
set_permission() {

View file

@ -3,39 +3,64 @@
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Import common cmd
source ../settings/scripts/experimental_helper.sh
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Stop script if errors
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Retrieve arguments
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
domain=$(ynh_app_setting_get --app $app --key domain)
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# STANDARD BACKUP STEPS
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
# Copy NGINX configuration
ynh_print_info --message="Backing up configuration..."
domain=$(ynh_app_setting_get --app $app --key domain)
ynh_backup --src_path "/etc/nginx/conf.d/${domain}.d/${app}.conf"
ynh_backup --src_path "/etc/nginx/conf.d/monitorix_status.conf"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/nginx/conf.d/monitorix_status.conf"
# Copy hook
ynh_backup --src_path "/etc/yunohost/hooks.d/post_iptable_rules/50-$app"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
# Copy Monitorix configuration
ynh_backup --src_path "/etc/monitorix"
ynh_backup --src_path="/etc/yunohost/hooks.d/post_iptable_rules/50-$app"
# Copy Monitorix data
ynh_print_info --message="Backing up data..."
ynh_backup --src_path "/var/lib/monitorix"
ynh_backup --src_path="/etc/monitorix"
ynh_backup --src_path="/var/lib/monitorix"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,62 +1,163 @@
#!/bin/bash
#=================================================
# GENERIC START
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Import common cmd
source ./experimental_helper.sh
source ./_common.sh
# Source YunoHost helpers
source _common.sh
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
#=================================================
# 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..."
# Retrive arguments
path_url=$(ynh_normalize_url_path --path_url $YNH_APP_NEW_PATH)
old_domain=$YNH_APP_OLD_DOMAIN
domain=$YNH_APP_NEW_DOMAIN
port=$(ynh_app_setting_get --app $app --key http_port)
nginx_status_port=$(ynh_app_setting_get --app $app --key nginx_status_port)
dbuser=$app
dbname=$app
dbpass=$(ynh_app_setting_get --app $app --key mysqlpwd)
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Add settings here as needed by your application
port=$(ynh_app_setting_get --app=$app --key=port)
nginx_status_port=$(ynh_app_setting_get --app=$app --key=nginx_status_port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# 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..."
ynh_script_progression --message="Updating nginx configuration..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
# Update nginx config
if [ "$old_domain" != "$domain" ]
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..."
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
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file "/etc/nginx/conf.d/$old_domain.d/$app.conf"
mv "/etc/nginx/conf.d/$old_domain.d/$app.conf" "/etc/nginx/conf.d/$domain.d/$app.conf"
# Store file checksum for the new config file location
ynh_store_file_checksum --file "/etc/nginx/conf.d/$domain.d/$app.conf"
# 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
config_nginx
ynh_script_progression --message="Updating monitorix configuration..."
# 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
ynh_add_config --template="../conf/nginx_status.conf" --destination="/etc/nginx/conf.d/monitorix_status.conf"
# Update monitorix configuration
config_monitorix
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
ynh_script_progression --message="Restarting monitorix services..." --weight=3
# Reload monitorix
# While we stop monitorix sometime the built-in web server is not stopped cleanly. So are sure that everything is cleanly stoped by that
# So this fix that
systemctl stop monitorix.service
sleep 1
pkill -f "monitorix-httpd listening on" || true
ynh_systemd_action -l ' - Ok, ready.' -p '/var/log/monitorix'
domain="$new_domain"
path_url="$new_path"
jail_list=$(fail2ban-client status | grep 'Jail list:' | sed 's/.*Jail list://' | sed 's/,//g')
additional_jail=""
for jail in $jail_list; do
if ! [[ "$jail" =~ (recidive|pam-generic|yunohost|postfix|postfix-sasl|dovecot|nginx-http-auth|sshd|sshd-ddos) ]]; then
if [ -z "$additional_jail" ]; then
additional_jail="[$jail]"
else
additional_jail+=", [$jail]"
fi
fi
done
path_url_slash_less=${path_url%/}
ynh_add_config --template="../conf/monitorix.conf" --destination="/etc/monitorix/monitorix.conf"
chown www-data:root -R /etc/monitorix
chmod u=rX,g=rwX,o= -R /etc/monitorix
chown www-data:root -R /var/lib/monitorix
chmod u=rwX,g=rwX,o= -R /var/lib/monitorix
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3
# Start a systemd service
ynh_systemd_action --service_name=$app --action="restart" --log_path="/var/log/monitorix" --line_match=" - Ok, ready."
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -3,82 +3,145 @@
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Import common cmd
source ./experimental_helper.sh
source ./_common.sh
# Source YunoHost helpers
source _common.sh
source /usr/share/yunohost/helpers
# Stop script if errors
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
ynh_script_progression --message="Validating installation parameters..."
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
# Check domain/path availability
test $(ynh_webpath_available --domain $domain --path_url $path_url) == 'True' || ynh_die --message "$domain$path_url is not available, please use an other domain or path."
ynh_webpath_register $app $domain $path_url
app=$YNH_APP_INSTANCE_NAME
# Find a port for built-in monitorix HTTP server
ynh_script_progression --message="Finding available ports..."
port=$(ynh_find_port --port 8080)
nginx_status_port=$(ynh_find_port --port $(($port +1)))
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
# store config in yunohost
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app $app --key http_port --value $port
ynh_app_setting_set --app $app --key nginx_status_port --value $nginx_status_port
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..."
# Install package
# Find an available port
port=$(ynh_find_port --port=8080)
ynh_app_setting_set --app=$app --key=port --value=$port
nginx_status_port=$(ynh_find_port --port $(($port +1)))
ynh_app_setting_set --app=$app --key=nginx_status_port --value=$nginx_status_port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=7
install_dependances
# Download package and install it
ynh_script_progression --message="Installing sources files..." --weight=7
get_install_source
ynh_install_app_dependencies $pkg_dependencies
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir="$tempdir"
ynh_package_update
dpkg --force-confdef --force-confold -i /$tempdir/app.deb
ynh_package_install -f
ynh_secure_remove --file="$tempdir"
# # Generate MySQL user
ynh_script_progression --message="Configuring MySQL database..."
dbuser=$app
dbpass=$(ynh_string_random 12)
ynh_app_setting_set --app $app --key mysqlpwd --value "$dbpass"
ynh_mysql_create_user $dbuser $dbpass
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..."
# Config nginx
ynh_script_progression --message="Configuring nginx..." --weight=1
config_nginx
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
# Update monitorix configuration
ynh_script_progression --message="Configuring application..." --weight=3
config_monitorix
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
ynh_add_config --template="../conf/nginx_status.conf" --destination="/etc/nginx/conf.d/monitorix_status.conf"
#=================================================
# SPECIFIC SETUP
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=3
jail_list=$(fail2ban-client status | grep 'Jail list:' | sed 's/.*Jail list://' | sed 's/,//g')
additional_jail=""
for jail in $jail_list; do
if ! [[ "$jail" =~ (recidive|pam-generic|yunohost|postfix|postfix-sasl|dovecot|nginx-http-auth|sshd|sshd-ddos) ]]; then
if [ -z "$additional_jail" ]; then
additional_jail="[$jail]"
else
additional_jail+=", [$jail]"
fi
fi
done
path_url_slash_less=${path_url%/}
ynh_add_config --template="../conf/monitorix.conf" --destination="/etc/monitorix/monitorix.conf"
chown www-data:root -R /etc/monitorix
chmod u=rX,g=rwX,o= -R /etc/monitorix
chown www-data:root -R /var/lib/monitorix
chmod u=rwX,g=rwX,o= -R /var/lib/monitorix
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
# Set access
ynh_script_progression --message="Protecting directory..."
set_permission
# register yunohost service
yunohost service add monitorix
# Reload monitorix
ynh_script_progression --message="Starting monitorix services..." --weight=3
# While we stop monitorix sometime the built-in web server is not stopped cleanly. So are sure that everything is cleanly stoped by that
# So this fix that
systemctl stop monitorix.service
sleep 1
pkill -f "monitorix-httpd listening on" || true
ynh_systemd_action -l ' - Ok, ready.' -p '/var/log/monitorix'
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3
# Start a systemd service
ynh_systemd_action --service_name=$app --action="restart" --log_path="/var/log/monitorix" --line_match=" - Ok, ready."
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -3,48 +3,79 @@
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Import common cmd
source ./experimental_helper.sh
source ./_common.sh
# Source YunoHost helpers
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
domain=$(ynh_app_setting_get --app $app --key domain)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Stop service
ynh_script_progression --message="Stoping services..."
systemctl stop monitorix.service
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove $app
fi
# Drop MySQL database and user
ynh_script_progression --message="Removing databases..."
dbname=$app
dbuser=$app
ynh_mysql_drop_db "$dbname" || true
ynh_mysql_drop_user "$dbuser" || true
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..."
systemctl stop $app.service
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Removing the MySQL database..."
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely
# Remove data
ynh_script_progression --message="Removing logs..."
ynh_secure_remove --file=/var/lib/monitorix
# Remove nginx config
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove the dedicated NGINX config
ynh_secure_remove --file="/etc/nginx/conf.d/monitorix_status.conf"
ynh_remove_nginx_config
# Autoremove package
ynh_script_progression --message="Removing dependencies" --weight=10
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=10
ynh_remove_app_dependencies
ynh_package_autoremove monitorix
ynh_package_autoremove $app
yunohost service remove monitorix
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -3,71 +3,115 @@
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Import common cmd
source ../settings/scripts/experimental_helper.sh
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Stop script if errors
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
ynh_script_progression --message="Loading settings..."
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
# Retrieve old app settings
domain=$(ynh_app_setting_get --app $app --key domain)
path_url=$(ynh_normalize_url_path --path_url $(ynh_app_setting_get --app $app --key path))
app=$YNH_APP_INSTANCE_NAME
# Check domain/path availability
ynh_webpath_available --domain $domain --path_url $path_url || ynh_die --message "$domain/$path_url is not available, please use an other domain or path."
domain=$(ynh_app_setting_get --app=$app --key=domain)
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
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# Install package
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=5
install_dependances
# Download package and install it
ynh_script_progression --message="Installing sources files..." --weight=7
get_install_source
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir="$tempdir"
ynh_package_update
dpkg --force-confdef --force-confold -i /$tempdir/app.deb
ynh_secure_remove --file=/etc/monitorix/conf.d/00-debian.conf
ynh_package_install -f
ynh_secure_remove --file="$tempdir"
# Create user for database
ynh_script_progression --message="Configuring MySQL database..."
dbuser=$app
dbpass=$(ynh_app_setting_get --app $app --key mysqlpwd)
ynh_mysql_create_user $dbuser $dbpass
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/monitorix_status.conf"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..."
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..." --weight=10
# Restore all config and data
ynh_script_progression --message="Restoring files..." --weight=10
ynh_secure_remove --file=/etc/monitorix # we remove the directory because if it is not empty the ynh_restore cmd fail
ynh_secure_remove --file=/var/lib/monitorix
ynh_restore
ynh_restore_file --origin_path="/etc/yunohost/hooks.d/post_iptable_rules/50-$app"
ynh_restore_file --origin_path="/etc/monitorix"
ynh_restore_file --origin_path="/var/lib/monitorix"
chown www-data:root -R /etc/monitorix
chmod u=rX,g=rwX,o= -R /etc/monitorix
chown www-data:root -R /var/lib/monitorix
chmod u=rwX,g=rwX,o= -R /var/lib/monitorix
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add monitorix
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3
ynh_systemd_action --service_name=$app --action="restart" --log_path="/var/log/monitorix" --line_match=" - Ok, ready."
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
# Set access
ynh_script_progression --message="Protecting directory..."
set_permission
ynh_systemd_action --service_name=nginx --action=reload
# register yunohost service
yunohost service add monitorix
# Reload nginx
systemctl reload nginx.service
# Reload monitorix
ynh_script_progression --message="Starting monitorix services..." --weight=3
# While we stop monitorix sometime the built-in web server is not stopped cleanly. So are sure that everything is cleanly stoped by that
# So this fix that
systemctl stop monitorix.service
sleep 1
pkill -f "monitorix-httpd listening on" || true
ynh_systemd_action -l ' - Ok, ready.' -p '/var/log/monitorix'
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -3,36 +3,44 @@
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Import common cmd
source ./experimental_helper.sh
source ./_common.sh
# Source YunoHost helpers
source _common.sh
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
# Retrieve app settings
domain=$(ynh_app_setting_get --app $app --key domain)
path_url=$(ynh_normalize_url_path --path_url $(ynh_app_setting_get --app $app --key path))
port=$(ynh_app_setting_get --app $app --key http_port)
nginx_status_port=$(ynh_app_setting_get --app $app --key nginx_status_port)
dbuser=$app
dbname=$app
dbpass=$(ynh_app_setting_get --app $app --key mysqlpwd)
app=$YNH_APP_INSTANCE_NAME
# Stop services
ynh_script_progression --message="Stoping services..."
systemctl stop monitorix.service
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
port=$(ynh_app_setting_get --app=$app --key=port)
nginx_status_port=$(ynh_app_setting_get --app=$app --key=nginx_status_port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
dbuser=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_clean_check_starting
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
@ -41,43 +49,106 @@ ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
# Install package
ynh_script_progression --message="Installing dependencies..." --weight=6
install_dependances
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
# Download package and install it
ynh_script_progression --message="Upgrading source files..." --weight=6
get_install_source
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Update nginx config
config_nginx
# If db_name doesn't exist, create it
if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid --db_name=$app)
dbuser=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
# Update monitorix configuration
ynh_script_progression --message="Configuring application..."
config_monitorix
# If port doesn't exist, create it
if [ -z "$port" ]; then
port=$(ynh_app_setting_get --app=$app --key=http_port)
ynh_app_setting_set --app=$app --key=port --value=$port
ynh_app_setting_delete --app=app --key=http_port
fi
# Remove old hook if exist
ynh_secure_remove --file=/usr/share/yunohost/hooks/post_iptable_rules/50-$app
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=6
ynh_install_app_dependencies $pkg_dependencies
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir="$tempdir"
ynh_package_update
dpkg --force-confdef --force-confold -i /$tempdir/app.deb
ynh_package_install -f
ynh_secure_remove --file="$tempdir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config
ynh_add_config --template="../conf/nginx_status.conf" --destination="/etc/nginx/conf.d/monitorix_status.conf"
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
jail_list=$(fail2ban-client status | grep 'Jail list:' | sed 's/.*Jail list://' | sed 's/,//g')
additional_jail=""
for jail in $jail_list; do
if ! [[ "$jail" =~ (recidive|pam-generic|yunohost|postfix|postfix-sasl|dovecot|nginx-http-auth|sshd|sshd-ddos) ]]; then
if [ -z "$additional_jail" ]; then
additional_jail="[$jail]"
else
additional_jail+=", [$jail]"
fi
fi
done
path_url_slash_less=${path_url%/}
ynh_add_config --template="../conf/monitorix.conf" --destination="/etc/monitorix/monitorix.conf"
chown www-data:root -R /etc/monitorix
chmod u=rX,g=rwX,o= -R /etc/monitorix
chown www-data:root -R /var/lib/monitorix
chmod u=rwX,g=rwX,o= -R /var/lib/monitorix
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
# Set access
ynh_script_progression --message="Protecting directory..."
set_permission
# register yunohost service
yunohost service add monitorix
# Reload monitorix
# While we stop monitorix sometime the built-in web server is not stopped cleanly. So are sure that everything is cleanly stoped by that
# So this fix that
ynh_script_progression --message="Starting monitorix services..." --weight=3
systemctl stop monitorix.service
sleep 1
pkill -f "monitorix-httpd listening on" || true
ynh_systemd_action -l ' - Ok, ready.' -p '/var/log/monitorix'
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3
ynh_systemd_action --service_name=$app --action="restart" --log_path="/var/log/monitorix" --line_match=" - Ok, ready."
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last