1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/domoticz_ynh.git synced 2024-09-03 18:26:17 +02:00

Add Mosquitto broker

This commit is contained in:
Krakinou 2022-05-22 19:15:23 +02:00
parent 284eef5113
commit f48c003bb0
15 changed files with 282 additions and 89 deletions

View file

@ -1,9 +1,5 @@
;; Test complet
;; Test sans Mosquitto
; Manifest
domain="domain.tld"
path="/path"
is_public=1
port="666"
; Checks
pkg_linter=1
setup_sub_dir=1
@ -11,15 +7,43 @@
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=cf402923ff6feeead1c87555c6e9207b8c7f6595
upgrade=1 from_commit=048ae59a016755b0829a4e8f3ed5d0dbbd1b826b
backup_restore=1
multi_instance=0
port_already_use=1
change_url=1
;;; Options
Email=nicolas@aubonalbanais.ovh
Notification=none
;;; Upgrade options
; commit=CommitHash
name=Name and date of the commit.
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666&
; commit=048ae59a016755b0829a4e8f3ed5d0dbbd1b826b
name=Package ynh3.
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&
;; Test avec Mosquitto
; pre-install
set -euxo pipefail
yunohost domain add mqtt.domain.tld
; pre-upgrade
set -euxo pipefail
yunohost app setting domoticz mqtt_domain -v mqtt.domain.tld
; Manifest
mqtt_domain="mqtt.domain.tld"
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=048ae59a016755b0829a4e8f3ed5d0dbbd1b826b
backup_restore=1
port_already_use=1
change_url=1
;;; Options
Email=nicolas@aubonalbanais.ovh
Notification=none
;;; Upgrade options
; commit=048ae59a016755b0829a4e8f3ed5d0dbbd1b826b
name=Package ynh3
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass

View file

@ -1,4 +1,9 @@
log_timestamp_format %Y-%m-%dT%H:%M:%S
listener __MQTT_PORT__
listener __MQTT_WEBSOCKET_PORT__
protocol websockets
allow_anonymous false
password_file /etc/mosquitto/conf.d/credentials
password_file /etc/mosquitto/conf.d/__APP___credentials

11
conf/mqtt_nginx.conf Normal file
View file

@ -0,0 +1,11 @@
location / {
#Settings for mqtt server from outside
proxy_http_version 1.1;
proxy_pass http://localhost:__MQTT_WEBSOCKET_PORT__;
proxy_read_timeout 90;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}

View file

@ -20,7 +20,7 @@ location __PATH__/ {
include conf.d/yunohost_panel.conf.inc;
}
#This part should be split in a second file to not be overwritten
#sub_path_only rewrite ^api___PATH__$ api___PATH__/ permanent;
location __API_PATH__/ {
#Alternative path for api, only authorized json command will be accepted
@ -56,4 +56,4 @@ location __API_PATH__/ {
return 403;
}
}
}

View file

@ -40,7 +40,8 @@ CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK
CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM
CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE
CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
#Has to be commented as prevent the service to run
#CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG

View file

@ -12,9 +12,44 @@ For example this system can be used with:
* And more ...
**Shipped version:** Always the last stable one. The last compiled version is retrieved from [this directory](https://releases.domoticz.com/releases/?dir=./beta)
**Shipped version:** Always the last stable one. The last compiled version is retrieved from [this directory](https://releases.domoticz.com/releases/?dir=./beta) during install
Once installed, **updates from the uptream app are managed from within the app.**. Yunohost upgrade script will only upgrade the Yunohost package.
The MQTT broker mosquitto is integrated into the package. It requires its own domain or subdomain. It's an optional setting: during install if you set the same domaine as your main app domain, it won't be installed.
## Configuration
### Broker Mosquitto
During installation, a [MQTT](https://en.wikipedia.org/wiki/MQTT) broker is installed at the same time as Domoticz. The broker is Mosquitto with documentation available [here](https://mosquitto.org/). The installed version is the one from the official project repo and not from Debian ones.
This broker requires a dedicated domain or subdomain to work (ex : mqtt.your.domain.tld) : creating this domain prior installation is a prerequisite
####Use
To use mosquitto, you need to customize the communication between domoticz and the broker by following the [domoticz documentation](https://www.domoticz.com/wiki/MQTT#Installing_Mosquitto), part *Add hardware "MQTT Client Gateway"*.
User and password are automatically generated during installation, you may retrieve them with
````
sudo yunohost app setting domoticz mqtt_user
sudo yunohost app setting domoticz mqtt_pwd
````
You can then publish on a device on domoticz with following syntax:
````
mosquitto_pub -u *user* -P *password* -h mqtt.your.domain.tld -p 443 -t 'domoticz/in' -m '{ "idx" : 1, "nvalue" : 0, "svalue" : "25.0" }'
````
In the same way, you may subscribe to a topic with
````
mosquitto_sub -u *user* -P *password* -h mqtt.your.domain.tld -p 443 -t 'domoticz/out'
````
#### Upgrade from version without mosquitto
If you have package ynh3 or below, mosquitto is not installed by default.
If you have chosen to not set a domain during initial installation also.
So, if you need to activate mosquitto in retrospect, do following actions:
1/ Create a domain or a subdomain (for example : 'mqtt.your.domain.tld')
2/ Connect to your server in command line
3/ Type following command : `yunohost app setting domoticz mqtt_domain -v mqtt.your.domain.tld`
4/ Upgrade domoticz to last package.
If you're already on the last package version, use the following command : `yunohost app upgrade domoticz --force`
## Configuration

View file

@ -11,14 +11,49 @@ Il peut par exemple être utilisé avec :
* des voltmètres
* Et bien d'autres
**Version incluse :** Toujours la dernière version stable. La dernière version compilée est récupérée dans [ce répertoire](https://releases.domoticz.com/releases/?dir=./beta)
**Version incluse :** Toujours la dernière version stable. La dernière version compilée est récupérée dans [ce répertoire](https://releases.domoticz.com/releases/?dir=./beta) lors de l'installation
Une fois installée, **les mises à jour de l'application sont gérées depuis les menus de l'application elle même.**. Le script de mise à jour Yunohost mettra uniquement à jour de nouvelles version du package.
Le broker MQTT mosquitto est intégré au package et nécessite un sous-domaine ou un domaine distinct. Il est optionnel et si vous indiquez lors de l'installation le même domaine que le domaine principal, il ne sera pas installé.
## Configuration
### Broker MQTT Mosquitto
A l'installation, un broker [MQTT](https://fr.wikipedia.org/wiki/MQTT) est installé en même temps que Domoticz. Il s'agit du serveur mosquitto dont la documentation est disponible [ici](https://mosquitto.org/). La version installée est celle du dépot officiel du projet, et non des dépots Debian.
Ce broker nécessite un domaine ou un sous-domaine particulier pour fonctionner (ex : mqtt.your.domain.tld) : il est nécessaire de créer ce domaine auparavant.
####Utilisation
Pour pouvoir l'utiliser, vous devez paramétrer la communication avec entre domoticz et le broker en suivant la [documentation de domoticz](https://www.domoticz.com/wiki/MQTT#Installing_Mosquitto) dans la partie *Add hardware "MQTT Client Gateway"*
Les users et mot de passe du broker sont automatiquement générés lors de l'installation. Vous pouvez les récupérer en tapant
````
sudo yunohost app setting domoticz mqtt_user
sudo yunohost app setting domoticz mqtt_pwd
````
Vous pouvez ensuite publier sur ce serveur en utilisant la syntaxe:
````
mosquitto_pub -u *user* -P *password* -h mqtt.your.domain.tld -p 443 -t 'domoticz/in' -m '{ "idx" : 1, "nvalue" : 0, "svalue" : "25.0" }'
````
De la même manière, vous pouvez suivre ce qu'il se passe avec
````
mosquitto_sub -u *user* -P *password* -h mqtt.your.domain.tld -p 443 -t 'domoticz/out'
````
####Mise à jour depuis les versions n'ayant pas mosquitto
Si vous êtes sur le package ynh3 ou inférieur, mosquitto n'est pas installé par défaut.
De même si vous avez choisi de ne pas indiquer de domaine pour mosquitto lors de l'installation initiale.
Pour pouvoir l'installer après coup, faites les actions suivantes:
1/ créez un domaine ou sous-domaine pour recevoir les informations (par exemple : 'mqtt.your.domain.tld')
2/ connecter vous en ligne de commande à votre serveur
3/ taper la commande suivante : `yunohost app setting domoticz mqtt_domain -v mqtt.your.domain.tld`
4/ Procédez à la mise à jour.
Si vous êtes déjà sur la dernière version, utiliser la commmande suivante : `yunohost app upgrade domoticz --force`
### Senseurs, langue et ce genre de choses
Toute la configuration de l'application a lieu dans l'application elle même
Main configuration of the app take place inside the app itself.
### Accès et API
Par défaut, l'accès aux [API JSON](https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's) est autorisé sur cette URL `/votredomaine.tld/api_/chemindedomoticz`.

View file

@ -31,7 +31,7 @@
"install" : [
{
"name": "domain",
"type": "domain",
"type": "domain"
},
{
"name": "path",
@ -43,7 +43,24 @@
"name": "is_public",
"type": "boolean",
"default": false,
"help": "Attention, cette application n'a pas de gestion d'utilisateur par défaut, si vous la mettez public, n importe qui y aura accès!"
"help": {
"fr": "Attention, cette application n'a pas de gestion d'utilisateur par défaut, si vous la mettez public, n importe qui y aura accès!",
"en": "Beware, there is no user management by default. If it's set as public, anyone will have access!"
}
},
{
"name": "mqtt_domain",
"type": "domain",
"ask": {
"fr":"Domaine MQTT",
"en":"MQTT domain"
},
"example": "mqtt.your.domain.com",
"optional": true,
"help": {
"fr": "Domaine pour le serveur MQTT. Remettez le domaine principal si vous ne souhaitez pas l'utiliser. Lire la documentation pour plus d'informations",
"en": "MQTT server domain. Set the main domain if you don't wish to use it. See the doc for more info"
}
}
]
}

View file

@ -11,6 +11,9 @@
pkg_dependencies="libudev-dev python3-dev"
extra_pkg_dependencies="mosquitto mosquitto-clients"
default_mqtt_port=1883
default_mqtt_websocket_port=8083
#ALL FOLLOWING LINE FROM THE upstream bash installation script
DEBIAN_ID=$(grep -oP '(?<=^ID=).+' /etc/*-release | tr -d '"')
DEBIAN_VERSION=$(grep -oP '(?<=^VERSION_ID=).+' /etc/*-release | tr -d '"')

View file

@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
mqtt_domain=$(ynh_app_setting_get --app=$app --key=mqtt_domain)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
@ -47,6 +48,8 @@ ynh_backup --src_path="$final_path"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/nginx/conf.d/$mqtt_domain.d/mqtt_$app.conf" --not_mandatory
#=================================================
# SPECIFIC BACKUP
#=================================================
@ -66,7 +69,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
ynh_backup --src_path="/etc/sudoers.d/$app"
ynh_backup --src_path="/etc/mosquitto/conf.d"
ynh_backup --src_path="/etc/mosquitto/conf.d" --not_mandatory
#=================================================

View file

@ -30,14 +30,11 @@ ynh_script_progression --message="Loading installation settings..."
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
old_api=$(ynh_app_setting_get --app=$app --key=api_path)
old_mqtt=$(ynh_app_setting_get --app=$app --key=mqtt_path)
if [ "$new_path" == "/" ]; then
new_api=/api_/$app
new_mqtt=/mqtt/$app
else
new_api=/api_$new_path
new_mqtt=/mqtt$new_path
fi
@ -100,7 +97,6 @@ then
domain="$old_domain"
path_url="$new_path"
api_path="$new_api"
mqtt_path="$new_mqtt"
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
@ -127,10 +123,6 @@ ynh_app_setting_delete --app=$app --key="api_path"
ynh_app_setting_set --app=$app --key="api_path" --value=$new_api
ynh_permission_url --permission domoticz_API --url "$new_domain$new_api"
ynh_app_setting_delete --app=$app --key="mqtt_path"
ynh_app_setting_set --app=$app --key="mqtt_path" --value=$new_mqtt
ynh_permission_url --permission domoticz_MQTT --url "$new_domain$new_mqtt"
#=================================================
# GENERIC FINALISATION
#=================================================

View file

@ -26,16 +26,15 @@ ynh_abort_if_errors
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
mqtt_domain=$YNH_APP_ARG_MQTT_DOMAIN
app=$YNH_APP_INSTANCE_NAME
#Set dedicated variables
if [ "$path_url" == "/" ]; then
api_path=/api_/$app
mqtt_path=/mqtt/$app
else
api_path=/api_$path_url
mqtt_path=/mqtt$path_url
fi
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
@ -47,6 +46,14 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#impossible de booker plusieurs webpath
#if [ ! -z $mqtt_domain ]; then
# ynh_webpath_register --app=mqtt_$app --domain=$mqtt_domain --path_url="/"
#fi
if [ $domain == $mqtt_domain ]; then
unset $mqtt_domain
fi
#=================================================
# STORE SETTINGS FROM MANIFEST
@ -62,7 +69,9 @@ ynh_app_setting_set --app=$app --key=mach --value=$mach
#path used by api & mqtt to read/update domoticz
ynh_app_setting_set --app=$app --key=api_path --value=$api_path
ynh_app_setting_set --app=$app --key=mqtt_path --value=$mqtt_path
if [ ! -z $mqtt_domain ]; then
ynh_app_setting_set --app=$app --key=mqtt_domain --value=$mqtt_domain
fi
#=================================================
# STANDARD MODIFICATIONS
@ -75,8 +84,13 @@ ynh_script_progression --message="Finding an available port..."
port=$(ynh_find_port --port=8080)
ynh_app_setting_set --app=$app --key=port --value=$port
mqtt_port=$(ynh_find_port --port=1883)
ynh_app_setting_set --app=$app --key=mqtt_port --value=$mqtt_port
if [ ! -z $mqtt_domain ]; then
mqtt_port=$(ynh_find_port --port=$default_mqtt_port)
ynh_app_setting_set --app=$app --key=mqtt_port --value=$mqtt_port
mqtt_websocket_port=$(ynh_find_port --port=$default_mqtt_websocket_port)
ynh_app_setting_set --app=$app --key=mqtt_websocket_port --value=$mqtt_websocket_port
fi
#=================================================
# INSTALL DEPENDENCIES
@ -135,29 +149,38 @@ chown -R $app:$app "$final_path"
#=================================================
# SET MOSQUITTO SETTINGS
#=================================================
ynh_script_progression --message="Setting up mosquitto..." --weight=5
if [ ! -z $mqtt_domain ]; then
#Installing packages
ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian buster main" --package="$extra_pkg_dependencies" --key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key"
ynh_script_progression --message="Setting up mosquitto..." --weight=5
#Setting up conf file for access
ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/domoticz_mosquitto.conf"
#Installing packages
ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian buster main" --package="$extra_pkg_dependencies" --key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key"
#Setting up user&pwd for mqtt access
ynh_app_setting_set --app=$app --key=mqtt_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --app=$app --key=mqtt_pwd --value=$(ynh_string_random)
echo $(ynh_app_setting_get --app=$app --key=mqtt_user):$(ynh_app_setting_get --app=$app --key=mqtt_pwd) > /etc/mosquitto/conf.d/credentials
mosquitto_passwd -U /etc/mosquitto/conf.d/credentials
#Setting up conf file for access
ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/"$app"_mosquitto.conf"
#Setting up user&pwd for mqtt access
ynh_app_setting_set --app=$app --key=mqtt_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --app=$app --key=mqtt_pwd --value=$(ynh_string_random)
echo $(ynh_app_setting_get --app=$app --key=mqtt_user):$(ynh_app_setting_get --app=$app --key=mqtt_pwd) > "/etc/mosquitto/conf.d/"$app"_credentials"
mosquitto_passwd -U "/etc/mosquitto/conf.d/"$app"_credentials"
ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app"
fi
ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
if [ ! -z $mqtt_domain ]; then
ynh_add_config --template="../conf/mqtt_nginx.conf" --destination="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf"
fi
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
@ -180,8 +203,9 @@ chown -R domoticz: /var/log/$app
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
ynh_use_logrotate --logfile="/var/log/mosquitto/"
if [ ! -z $mqtt_domain ]; then
ynh_use_logrotate --logfile="/var/log/mosquitto/"
fi
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
@ -189,7 +213,9 @@ ynh_use_logrotate --logfile="/var/log/mosquitto/"
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Domotique open sources" --log="/var/log/$app/$app.log"
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
if [ ! -z $mqtt_domain ]; then
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
fi
#=================================================
# START SYSTEMD SERVICE
@ -200,7 +226,9 @@ ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start"
#Restarting mosquitto to take changes into account
ynh_systemd_action --service_name=mosquitto --action="restart"
if [ ! -z $mqtt_domain ]; then
ynh_systemd_action --service_name=mosquitto --action="restart"
fi
#=================================================
# SETUP SSOWAT
@ -217,7 +245,9 @@ fi
#API & MQTT should stay publicly accessible.
ynh_permission_create --permission="domoticz_API" --url="$domain$api_path" --allowed="visitors"
ynh_permission_create --permission="domoticz_MQTT" --url="$domain$mqtt_path" --allowed="visitors"
if [ ! -z $mqtt_domain ]; then
ynh_permission_create --permission="domoticz_MQTT" --url="$mqtt_domain" --allowed="visitors"
fi
#=================================================
# RELOAD NGINX

View file

@ -45,12 +45,23 @@ ynh_script_progression --message="Stopping and removing the systemd service..."
ynh_remove_systemd_config
#=================================================
# CLOSE A PORT
#=================================================
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port..." --weight=1
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=3
# Remove metapackage and its dependencies
ynh_secure_remove --file="/etc/mosquitto/conf.d"
ynh_remove_app_dependencies
#=================================================
@ -67,6 +78,7 @@ ynh_secure_remove --file="$final_path"
ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove the dedicated NGINX config
ynh_secure_remove --file="/etc/nginx/"$mqtt_domain".d/mqtt_"$app".conf"
ynh_remove_nginx_config
#=================================================

View file

@ -33,7 +33,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
backup_OS=$(ynh_app_setting_get --app=$app --key=OS)
backup_mach=$(ynh_app_setting_get --app=$app --key=mach)
api_path=$(ynh_app_setting_get --app=$app --key=api_path)
mqtt_path=$(ynh_app_setting_get --app=$app --key=mqtt_path)
mqtt_domain=$(ynh_app_setting_get --app=$app --key=mqtt_domain)
mqtt_user=$(ynh_app_setting_get --app=$app --key=mqtt_user)
mqtt_pwd=$(ynh_app_setting_get --app=$app --key=mqtt_pwd)
@ -59,6 +59,7 @@ test "$backup_mach" = "$mach" \
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/$mqtt_domain.d/mqtt_$app.conf" --not_mandatory
#=================================================
# RECREATE THE DEDICATED USER
@ -106,12 +107,14 @@ ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SET MOSQUITTO SETTINGS
#=================================================
ynh_script_progression --message="Reinstalling up mosquitto..." --weight=5
if [ -z $mqtt_domain]; then
ynh_script_progression --message="Reinstalling up mosquitto..." --weight=5
#Installing packages
ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian buster main" --package="$extra_pkg_dependencies" --key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key"
#reinstalling settings
ynh_restore_file --origin_path="/etc/mosquitto/conf.d"
#Installing packages
ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian buster main" --package="$extra_pkg_dependencies" --key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key"
#reinstalling settings
ynh_restore_file --origin_path="/etc/mosquitto/conf.d" --not_mandatory
fi
#=================================================
# RESTORE SYSTEMD
@ -127,8 +130,9 @@ systemctl enable $app.service --quiet
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Domotique open sources" --log="/var/log/$app/$app.log"
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
if [ -z $mqtt_domain ]; then
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
fi
#=================================================
# START SYSTEMD SERVICE

View file

@ -27,7 +27,9 @@ port=$(ynh_app_setting_get --app=$app --key=port)
current_OS=$(ynh_app_setting_get --app=$app --key=OS)
current_mach=$(ynh_app_setting_get --app=$app --key=mach)
api_path=$(ynh_app_setting_get --app=$app --key=api_path)
mqtt_path=$(ynh_app_setting_get --app=$app --key=mqtt_path)
mqtt_domain=$(ynh_app_setting_get --app=$app --key=mqtt_domain)
mqtt_port=$(ynh_app_setting_get --app=$app --key=mqtt_port)
mqtt_websocket_port=$(ynh_app_setting_get --app=$app --key=mqtt_websocket_port)
#=================================================
# CHECK VERSION
@ -74,7 +76,6 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -104,14 +105,21 @@ if [ -z "$api_path" ]; then
ynh_app_setting_set --app=$app --key=api_path --value=$api_path
fi
#Create a dedicated path for the api access
if [ -z "$mqtt_path" ]; then
if [ "$path_url" == "/" ]; then
mqtt_path=/mqtt/$app
else
mqtt_path=/mqtt$path_url
fi
ynh_app_setting_set --app=$app --key=mqtt_path --value=$mqtt_path
#Create a dedicated path for the mqtt access
if [ -z "$mqtt_domain" ]; then
ynh_print_info --message="Mosquitto, a mqtt server, can now be installed during upgrade, pleaser refer to package documentation to activate it"
fi
#Port to listen for MQTT internal
if [[ -z "$mqtt_port" && ! -z "$mqtt_domain" ]]; then
mqtt_port=$(ynh_find_port --port=$default_mqtt_port)
ynh_app_setting_set --app=$app --key=mqtt_port --value=$mqtt_port
fi
#Port to listen for MQTT websocket
if [[ -z "$mqtt_websocket_port" && ! -z "$mqtt_domain" ]]; then
mqtt_websocket_port=$(ynh_find_port --port=$default_mqtt_websocket_port)
ynh_app_setting_set --app=$app --key=mqtt_websocket_port --value=$mqtt_websocket_port
fi
@ -130,10 +138,12 @@ then
fi
# Create the permission "domoticz_MQTT" only if it doesn't exist.
if ! ynh_permission_exists --permission="domoticz_MQTT"
then
# API Authorization with dedicated URL
ynh_permission_create --permission="domoticz_MQTT" --url="$domain$mqtt_path" --allowed="visitors"
if [ ! -z $mqtt_domain ]; then
if ! ynh_permission_exists --permission="domoticz_MQTT"
then
# API Authorization with dedicated URL
ynh_permission_create --permission="domoticz_MQTT" --url="$mqtt_domain" --allowed="visitors"
fi
fi
@ -185,23 +195,25 @@ chown -R $app:$app "$final_path"
#=================================================
# SET MOSQUITTO SETTINGS
#=================================================
ynh_script_progression --message="Setting up mosquitto..." --weight=5
if [ ! -z $mqtt_domain ]; then
ynh_script_progression --message="Setting up mosquitto..." --weight=5
#Installing packages
ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian buster main" --package="$extra_pkg_dependencies" --key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key"
#Installing packages
ynh_install_extra_app_dependencies --repo="deb https://repo.mosquitto.org/debian buster main" --package="$extra_pkg_dependencies" --key="http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key"
#Setting up conf file for access
if [ ! -f "/etc/mosquitto/conf.d/domoticz_mosquitto.conf" ]
then
ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/domoticz_mosquitto.conf"
#Setting up conf file for access
if [ ! -f "/etc/mosquitto/conf.d/"$app"_mosquitto.conf" ]
then
ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/"$app"_mosquitto.conf"
#Setting up user&pwd for mqtt access
ynh_app_setting_set --app=$app --key=mqtt_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --app=$app --key=mqtt_pwd --value=$(ynh_string_random)
echo $(ynh_app_setting_get --app=$app --key=mqtt_user):$(ynh_app_setting_get --app=$app --key=mqtt_pwd) > /etc/mosquitto/conf.d/credentials
mosquitto_passwd -U /etc/mosquitto/conf.d/credentials
#Setting up user&pwd for mqtt access
ynh_app_setting_set --app=$app --key=mqtt_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --app=$app --key=mqtt_pwd --value=$(ynh_string_random)
echo $(ynh_app_setting_get --app=$app --key=mqtt_user):$(ynh_app_setting_get --app=$app --key=mqtt_pwd) > "/etc/mosquitto/conf.d/"$app"_credentials"
mosquitto_passwd -U "/etc/mosquitto/conf.d/"$app"_credentials"
ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app"
ynh_print_info --message="The credential to the mosquitto server has been saved in the settings of the app"
fi
fi
#=================================================
@ -209,6 +221,10 @@ fi
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
if [ ! -z $mqtt_domain ]; then
ynh_add_config --template="../conf/mqtt_nginx.conf" --destination="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf"
fi
# Create a dedicated NGINX config
ynh_add_nginx_config
@ -241,7 +257,9 @@ chown -R domoticz: /var/log/$app
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
ynh_use_logrotate --logfile="/var/log/mosquitto/" --non-append
if [ ! -z $mqtt_domain ]; then
ynh_use_logrotate --logfile="/var/log/mosquitto/" --non-append
fi
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
@ -249,7 +267,9 @@ ynh_use_logrotate --logfile="/var/log/mosquitto/" --non-append
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Domotique open sources" --log="/var/log/$app/$app.log"
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
if [ ! -z $mqtt_domain ]; then
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
fi
#=================================================
# START SYSTEMD SERVICE
@ -258,9 +278,10 @@ ynh_script_progression --message="Starting a systemd service..." --weight=3
ynh_systemd_action --service_name=$app --action="start"
#Restarting mosquitto to take changes into account
ynh_systemd_action --service_name=mosquitto --action="restart"
#Restarting mosquitto to take changes from /etc/mosquitto/conf.d/*.conf into account
if [ ! -z $mqtt_domain ]; then
ynh_systemd_action --service_name=mosquitto --action="restart"
fi
#=================================================
# RELOAD NGINX
#=================================================