mirror of
https://github.com/YunoHost-Apps/monitorix_ynh.git
synced 2024-09-03 19:46:06 +02:00
Use new helper
This commit is contained in:
parent
9090436531
commit
290f0043ae
10 changed files with 169 additions and 282 deletions
|
@ -21,13 +21,13 @@ include_dir = /etc/monitorix/conf.d
|
||||||
|
|
||||||
base_dir = /var/lib/monitorix/www/
|
base_dir = /var/lib/monitorix/www/
|
||||||
base_lib = /var/lib/monitorix/
|
base_lib = /var/lib/monitorix/
|
||||||
base_url = YNH_WWW_PATH
|
base_url = __YNH_WWW_PATH__
|
||||||
base_cgi = YNH_WWW_PATH-cgi
|
base_cgi = __YNH_WWW_PATH__-cgi
|
||||||
|
|
||||||
<httpd_builtin>
|
<httpd_builtin>
|
||||||
enabled = y
|
enabled = y
|
||||||
host = localhost
|
host = localhost
|
||||||
port = SERVICE_PORT
|
port = __SERVICE_PORT__
|
||||||
user = www-data
|
user = www-data
|
||||||
group = nogroup
|
group = nogroup
|
||||||
log_file = /var/log/monitorix-httpd
|
log_file = /var/log/monitorix-httpd
|
||||||
|
@ -446,8 +446,8 @@ secure_log_date_format = %b %e
|
||||||
# NGINX graph
|
# NGINX graph
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
<nginx>
|
<nginx>
|
||||||
url = http://localhost:NGINX_STATUS_PORT/nginx_status_monitorix
|
url = http://localhost:__NGINX_STATUS_PORT__/nginx_status_monitorix
|
||||||
port = NGINX_STATUS_PORT
|
port = __NGINX_STATUS_PORT__
|
||||||
rule = 24100
|
rule = 24100
|
||||||
rigid = 0, 0, 0
|
rigid = 0, 0, 0
|
||||||
limit = 100, 100, 100
|
limit = 100, 100, 100
|
||||||
|
@ -469,7 +469,7 @@ secure_log_date_format = %b %e
|
||||||
conn_type = socket
|
conn_type = socket
|
||||||
list = /var/run/mysqld/mysqld.sock
|
list = /var/run/mysqld/mysqld.sock
|
||||||
<desc>
|
<desc>
|
||||||
/var/run/mysqld/mysqld.sock = 3306, MYSQL_USER, MYSQL_PASSWORD
|
/var/run/mysqld/mysqld.sock = 3306, __MYSQL_USER__, MYSQL_PASSWORD
|
||||||
</desc>
|
</desc>
|
||||||
rigid = 0, 2, 0, 0, 0, 0
|
rigid = 0, 2, 0, 0, 0, 0
|
||||||
limit = 100, 100, 100, 100, 100, 100
|
limit = 100, 100, 100, 100, 100, 100
|
||||||
|
@ -733,9 +733,9 @@ secure_log_date_format = %b %e
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
<emailreports>
|
<emailreports>
|
||||||
enabled = n
|
enabled = n
|
||||||
url_prefix = http://127.0.0.1:SERVICE_PORTYNH_WWW_PATH
|
url_prefix = http://127.0.0.1:__SERVICE_PORT____YNH_WWW_PATH__
|
||||||
smtp_hostname = localhost
|
smtp_hostname = localhost
|
||||||
from_address = noreply@YNH_DOMAIN
|
from_address = noreply@__YNH_DOMAIN__
|
||||||
hour = 0
|
hour = 0
|
||||||
minute = 0
|
minute = 0
|
||||||
<daily>
|
<daily>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
location YNH_WWW_PATH {
|
location __YNH_WWW_PATH__ {
|
||||||
proxy_pass http://127.0.0.1:SERVICE_PORTYNH_WWW_PATH;
|
proxy_pass http://127.0.0.1:__SERVICE_PORT____YNH_WWW_PATH__;
|
||||||
allow 127.0.0.0/8;
|
allow 127.0.0.0/8;
|
||||||
|
|
||||||
location ~ ^YNH_WWW_PATH/(.+\.png)$ {
|
location ~ ^__YNH_WWW_PATH__/(.+\.png)$ {
|
||||||
alias /var/lib/monitorix/www/$1;
|
alias /var/lib/monitorix/www/$1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
"en": "A monitoring tools",
|
"en": "A monitoring tools",
|
||||||
"fr": "Un outils de monitoring"
|
"fr": "Un outils de monitoring"
|
||||||
},
|
},
|
||||||
|
"version": "3.9.0",
|
||||||
"url": "http://monitorix.org",
|
"url": "http://monitorix.org",
|
||||||
"license": "free",
|
"license": "free",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
"email": "josue@familletille.ch"
|
"email": "josue@familletille.ch"
|
||||||
},
|
},
|
||||||
"requirements": {
|
"requirements": {
|
||||||
"yunohost": ">> 2.4.0"
|
"yunohost": ">= 2.6.4"
|
||||||
},
|
},
|
||||||
"multi_instance": false,
|
"multi_instance": false,
|
||||||
"services": [
|
"services": [
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
## Adapt md5sum while you update app
|
## Adapt md5sum while you update app
|
||||||
md5sum="7314ad6fcd014a34c2e4e8a95455bcaa"
|
md5sum="7314ad6fcd014a34c2e4e8a95455bcaa"
|
||||||
monitorix_version="3.9.0"
|
monitorix_version="3.9.0"
|
||||||
|
|
||||||
init_script() {
|
install_dependances() {
|
||||||
# Exit on command errors and treat unset variables as an error
|
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
|
||||||
set -eu
|
ynh_package_update
|
||||||
|
dpkg -i /tmp/monitorix.deb
|
||||||
# Source YunoHost helpers
|
ynh_secure_remove /etc/monitorix/conf.d/00-debian.conf
|
||||||
source /usr/share/yunohost/helpers
|
ynh_package_install -f
|
||||||
|
|
||||||
# Retrieve arguments
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get_source() {
|
get_source() {
|
||||||
|
|
||||||
wget -q -O '/tmp/monitorix.deb' "http://www.monitorix.org/monitorix_${monitorix_version}-izzy1_all.deb"
|
wget -q -O '/tmp/monitorix.deb' "http://www.monitorix.org/monitorix_${monitorix_version}-izzy1_all.deb"
|
||||||
|
|
||||||
if [[ ! -e '/tmp/monitorix.deb' ]] || [[ $(md5sum '/tmp/monitorix.deb' | cut -d' ' -f1) != $md5sum ]]
|
if [[ ! -e '/tmp/monitorix.deb' ]] || [[ $(md5sum '/tmp/monitorix.deb' | cut -d' ' -f1) != $md5sum ]]
|
||||||
|
@ -25,56 +23,27 @@ get_source() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_VAR () { # Vérifie que la variable n'est pas vide.
|
config_nginx() {
|
||||||
# $1 = Variable à vérifier
|
nginx_conf=../conf/nginx.conf
|
||||||
# $2 = Texte à afficher en cas d'erreur
|
ynh_replace_string __YNH_WWW_PATH__ $path $nginx_conf
|
||||||
test -n "$1" || (echo "$2" >&2 && false)
|
ynh_replace_string __SERVICE_PORT__ $http_port $nginx_conf
|
||||||
|
cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
|
|
||||||
|
# Add special hostname for monitorix status
|
||||||
|
nginx_status_conf=../conf/nginx_status.conf
|
||||||
|
ynh_replace_string PORT $nginx_status_port $nginx_status_conf
|
||||||
|
cp $nginx_status_conf /etc/nginx/conf.d/monitorix_status.conf
|
||||||
|
|
||||||
|
systemctl reload nginx.service
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_PATH () { # Vérifie la présence du / en début de path. Et son absence à la fin.
|
config_monitorix() {
|
||||||
if [ "${path:0:1}" != "/" ]; then # Si le premier caractère n'est pas un /
|
monitorix_conf=../conf/monitorix.conf
|
||||||
path="/$path" # Ajoute un / en début de path
|
ynh_replace_string __SERVICE_PORT__ $http_port $monitorix_conf
|
||||||
fi
|
ynh_replace_string __YNH_DOMAIN__ $domain $monitorix_conf
|
||||||
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # Si le dernier caractère est un / et que ce n'est pas le seul caractère.
|
ynh_replace_string __NGINX_STATUS_PORT__ $nginx_status_port $monitorix_conf
|
||||||
path="${path:0:${#path}-1}" # Supprime le dernier caractère
|
ynh_replace_string __YNH_WWW_PATH__ $path $monitorix_conf
|
||||||
fi
|
ynh_replace_string __MYSQL_USER__ $dbuser $monitorix_conf
|
||||||
}
|
ynh_replace_string MYSQL_PASSWORD $dbpass $monitorix_conf
|
||||||
|
cp $monitorix_conf /etc/monitorix/monitorix.conf
|
||||||
CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine.
|
|
||||||
sudo yunohost app checkurl $domain$path -a $app
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
|
||||||
final_path=/var/www/$app
|
|
||||||
if [ -e "$final_path" ]
|
|
||||||
then
|
|
||||||
echo "This path already contains a folder" >&2
|
|
||||||
false
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Find a free port and return it
|
|
||||||
#
|
|
||||||
# example: port=$(ynh_find_port 8080)
|
|
||||||
#
|
|
||||||
# usage: ynh_find_port begin_port
|
|
||||||
# | arg: begin_port - port to start to search
|
|
||||||
ynh_find_port () {
|
|
||||||
port=$1
|
|
||||||
test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port."
|
|
||||||
while netcat -z 127.0.0.1 $port # Check if the port is free
|
|
||||||
do
|
|
||||||
port=$((port+1)) # Else, pass to next port
|
|
||||||
done
|
|
||||||
echo $port
|
|
||||||
}
|
|
||||||
|
|
||||||
### REMOVE SCRIPT
|
|
||||||
|
|
||||||
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
|
|
||||||
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
|
|
||||||
echo "Delete nginx config"
|
|
||||||
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
||||||
sudo service nginx reload
|
|
||||||
fi
|
|
||||||
}
|
}
|
|
@ -1,33 +1,17 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
######## Actually we cant use common script in backup / restore script see this issue for more informations : https://dev.yunohost.org/issues/621
|
# Source YunoHost helpers
|
||||||
# # Import common cmd
|
source /usr/share/yunohost/helpers
|
||||||
# source ./_common.sh
|
|
||||||
#
|
|
||||||
|
|
||||||
######## We implement manually this fonctions
|
# Stop script if errors
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
init_script() {
|
# Import common cmd
|
||||||
# Exit on command errors and treat unset variables as an error
|
source ../settings/scripts/_common.sh
|
||||||
set -eu
|
|
||||||
|
|
||||||
# Source YunoHost helpers
|
# Retrieve arguments
|
||||||
source /usr/share/yunohost/helpers
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
|
||||||
# Retrieve arguments
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
|
||||||
}
|
|
||||||
|
|
||||||
######## End of common fonctions
|
|
||||||
|
|
||||||
# Init script
|
|
||||||
init_script
|
|
||||||
|
|
||||||
# # Dump the database
|
|
||||||
dbname=$app
|
|
||||||
dbuser=$app
|
|
||||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
||||||
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
|
|
||||||
|
|
||||||
# Copy NGINX configuration
|
# Copy NGINX configuration
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
|
|
55
scripts/change_url
Normal file
55
scripts/change_url
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Source YunoHost helpers
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
# Import common cmd
|
||||||
|
source ./_common.sh
|
||||||
|
|
||||||
|
# Retrive arguments
|
||||||
|
old_domain=$YNH_APP_OLD_DOMAIN
|
||||||
|
old_path=$(ynh_normalize_url_path $YNH_APP_OLD_PATH)
|
||||||
|
new_domain=$YNH_APP_NEW_DOMAIN
|
||||||
|
new_path=$(ynh_normalize_url_path $YNH_APP_NEW_PATH)
|
||||||
|
http_port=$(ynh_app_setting_get "$app" http_port)
|
||||||
|
|
||||||
|
# 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
|
||||||
|
# MODIFY URL IN NGINX CONF
|
||||||
|
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
|
||||||
|
ynh_replace_string "location $old_path" "location $new_path" "$nginx_conf_path"
|
||||||
|
ynh_replace_string "http://127.0.0.1:$http_port$old_path;" "http://127.0.0.1:$http_port$new_path;" "$nginx_conf_path"
|
||||||
|
ynh_replace_string "location ~ ^$old_path/(.+\.png)$" "location ~ ^$new_path/(.+\.png)$" "$nginx_conf_path"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Change the domain for nginx
|
||||||
|
if [ $change_domain -eq 1 ]
|
||||||
|
then
|
||||||
|
sudo mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update Monitorix Config
|
||||||
|
ynh_replace_string "base_url = $old_path" "base_url = $new_path" /etc/monitorix/monitorix.conf
|
||||||
|
ynh_replace_string "base_cgi = $old_path-cgi" "base_cgi = $new_path-cgi" /etc/monitorix/monitorix.conf
|
||||||
|
ynh_replace_string "url_prefix = http://127.0.0.1:$http_port$old_path" "url_prefix = http://127.0.0.1:$http_port$new_path" /etc/monitorix/monitorix.conf
|
||||||
|
ynh_replace_string "from_address = noreply@$old_domain" "from_address = noreply@$new_domain" /etc/monitorix/monitorix.conf
|
||||||
|
|
||||||
|
# Reload services
|
||||||
|
sudo systemctl reload nginx.service
|
||||||
|
sudo systemctl restart monitorix.service
|
|
@ -1,38 +1,33 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Source YunoHost helpers
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
# Stop script if errors
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
# Import common cmd
|
# Import common cmd
|
||||||
source ./_common.sh
|
source ./_common.sh
|
||||||
|
|
||||||
# Init script
|
|
||||||
init_script
|
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path=$YNH_APP_ARG_PATH
|
path=$(ynh_normalize_url_path $YNH_APP_ARG_PATH)
|
||||||
|
|
||||||
# Correct path if it is not correct
|
|
||||||
CHECK_PATH
|
|
||||||
|
|
||||||
# Check domain/path availability
|
# Check domain/path availability
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
test $(ynh_webpath_available $domain $path) == 'True' || ynh_die "$domain$path is not available, please use an other domain or path."
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
ynh_webpath_register $app $domain $path
|
||||||
|
|
||||||
# Download package
|
# Download package
|
||||||
get_source
|
get_source
|
||||||
|
|
||||||
# Install package
|
# Install package
|
||||||
ynh_package_update
|
install_dependances
|
||||||
ynh_package_install rrdtool perl libwww-perl libmailtools-perl libmime-lite-perl librrds-perl libdbi-perl libxml-simple-perl libhttp-server-simple-perl libconfig-general-perl pflogsumm
|
|
||||||
sudo dpkg -i /tmp/monitorix.deb
|
|
||||||
sudo rm -rf /etc/monitorix/conf.d/00-debian.conf
|
|
||||||
ynh_package_install -f
|
|
||||||
|
|
||||||
# # Generate MySQL password and create database
|
# # Generate MySQL user
|
||||||
dbuser=$app
|
dbuser=$app
|
||||||
dbname=$app
|
|
||||||
dbpass=$(ynh_string_random 12)
|
dbpass=$(ynh_string_random 12)
|
||||||
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
||||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
ynh_mysql_create_user $dbuser $dbpass
|
||||||
|
|
||||||
# Find a port for built-in monitorix HTTP server
|
# Find a port for built-in monitorix HTTP server
|
||||||
http_port=$(ynh_find_port 8080)
|
http_port=$(ynh_find_port 8080)
|
||||||
|
@ -41,31 +36,14 @@ nginx_status_port=$(ynh_find_port $(($http_port +1)))
|
||||||
ynh_app_setting_set $app http_port $http_port
|
ynh_app_setting_set $app http_port $http_port
|
||||||
ynh_app_setting_set $app nginx_status_port $nginx_status_port
|
ynh_app_setting_set $app nginx_status_port $nginx_status_port
|
||||||
|
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
# Config nginx
|
||||||
nginx_conf=../conf/nginx.conf
|
config_nginx
|
||||||
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
|
|
||||||
sed -i "s@SERVICE_PORT@$http_port@g" $nginx_conf
|
|
||||||
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
|
|
||||||
# Add special hostname for monitorix status
|
|
||||||
nginx_status_conf=../conf/nginx_status.conf
|
|
||||||
sed -i "s@PORT@$nginx_status_port@g" $nginx_status_conf
|
|
||||||
sudo cp $nginx_status_conf /etc/nginx/conf.d/monitorix_status.conf
|
|
||||||
|
|
||||||
# Update monitorix configuration
|
# Update monitorix configuration
|
||||||
monitorix_conf=../conf/monitorix.conf
|
config_monitorix
|
||||||
sed -i "s@SERVICE_PORT@$http_port@g" $monitorix_conf
|
|
||||||
sed -i "s@YNH_DOMAIN@$domain@g" $monitorix_conf
|
|
||||||
sed -i "s@NGINX_STATUS_PORT@$nginx_status_port@g" $monitorix_conf
|
|
||||||
sed -i "s@YNH_WWW_PATH@$path@g" $monitorix_conf
|
|
||||||
sed -i "s@MYSQL_USER@$dbuser@g" $monitorix_conf
|
|
||||||
sed -i "s@MYSQL_PASSWORD@$dbpass@g" $monitorix_conf
|
|
||||||
sudo cp $monitorix_conf /etc/monitorix/monitorix.conf
|
|
||||||
|
|
||||||
# register yunohost service
|
# register yunohost service
|
||||||
sudo yunohost service add monitorix
|
yunohost service add monitorix
|
||||||
|
|
||||||
# Reload services
|
# Reload services
|
||||||
sudo service monitorix restart
|
systemctl restart monitorix.service
|
||||||
sudo yunohost app ssowatconf
|
|
||||||
sudo service nginx reload
|
|
||||||
|
|
|
@ -1,19 +1,23 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Source YunoHost helpers
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
# Stop script if errors
|
||||||
|
set -u
|
||||||
|
|
||||||
# Import common cmd
|
# Import common cmd
|
||||||
source ./_common.sh
|
source ./_common.sh
|
||||||
|
|
||||||
# Init script
|
|
||||||
init_script
|
|
||||||
|
|
||||||
# Retrieve app settings
|
# Retrieve app settings
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
|
|
||||||
# Stop service
|
# Stop service
|
||||||
sudo service monitorix stop || true
|
systemctl stop monitorix.service
|
||||||
|
|
||||||
# Remove nginx configuration file
|
# Suppression de la configuration nginx
|
||||||
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
systemctl reload nginx.service
|
||||||
|
|
||||||
# Drop MySQL database and user
|
# Drop MySQL database and user
|
||||||
dbname=$app
|
dbname=$app
|
||||||
|
@ -22,9 +26,7 @@ ynh_mysql_drop_db "$dbname" || true
|
||||||
ynh_mysql_drop_user "$dbuser" || true
|
ynh_mysql_drop_user "$dbuser" || true
|
||||||
|
|
||||||
# Autoremove package
|
# Autoremove package
|
||||||
|
ynh_remove_app_dependencies
|
||||||
ynh_package_autoremove monitorix
|
ynh_package_autoremove monitorix
|
||||||
|
|
||||||
sudo yunohost service remove monitorix
|
yunohost service remove monitorix
|
||||||
|
|
||||||
# Reload nginx service
|
|
||||||
sudo service nginx reload
|
|
||||||
|
|
121
scripts/restore
121
scripts/restore
|
@ -1,122 +1,37 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
######## Actually we cant use common script in backup / restore script see this issue for more informations : https://dev.yunohost.org/issues/621
|
# Source YunoHost helpers
|
||||||
# # Import common cmd
|
source /usr/share/yunohost/helpers
|
||||||
# source ./_common.sh
|
|
||||||
#
|
|
||||||
|
|
||||||
######## We implement manually this fonctions
|
# Stop script if errors
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
## Adapt md5sum while you update app
|
# Import common cmd
|
||||||
md5sum="7314ad6fcd014a34c2e4e8a95455bcaa"
|
source ../settings/scripts/_common.sh
|
||||||
monitorix_version="3.9.0"
|
|
||||||
|
|
||||||
init_script() {
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
# Source YunoHost helpers
|
|
||||||
source /usr/share/yunohost/helpers
|
|
||||||
|
|
||||||
# Retrieve arguments
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
|
||||||
}
|
|
||||||
|
|
||||||
get_source() {
|
|
||||||
|
|
||||||
wget -q -O '/tmp/monitorix.deb' "http://www.monitorix.org/monitorix_${monitorix_version}-izzy1_all.deb"
|
|
||||||
|
|
||||||
if [[ ! -e '/tmp/monitorix.deb' ]] || [[ $(md5sum '/tmp/monitorix.deb' | cut -d' ' -f1) != $md5sum ]]
|
|
||||||
then
|
|
||||||
ynh_die "Error : can't get monitorix debian package"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_VAR () { # Vérifie que la variable n'est pas vide.
|
|
||||||
# $1 = Variable à vérifier
|
|
||||||
# $2 = Texte à afficher en cas d'erreur
|
|
||||||
test -n "$1" || (echo "$2" >&2 && false)
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_PATH () { # Vérifie la présence du / en début de path. Et son absence à la fin.
|
|
||||||
if [ "${path:0:1}" != "/" ]; then # Si le premier caractère n'est pas un /
|
|
||||||
path="/$path" # Ajoute un / en début de path
|
|
||||||
fi
|
|
||||||
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # Si le dernier caractère est un / et que ce n'est pas le seul caractère.
|
|
||||||
path="${path:0:${#path}-1}" # Supprime le dernier caractère
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine.
|
|
||||||
sudo yunohost app checkurl $domain$path -a $app
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
|
||||||
final_path=/var/www/$app
|
|
||||||
if [ -e "$final_path" ]
|
|
||||||
then
|
|
||||||
echo "This path already contains a folder" >&2
|
|
||||||
false
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
### REMOVE SCRIPT
|
|
||||||
|
|
||||||
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
|
|
||||||
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
|
|
||||||
echo "Delete nginx config"
|
|
||||||
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
||||||
sudo service nginx reload
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
######## End of common fonctions
|
|
||||||
|
|
||||||
# Init script
|
|
||||||
init_script
|
|
||||||
|
|
||||||
# Note: each files and directories you've saved using the ynh_backup helper
|
|
||||||
# will be located in the current directory, regarding the last argument.
|
|
||||||
|
|
||||||
# Retrieve old app settings
|
# Retrieve old app settings
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
path=$(ynh_normalize_url_path $(ynh_app_setting_get "$app" path))
|
||||||
|
|
||||||
# Correct path if it is not correct
|
|
||||||
CHECK_PATH
|
|
||||||
|
|
||||||
# Check domain/path availability
|
# Check domain/path availability
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
ynh_webpath_available $domain $path || ynh_die "$domain/$path is not available, please use an other domain or path."
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
|
||||||
|
# Download package
|
||||||
|
get_source
|
||||||
|
|
||||||
# Download package
|
# Download package
|
||||||
get_source
|
get_source
|
||||||
|
|
||||||
# Install package
|
# Install package
|
||||||
ynh_package_update
|
install_dependances
|
||||||
ynh_package_install rrdtool perl libwww-perl libmailtools-perl libmime-lite-perl librrds-perl libdbi-perl libxml-simple-perl libhttp-server-simple-perl libconfig-general-perl
|
|
||||||
sudo dpkg -i /tmp/monitorix.deb
|
|
||||||
sudo rm -rf /etc/monitorix/conf.d/00-debian.conf
|
|
||||||
ynh_package_install -f
|
|
||||||
|
|
||||||
# # Create and restore the database
|
# Create user for database
|
||||||
dbname=$app
|
|
||||||
dbuser=$app
|
dbuser=$app
|
||||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
ynh_mysql_create_user $dbuser $dbpass
|
||||||
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
|
|
||||||
|
|
||||||
# Restore NGINX configuration
|
# Restore all config and data
|
||||||
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
ynh_restore
|
||||||
sudo cp -a ./monitorix_status.conf "/etc/nginx/conf.d/monitorix_status.conf"
|
|
||||||
|
|
||||||
# Restore Monitorix configuration
|
# Reload services
|
||||||
sudo cp -a ./config/. "/etc/monitorix/."
|
systemctl restart monitorix.service
|
||||||
sudo cp -a ./data/. "/var/lib/monitorix/."
|
|
||||||
|
|
||||||
|
|
||||||
# Restart webserver
|
|
||||||
sudo service monitorix restart
|
|
||||||
sudo yunohost app ssowatconf
|
|
||||||
sudo service nginx reload
|
|
|
@ -1,52 +1,35 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Source YunoHost helpers
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
# Stop script if errors
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
# Import common cmd
|
# Import common cmd
|
||||||
source ./_common.sh
|
source ./_common.sh
|
||||||
|
|
||||||
# Init script
|
|
||||||
init_script
|
|
||||||
|
|
||||||
# Retrieve app settings
|
# Retrieve app settings
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
path=$(ynh_normalize_url_path $(ynh_app_setting_get "$app" path))
|
||||||
http_port=$(ynh_app_setting_get "$app" http_port)
|
http_port=$(ynh_app_setting_get "$app" http_port)
|
||||||
nginx_status_port=$(ynh_app_setting_get "$app" nginx_status_port)
|
nginx_status_port=$(ynh_app_setting_get "$app" nginx_status_port)
|
||||||
dbuser=$app
|
dbuser=$app
|
||||||
dbname=$app
|
dbname=$app
|
||||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||||
|
|
||||||
# Correct path if it is not correct
|
|
||||||
CHECK_PATH
|
|
||||||
|
|
||||||
# Download package
|
# Download package
|
||||||
get_source
|
get_source
|
||||||
|
|
||||||
# Update package
|
# Update package
|
||||||
sudo dpkg -i /tmp/monitorix.deb
|
dpkg -i /tmp/monitorix.deb
|
||||||
sudo rm -rf /etc/monitorix/conf.d/00-debian.conf
|
ynh_secure_remove /etc/monitorix/conf.d/00-debian.conf
|
||||||
|
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
# Update nginx config
|
||||||
nginx_conf=../conf/nginx.conf
|
config_nginx
|
||||||
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
|
|
||||||
sed -i "s@SERVICE_PORT@$http_port@g" $nginx_conf
|
|
||||||
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
||||||
|
|
||||||
# Add special hostname for monitorix status
|
|
||||||
nginx_status_conf=../conf/nginx_status.conf
|
|
||||||
sed -i "s@PORT@$nginx_status_port@g" $nginx_status_conf
|
|
||||||
sudo cp $nginx_status_conf /etc/nginx/conf.d/monitorix_status.conf
|
|
||||||
|
|
||||||
# Update monitorix configuration
|
# Update monitorix configuration
|
||||||
monitorix_conf=../conf/monitorix.conf
|
config_monitorix
|
||||||
sed -i "s@SERVICE_PORT@$http_port@g" $monitorix_conf
|
|
||||||
sed -i "s@YNH_DOMAIN@$domain@g" $monitorix_conf
|
|
||||||
sed -i "s@NGINX_STATUS_PORT@$nginx_status_port@g" $monitorix_conf
|
|
||||||
sed -i "s@YNH_WWW_PATH@$path@g" $monitorix_conf
|
|
||||||
sed -i "s@MYSQL_USER@$dbuser@g" $monitorix_conf
|
|
||||||
sed -i "s@MYSQL_PASSWORD@$dbpass@g" $monitorix_conf
|
|
||||||
sudo cp $monitorix_conf /etc/monitorix/monitorix.conf
|
|
||||||
|
|
||||||
# Reload services
|
# Reload services
|
||||||
sudo service monitorix restart
|
systemctl restart monitorix.service
|
||||||
sudo yunohost app ssowatconf
|
|
||||||
sudo service nginx reload
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue