mirror of
https://github.com/YunoHost-Apps/monitorix_ynh.git
synced 2024-09-03 19:46:06 +02:00
Use new findport fonction (#4)
* Clean common script * Add check_process * Use new findport fonction * Use new findport fonction
This commit is contained in:
parent
aaff7c80ed
commit
051408bace
3 changed files with 15 additions and 48 deletions
|
@ -31,20 +31,6 @@ CHECK_VAR () { # Vérifie que la variable n'est pas vide.
|
|||
test -n "$1" || (echo "$2" >&2 && false)
|
||||
}
|
||||
|
||||
# Ignore the yunohost-cli log to prevent errors with conditionals commands
|
||||
# usage: NO_LOG COMMAND
|
||||
# Simply duplicate the log, execute the yunohost command and replace the log without the result of this command
|
||||
# It's a very badly hack...
|
||||
# Petite copie perso à mon usage ;)
|
||||
NO_LOG() {
|
||||
ynh_cli_log=/var/log/yunohost/yunohost-cli.log
|
||||
sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move
|
||||
eval $@
|
||||
exit_code=$?
|
||||
sudo mv ${ynh_cli_log}-move ${ynh_cli_log}
|
||||
return $?
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -67,16 +53,22 @@ CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà u
|
|||
fi
|
||||
}
|
||||
|
||||
FIND_PORT () { # Cherche un port libre.
|
||||
# $1 = Numéro de port pour débuter la recherche.
|
||||
# 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
|
||||
while ! sudo yunohost app checkport $port ; do
|
||||
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
|
||||
CHECK_VAR "$port" "port empty"
|
||||
echo $port
|
||||
}
|
||||
|
||||
|
||||
### REMOVE SCRIPT
|
||||
|
||||
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
|
||||
|
|
|
@ -35,11 +35,10 @@ ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
|||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||
|
||||
# Find a port for built-in monitorix HTTP server
|
||||
NO_LOG FIND_PORT 8080
|
||||
http_port=$port
|
||||
http_port=$(ynh_find_port 8080)
|
||||
nginx_status_port=$(ynh_find_port $(($http_port +1)))
|
||||
|
||||
ynh_app_setting_set $app http_port $http_port
|
||||
NO_LOG FIND_PORT $(($port +1))
|
||||
nginx_status_port=$port
|
||||
ynh_app_setting_set $app nginx_status_port $nginx_status_port
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
|
|
|
@ -38,20 +38,6 @@ CHECK_VAR () { # Vérifie que la variable n'est pas vide.
|
|||
test -n "$1" || (echo "$2" >&2 && false)
|
||||
}
|
||||
|
||||
# Ignore the yunohost-cli log to prevent errors with conditionals commands
|
||||
# usage: NO_LOG COMMAND
|
||||
# Simply duplicate the log, execute the yunohost command and replace the log without the result of this command
|
||||
# It's a very badly hack...
|
||||
# Petite copie perso à mon usage ;)
|
||||
NO_LOG() {
|
||||
ynh_cli_log=/var/log/yunohost/yunohost-cli.log
|
||||
sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move
|
||||
eval $@
|
||||
exit_code=$?
|
||||
sudo mv ${ynh_cli_log}-move ${ynh_cli_log}
|
||||
return $?
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -74,16 +60,6 @@ CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà u
|
|||
fi
|
||||
}
|
||||
|
||||
FIND_PORT () { # Cherche un port libre.
|
||||
# $1 = Numéro de port pour débuter la recherche.
|
||||
port=$1
|
||||
while ! sudo yunohost app checkport $port ; do
|
||||
port=$((port+1))
|
||||
done
|
||||
CHECK_VAR "$port" "port empty"
|
||||
}
|
||||
|
||||
|
||||
### REMOVE SCRIPT
|
||||
|
||||
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
|
||||
|
|
Loading…
Reference in a new issue