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-26 09:30:42 +02:00
parent 15c0379f0c
commit 5d546797cd
8 changed files with 186 additions and 196 deletions

View file

@ -1,24 +1,3 @@
;; Test sans Mosquitto
; Manifest
; 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&
;; Test avec Mosquitto ;; Test avec Mosquitto
; pre-install ; pre-install
set -euxo pipefail set -euxo pipefail
@ -27,17 +6,44 @@ Notification=none
set -euxo pipefail set -euxo pipefail
yunohost app setting domoticz mqtt_domain -v mqtt.domain.tld yunohost app setting domoticz mqtt_domain -v mqtt.domain.tld
; Manifest ; Manifest
domain="domain.tld" (DOMAIN)
path="/domoticz" (PATH)
is_public=1 (PUBLIC|public=1|private=0)
mqtt_domain="mqtt.domain.tld" mqtt_domain="mqtt.domain.tld"
; Checks ; Checks
pkg_linter=1 pkg_linter=1
setup_sub_dir=1 setup_sub_dir=1
setup_root=1 setup_root=1
setup_private=1 setup_private=1
setup_public=1 setup_public=0
upgrade=1 upgrade=1
upgrade=1 from_commit=048ae59a016755b0829a4e8f3ed5d0dbbd1b826b upgrade=1 from_commit=048ae59a016755b0829a4e8f3ed5d0dbbd1b826b
backup_restore=1 backup_restore=1
port_already_use=1 port_already_use=0
change_url=1
;;; Options
Email=nicolas@aubonalbanais.ovh
Notification=none
;;; Upgrade options
; commit=048ae59a016755b0829a4e8f3ed5d0dbbd1b826b
name=Package ynh3
;; Test sans Mosquitto
; Manifest
domain="domain.tld" (DOMAIN)
path="/domoticz" (PATH)
is_public=1 (PUBLIC|public=1|private=0)
mqtt_domain="sub.domain.tld"
; Checks
pkg_linter=0
setup_sub_dir=1
setup_root=1
setup_private=1
setup_public=0
upgrade=1
upgrade=1 from_commit=048ae59a016755b0829a4e8f3ed5d0dbbd1b826b
backup_restore=1
port_already_use=0
change_url=1 change_url=1
;;; Options ;;; Options
Email=nicolas@aubonalbanais.ovh Email=nicolas@aubonalbanais.ovh
@ -45,5 +51,4 @@ Notification=none
;;; Upgrade options ;;; Upgrade options
; commit=048ae59a016755b0829a4e8f3ed5d0dbbd1b826b ; commit=048ae59a016755b0829a4e8f3ed5d0dbbd1b826b
name=Package ynh3 name=Package ynh3
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass

View file

@ -12,8 +12,8 @@ For example this system can be used with:
* And more ... * 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) during install **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. 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. 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.
@ -21,10 +21,10 @@ The MQTT broker mosquitto is integrated into the package. It requires its own do
### Broker Mosquitto ### 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. During installation, a [MQTT](https://en.wikipedia.org/wiki/MQTT) broker, [Mosquitto](https://mosquitto.org/), is installed at the same time as Domoticz. 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 This broker requires a dedicated domain or subdomain to work (ex : mqtt.your.domain.tld) : creating this domain prior installation is a prerequisite
####Use #### 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"*. 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 User and password are automatically generated during installation, you may retrieve them with

View file

@ -11,8 +11,8 @@ Il peut par exemple être utilisé avec :
* des voltmètres * des voltmètres
* Et bien d'autres * 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) lors de l'installation **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. 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é. 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é.
@ -20,7 +20,7 @@ Le broker MQTT mosquitto est intégré au package et nécessite un sous-domaine
### Broker MQTT Mosquitto ### 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. A l'installation, un broker [MQTT](https://fr.wikipedia.org/wiki/MQTT), [Mosquitto](https://mosquitto.org/), est installé en même temps que Domoticz. 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. 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 ####Utilisation

View file

@ -47,8 +47,7 @@ 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/$domain.d/$app.conf"
[[ ! -z "$mqtt_domain" ]] && ynh_backup --src_path="/etc/nginx/conf.d/$mqtt_domain.d/mqtt_$app.conf" --not_mandatory
ynh_backup --src_path="/etc/nginx/conf.d/$mqtt_domain.d/mqtt_$app.conf" --not_mandatory
#================================================= #=================================================
# SPECIFIC BACKUP # SPECIFIC BACKUP
@ -69,7 +68,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
#================================================= #=================================================
ynh_backup --src_path="/etc/sudoers.d/$app" ynh_backup --src_path="/etc/sudoers.d/$app"
ynh_backup --src_path="/etc/mosquitto/conf.d" --not_mandatory [[ ! -z "$mqtt_domain" ]] && ynh_backup --src_path="/etc/mosquitto/conf.d" --not_mandatory
#================================================= #=================================================

View file

@ -23,36 +23,36 @@ ynh_abort_if_errors
# RETRIEVE ARGUMENTS FROM THE MANIFEST # RETRIEVE ARGUMENTS FROM THE MANIFEST
#================================================= #=================================================
domain=$YNH_APP_ARG_DOMAIN domain="$YNH_APP_ARG_DOMAIN"
path_url=$YNH_APP_ARG_PATH path_url="$YNH_APP_ARG_PATH"
is_public=$YNH_APP_ARG_IS_PUBLIC is_public="$YNH_APP_ARG_IS_PUBLIC"
mqtt_domain=$YNH_APP_ARG_MQTT_DOMAIN mqtt_domain="$YNH_APP_ARG_MQTT_DOMAIN"
app=$YNH_APP_INSTANCE_NAME app="$YNH_APP_INSTANCE_NAME"
#Set dedicated variables #Set dedicated variables
if [ "$path_url" == "/" ]; then if [ "$path_url" == "/" ]; then
api_path=/api_/$app api_path=/api_/"$app"
else else
api_path=/api_$path_url api_path=/api_"$path_url"
fi fi
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_script_progression --message="Validating installation parameters..." ynh_script_progression --message="Validating installation parameters..."
final_path=/opt/yunohost/$app final_path=/opt/yunohost/"$app"
test ! -e "$final_path" || ynh_die --message="This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path # Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url"
#impossible de booker plusieurs webpath #impossible de booker plusieurs webpath
#if [ ! -z $mqtt_domain ]; then #if [ ! -z $mqtt_domain ]; then
# ynh_webpath_register --app=mqtt_$app --domain=$mqtt_domain --path_url="/" # ynh_webpath_register --app=mqtt_$app --domain=$mqtt_domain --path_url="/"
#fi #fi
if [ $domain == $mqtt_domain ]; then if [ "$domain" == "$mqtt_domain" ]; then
unset $mqtt_domain mqtt_domain=""
fi fi
#================================================= #=================================================
@ -60,17 +60,17 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app="$app" --key=domain --value="$domain"
ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app="$app" --key=path --value="$path_url"
#Will be used in restore script to check that we're restoring on the same OS/Board type #Will be used in restore script to check that we're restoring on the same OS/Board type
ynh_app_setting_set --app=$app --key=OS --value=$os ynh_app_setting_set --app="$app" --key=OS --value="$os"
ynh_app_setting_set --app=$app --key=mach --value=$mach ynh_app_setting_set --app="$app" --key=mach --value="$mach"
#path used by api & mqtt to read/update domoticz #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=api_path --value="$api_path"
if [ ! -z $mqtt_domain ]; then if [ ! -z "$mqtt_domain" ]; then
ynh_app_setting_set --app=$app --key=mqtt_domain --value=$mqtt_domain ynh_app_setting_set --app="$app" --key=mqtt_domain --value="$mqtt_domain"
fi fi
#================================================= #=================================================
@ -78,18 +78,19 @@ fi
#================================================= #=================================================
# FIND AND OPEN A PORT # FIND AND OPEN A PORT
#================================================= #=================================================
ynh_script_progression --message="Finding an available port..." ynh_script_progression --message="Finding available port..."
# Find an available port # Find an available port
port=$(ynh_find_port --port=8080) port=$(ynh_find_port --port=8080)
ynh_app_setting_set --app=$app --key=port --value=$port ynh_app_setting_set --app="$app" --key=port --value="$port"
if [ ! -z $mqtt_domain ]; then if [ ! -z "$mqtt_domain" ]; then
mqtt_port=$(ynh_find_port --port=$default_mqtt_port) ynh_script_progression --message="Finding available ports for Mosquitto..."
ynh_app_setting_set --app=$app --key=mqtt_port --value=$mqtt_port 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) 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 ynh_app_setting_set --app="$app" --key=mqtt_websocket_port --value="$mqtt_websocket_port"
fi fi
#================================================= #=================================================
@ -97,7 +98,7 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Installing dependencies..." --weight=15 ynh_script_progression --message="Installing dependencies..." --weight=15
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies "$pkg_dependencies"
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
@ -105,29 +106,29 @@ ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Configuring system user..." ynh_script_progression --message="Configuring system user..."
# Create a system user # Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path ynh_system_user_create --username="$app" --home_dir="$final_path"
#allow user to access USB / serial port to communicate with tools (RFXtrx, Z-wave dongle, etc.) & i2c bus #allow user to access USB / serial port to communicate with tools (RFXtrx, Z-wave dongle, etc.) & i2c bus
if grep dialout -q < /etc/group; then if grep dialout -q < /etc/group; then
usermod -a -G dialout $app usermod -a -G dialout "$app"
fi fi
if grep i2c -q < /etc/group; then if grep i2c -q < /etc/group; then
usermod -a -G i2c $app usermod -a -G i2c "$app"
fi fi
if grep gpio -q < /etc/group; then if grep gpio -q < /etc/group; then
usermod -a -G gpio $app usermod -a -G gpio "$app"
fi fi
#allow app user to restart service on startup #allow app user to restart service on startup
ynh_add_config --template="../conf/sudoer" --destination="/etc/sudoers.d/$app" ynh_add_config --template="../conf/sudoer" --destination="/etc/sudoers.d/$app"
chmod 440 /etc/sudoers.d/$app chmod 440 /etc/sudoers.d/"$app"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --weight=5 ynh_script_progression --message="Setting up source files..." --weight=5
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
# Create an app.src for the correct version of domoticz # Create an app.src for the correct version of domoticz
# match string are fulfilled in _common.sh via the upstream bash installation script # match string are fulfilled in _common.sh via the upstream bash installation script
@ -136,20 +137,20 @@ ynh_add_config --template="../conf/app.src.default" --destination="../conf/app.s
ynh_setup_source --dest_dir="$final_path" ynh_setup_source --dest_dir="$final_path"
#Create the database file #Create the database file
if [ ! -f $final_path/domoticz.db ]; then if [ ! -f "$final_path"/domoticz.db ]; then
touch $final_path/domoticz.db touch "$final_path"/domoticz.db
chmod 640 $final_path/domoticz.db chmod 640 "$final_path"/domoticz.db
fi fi
chmod 750 "$final_path" chmod 750 "$final_path"
chmod -R o-rwx "$final_path" chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path" chown -R "$app":"$app" "$final_path"
#================================================= #=================================================
# SET MOSQUITTO SETTINGS # SET MOSQUITTO SETTINGS
#================================================= #=================================================
if [ ! -z $mqtt_domain ]; then if [ ! -z "$mqtt_domain" ]; then
ynh_script_progression --message="Setting up mosquitto..." --weight=5 ynh_script_progression --message="Setting up mosquitto..." --weight=5
@ -160,9 +161,9 @@ if [ ! -z $mqtt_domain ]; then
ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/"$app"_mosquitto.conf" ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/"$app"_mosquitto.conf"
#Setting up user&pwd for mqtt access #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_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --app=$app --key=mqtt_pwd --value=$(ynh_string_random) 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" 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" 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"
@ -173,9 +174,7 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2 ynh_script_progression --message="Configuring NGINX web server..." --weight=2
if [ ! -z $mqtt_domain ]; then [[ ! -z "$mqtt_domain" ]] && ynh_add_config --template="../conf/mqtt_nginx.conf" --destination="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf"
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 # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
@ -198,24 +197,21 @@ ynh_add_systemd_config
#================================================= #=================================================
ynh_script_progression --message="Configuring log rotation..." ynh_script_progression --message="Configuring log rotation..."
mkdir -p /var/log/$app mkdir -p /var/log/"$app"
chown -R domoticz: /var/log/$app chown -R domoticz: /var/log/"$app"
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate ynh_use_logrotate
if [ ! -z $mqtt_domain ]; then [[ ! -z "$mqtt_domain" ]] && ynh_use_logrotate --logfile="/var/log/mosquitto/"
ynh_use_logrotate --logfile="/var/log/mosquitto/"
fi
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." 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 "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log"
if [ ! -z $mqtt_domain ]; then [[ ! -z "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
fi
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -223,12 +219,11 @@ fi
ynh_script_progression --message="Starting a systemd service..." ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" ynh_systemd_action --service_name="$app" --action="start"
#Restarting mosquitto to take changes into account #Restarting mosquitto to take changes into account
if [ ! -z $mqtt_domain ]; then [[ ! -z "$mqtt_domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart"
ynh_systemd_action --service_name=mosquitto --action="restart"
fi
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
@ -236,7 +231,7 @@ fi
ynh_script_progression --message="Configuring permissions..." ynh_script_progression --message="Configuring permissions..."
# Make app public if necessary # Make app public if necessary
if [ $is_public -eq 1 ] if [ "$is_public" -eq 1 ]
then then
# Everyone can access the app. # Everyone can access the app.
# The "main" permission is automatically created before the install script. # The "main" permission is automatically created before the install script.
@ -245,9 +240,8 @@ fi
#API & MQTT should stay publicly accessible. #API & MQTT should stay publicly accessible.
ynh_permission_create --permission="domoticz_API" --url="$domain$api_path" --allowed="visitors" ynh_permission_create --permission="domoticz_API" --url="$domain$api_path" --allowed="visitors"
if [ ! -z $mqtt_domain ]; then [[ ! -z "$mqtt_domain" ]] && ynh_permission_create --permission="domoticz_MQTT" --url="$mqtt_domain" --allowed="visitors"
ynh_permission_create --permission="domoticz_MQTT" --url="$mqtt_domain" --allowed="visitors"
fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX

View file

@ -14,13 +14,12 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app="$YNH_APP_INSTANCE_NAME"
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app="$app" --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port) port=$(ynh_app_setting_get --app="$app" --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name) final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
db_user=$db_name mqtt_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
@ -29,11 +28,11 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) # 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 if ynh_exec_warn_less yunohost service status "$app" >/dev/null
then then
ynh_script_progression --message="Removing $app service integration..." ynh_script_progression --message="Removing $app service integration..."
yunohost service remove $app yunohost service remove "$app"
yunohost service remove mosquitto [[ ! -z "$mqtt_domain" ]] && yunohost service remove mosquitto
fi fi
#================================================= #=================================================
@ -52,7 +51,7 @@ ynh_remove_systemd_config
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
ynh_script_progression --message="Closing port $port..." --weight=1 ynh_script_progression --message="Closing port $port..." --weight=1
ynh_exec_warn_less yunohost firewall disallow TCP $port ynh_exec_warn_less yunohost firewall disallow TCP "$port"
fi fi
#================================================= #=================================================
@ -61,7 +60,7 @@ fi
ynh_script_progression --message="Removing dependencies..." --weight=3 ynh_script_progression --message="Removing dependencies..." --weight=3
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_secure_remove --file="/etc/mosquitto/conf.d" [[ ! -z "$mqtt_domain" ]] && ynh_secure_remove --file="/etc/mosquitto/conf.d"
ynh_remove_app_dependencies ynh_remove_app_dependencies
#================================================= #=================================================
@ -78,7 +77,8 @@ ynh_secure_remove --file="$final_path"
ynh_script_progression --message="Removing NGINX web server configuration..." ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_secure_remove --file="/etc/nginx/"$mqtt_domain".d/mqtt_"$app".conf" [[ ! -z "$mqtt_domain" ]] && ynh_secure_remove --file="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf"
ynh_remove_nginx_config ynh_remove_nginx_config
#================================================= #=================================================
@ -98,7 +98,7 @@ ynh_script_progression --message="Removing various files..."
# Remove the log files # Remove the log files
ynh_secure_remove --file="/var/log/$app" ynh_secure_remove --file="/var/log/$app"
ynh_secure_remove --file="/var/log/mosquitto" [[ ! -z "$mqtt_domain" ]] && ynh_secure_remove --file="/var/log/mosquitto"
#Delete the sudoer file #Delete the sudoer file
ynh_secure_remove --file="/etc/sudoers.d/$app" ynh_secure_remove --file="/etc/sudoers.d/$app"
@ -111,7 +111,7 @@ ynh_secure_remove --file="/etc/sudoers.d/$app"
ynh_script_progression --message="Removing the dedicated system user..." ynh_script_progression --message="Removing the dedicated system user..."
# Delete a system user # Delete a system user
ynh_system_user_delete --username=$app ynh_system_user_delete --username="$app"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -25,23 +25,20 @@ ynh_abort_if_errors
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app="$YNH_APP_INSTANCE_NAME"
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app="$app" --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) path_url=$(ynh_app_setting_get --app="$app" --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
backup_OS=$(ynh_app_setting_get --app=$app --key=OS) backup_OS=$(ynh_app_setting_get --app="$app" --key=OS)
backup_mach=$(ynh_app_setting_get --app=$app --key=mach) backup_mach=$(ynh_app_setting_get --app="$app" --key=mach)
api_path=$(ynh_app_setting_get --app=$app --key=api_path) mqtt_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain)
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)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_script_progression --message="Validating restoration parameters..." ynh_script_progression --message="Validating restoration parameters..."
test ! -d $final_path \ test ! -d "$final_path" \
|| ynh_die --message="There is already a directory: $final_path " || ynh_die --message="There is already a directory: $final_path "
#As we are downloading compiled binaries for each system, we have to check if the restore occurs #As we are downloading compiled binaries for each system, we have to check if the restore occurs
#on the same system type. If we are restoring on another system type it won't work and in that #on the same system type. If we are restoring on another system type it won't work and in that
@ -67,17 +64,17 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$mqtt_domain.d/mqtt_$app.conf"
ynh_script_progression --message="Recreating the dedicated system user..." ynh_script_progression --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path ynh_system_user_create --username="$app" --home_dir="$final_path"
#allow user to access USB / serial port to communicate with tools (RFXtrx, Z-wave dongle, etc.) & i2c bus #allow user to access USB / serial port to communicate with tools (RFXtrx, Z-wave dongle, etc.) & i2c bus
if grep dialout -q < /etc/group; then if grep dialout -q < /etc/group; then
usermod -a -G dialout $app usermod -a -G dialout "$app"
fi fi
if grep i2c -q < /etc/group; then if grep i2c -q < /etc/group; then
usermod -a -G i2c $app usermod -a -G i2c "$app"
fi fi
if grep gpio -q < /etc/group; then if grep gpio -q < /etc/group; then
usermod -a -G gpio $app usermod -a -G gpio "$app"
fi fi
#Restore user authorization to restart server #Restore user authorization to restart server
@ -92,7 +89,7 @@ ynh_restore_file --origin_path="$final_path"
chmod 750 "$final_path" chmod 750 "$final_path"
chmod -R o-rwx "$final_path" chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path" chown -R "$app":"$app" "$final_path"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
@ -102,12 +99,12 @@ chown -R $app:$app "$final_path"
ynh_script_progression --message="Reinstalling dependencies..." --weight=5 ynh_script_progression --message="Reinstalling dependencies..." --weight=5
# Define and install dependencies # Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies "$pkg_dependencies"
#================================================= #=================================================
# SET MOSQUITTO SETTINGS # SET MOSQUITTO SETTINGS
#================================================= #=================================================
if [ -z $mqtt_domain]; then if [ ! -z "$mqtt_domain" ]; then
ynh_script_progression --message="Reinstalling up mosquitto..." --weight=5 ynh_script_progression --message="Reinstalling up mosquitto..." --weight=5
#Installing packages #Installing packages
@ -122,38 +119,37 @@ fi
ynh_script_progression --message="Restoring the systemd configuration..." --weight=3 ynh_script_progression --message="Restoring the systemd configuration..." --weight=3
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet systemctl enable "$app".service --quiet
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." 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 "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log"
if [ -z $mqtt_domain ]; then [[ ! -z "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
fi
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
#Restarting mosquitto to take changes into account #Restarting mosquitto to take changes into account
ynh_systemd_action --service_name=mosquitto --action="restart" [[ ! -z "$mqtt_domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart"
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." ynh_script_progression --message="Restoring the logrotate configuration..."
mkdir -p /var/log/$app mkdir -p /var/log/"$app"
chown -R domoticz: /var/log/$app chown -R domoticz: /var/log/"$app"
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_use_logrotate --logfile="/var/log/mosquitto/" [[ ! -z "$mqtt_domain" ]] && ynh_use_logrotate --logfile="/var/log/mosquitto/"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -18,18 +18,18 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app="$YNH_APP_INSTANCE_NAME"
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app="$app" --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) path_url=$(ynh_app_setting_get --app="$app" --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port) port=$(ynh_app_setting_get --app="$app" --key=port)
current_OS=$(ynh_app_setting_get --app=$app --key=OS) current_OS=$(ynh_app_setting_get --app="$app" --key=OS)
current_mach=$(ynh_app_setting_get --app=$app --key=mach) current_mach=$(ynh_app_setting_get --app="$app" --key=mach)
api_path=$(ynh_app_setting_get --app=$app --key=api_path) api_path=$(ynh_app_setting_get --app="$app" --key=api_path)
mqtt_domain=$(ynh_app_setting_get --app=$app --key=mqtt_domain) mqtt_domain=$(ynh_app_setting_get --app="$app" --key=mqtt_domain)
mqtt_port=$(ynh_app_setting_get --app=$app --key=mqtt_port) mqtt_port=$(ynh_app_setting_get --app="$app" --key=mqtt_port)
mqtt_websocket_port=$(ynh_app_setting_get --app=$app --key=mqtt_websocket_port) mqtt_websocket_port=$(ynh_app_setting_get --app="$app" --key=mqtt_websocket_port)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
@ -47,8 +47,8 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
# It creates a dummy file in /etc/cron.d so that the backup do not fail. # It creates a dummy file in /etc/cron.d so that the backup do not fail.
current_upstream_version=$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$app/manifest.json") current_upstream_version=$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$app/manifest.json")
current_package_version=$(ynh_app_package_version --manifest="/etc/yunohost/apps/$app/manifest.json") current_package_version=$(ynh_app_package_version --manifest="/etc/yunohost/apps/$app/manifest.json")
if version_gt "4.9701" "$current_upstream_version" && version_gt "2" $current_package_version ; then if version_gt "4.9701" "$current_upstream_version" && version_gt "2" "$current_package_version" ; then
touch /etc/cron.d/$app touch /etc/cron.d/"$app"
fi fi
# Backup the current version of the app # Backup the current version of the app
@ -60,8 +60,8 @@ ynh_clean_setup () {
} }
#remove ugly hack #remove ugly hack
if [ -f /etc/cron.d/$app ]; then if [ -f /etc/cron.d/"$app" ]; then
rm /etc/cron.d/$app rm /etc/cron.d/"$app"
fi fi
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -74,7 +74,7 @@ ynh_abort_if_errors
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=2 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" ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
@ -83,26 +83,26 @@ ynh_script_progression --message="Ensuring downward compatibility..."
#Store OS and machine (to be used in restore script) #Store OS and machine (to be used in restore script)
if [ -z "$current_OS" ]; then if [ -z "$current_OS" ]; then
ynh_app_setting_set --app=$app --key=OS --value=$OS ynh_app_setting_set --app="$app" --key=OS --value="$OS"
fi fi
if [ -z "$current_mach" ]; then if [ -z "$current_mach" ]; then
ynh_app_setting_set --app=$app --key=mach --value=$MACH ynh_app_setting_set --app="$app" --key=mach --value="$MACH"
fi fi
# If final_path doesn't exist, create it # If final_path doesn't exist, create it
if [ -z "$final_path" ]; then if [ -z "$final_path" ]; then
final_path=/var/www/$app final_path=/var/www/"$app"
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
fi fi
#Create a dedicated path for the api access #Create a dedicated path for the api access
if [ -z "$api_path" ]; then if [ -z "$api_path" ]; then
if [ "$path_url" == "/" ]; then if [ "$path_url" == "/" ]; then
api_path=/api_/$app api_path=/api_/"$app"
else else
api_path=/api_$path_url api_path=/api_"$path_url"
fi fi
ynh_app_setting_set --app=$app --key=api_path --value=$api_path ynh_app_setting_set --app="$app" --key=api_path --value="$api_path"
fi fi
#Create a dedicated path for the mqtt access #Create a dedicated path for the mqtt access
@ -112,14 +112,14 @@ fi
#Port to listen for MQTT internal #Port to listen for MQTT internal
if [[ -z "$mqtt_port" && ! -z "$mqtt_domain" ]]; then if [[ -z "$mqtt_port" && ! -z "$mqtt_domain" ]]; then
mqtt_port=$(ynh_find_port --port=$default_mqtt_port) mqtt_port=$(ynh_find_port --port="$default_mqtt_port")
ynh_app_setting_set --app=$app --key=mqtt_port --value=$mqtt_port ynh_app_setting_set --app="$app" --key=mqtt_port --value="$mqtt_port"
fi fi
#Port to listen for MQTT websocket #Port to listen for MQTT websocket
if [[ -z "$mqtt_websocket_port" && ! -z "$mqtt_domain" ]]; then if [[ -z "$mqtt_websocket_port" && ! -z "$mqtt_domain" ]]; then
mqtt_websocket_port=$(ynh_find_port --port=$default_mqtt_websocket_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 ynh_app_setting_set --app="$app" --key=mqtt_websocket_port --value="$mqtt_websocket_port"
fi fi
@ -127,7 +127,7 @@ fi
if ynh_legacy_permissions_exists; then if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public ynh_app_setting_delete --app="$app" --key=is_public
fi fi
# Create the permission "domoticz_API" only if it doesn't exist. # Create the permission "domoticz_API" only if it doesn't exist.
@ -138,7 +138,7 @@ then
fi fi
# Create the permission "domoticz_MQTT" only if it doesn't exist. # Create the permission "domoticz_MQTT" only if it doesn't exist.
if [ ! -z $mqtt_domain ]; then if [ ! -z "$mqtt_domain" ]; then
if ! ynh_permission_exists --permission="domoticz_MQTT" if ! ynh_permission_exists --permission="domoticz_MQTT"
then then
# API Authorization with dedicated URL # API Authorization with dedicated URL
@ -153,22 +153,22 @@ fi
ynh_script_progression --message="Making sure dedicated system user exists..." ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing) # Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path ynh_system_user_create --username="$app" --home_dir="$final_path"
#allow user to access USB / serial port to communicate with tools (RFXtrx, Z-wave dongle, etc.) & i2c bus #allow user to access USB / serial port to communicate with tools (RFXtrx, Z-wave dongle, etc.) & i2c bus
if grep dialout -q < /etc/group; then if grep dialout -q < /etc/group; then
usermod -a -G dialout $app usermod -a -G dialout "$app"
fi fi
if grep i2c -q < /etc/group; then if grep i2c -q < /etc/group; then
usermod -a -G i2c $app usermod -a -G i2c "$app"
fi fi
if grep gpio -q < /etc/group; then if grep gpio -q < /etc/group; then
usermod -a -G gpio $app usermod -a -G gpio "$app"
fi fi
#allow app user to restart service on startup #allow app user to restart service on startup
ynh_add_config --template="../conf/sudoer" --destination="/etc/sudoers.d/$app" ynh_add_config --template="../conf/sudoer" --destination="/etc/sudoers.d/$app"
chmod 440 /etc/sudoers.d/$app chmod 440 /etc/sudoers.d/"$app"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
@ -182,20 +182,20 @@ then
ynh_add_config --template="../conf/app.src.default" --destination="../conf/app.src" ynh_add_config --template="../conf/app.src.default" --destination="../conf/app.src"
ynh_setup_source --dest_dir="$final_path" ynh_setup_source --dest_dir="$final_path"
#Create the database file #Create the database file
if [ ! -f $final_path/domoticz.db ]; then if [ ! -f "$final_path"/domoticz.db ]; then
touch $final_path/domoticz.db touch "$final_path"/domoticz.db
chmod 644 $final_path/domoticz.db chmod 644 "$final_path"/domoticz.db
fi fi
fi fi
chmod 750 "$final_path" chmod 750 "$final_path"
chmod -R o-rwx "$final_path" chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path" chown -R "$app":"$app" "$final_path"
#================================================= #=================================================
# SET MOSQUITTO SETTINGS # SET MOSQUITTO SETTINGS
#================================================= #=================================================
if [ ! -z $mqtt_domain ]; then if [ ! -z "$mqtt_domain" ]; then
ynh_script_progression --message="Setting up mosquitto..." --weight=5 ynh_script_progression --message="Setting up mosquitto..." --weight=5
#Installing packages #Installing packages
@ -207,9 +207,9 @@ if [ ! -z $mqtt_domain ]; then
ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/"$app"_mosquitto.conf" ynh_add_config --template="../conf/domoticz_mosquitto.conf" --destination="/etc/mosquitto/conf.d/"$app"_mosquitto.conf"
#Setting up user&pwd for mqtt access #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_user --value=$(ynh_string_random --length=8)
ynh_app_setting_set --app=$app --key=mqtt_pwd --value=$(ynh_string_random) 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" 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" 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"
@ -221,9 +221,8 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." ynh_script_progression --message="Upgrading NGINX web server configuration..."
if [ ! -z $mqtt_domain ]; then [[ ! -z "$mqtt_domain" ]] && ynh_add_config --template="../conf/mqtt_nginx.conf" --destination="/etc/nginx/conf.d/"$mqtt_domain".d/mqtt_"$app".conf"
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 # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
@ -233,7 +232,7 @@ ynh_add_nginx_config
#================================================= #=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=5 ynh_script_progression --message="Upgrading dependencies..." --weight=5
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies "$pkg_dependencies"
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
@ -252,36 +251,33 @@ ynh_add_systemd_config
#================================================= #=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." ynh_script_progression --message="Upgrading logrotate configuration..."
mkdir -p /var/log/$app mkdir -p /var/log/"$app"
chown -R domoticz: /var/log/$app chown -R domoticz: /var/log/"$app"
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
if [ ! -z $mqtt_domain ]; then [[ ! -z "$mqtt_domain" ]] && ynh_use_logrotate --logfile="/var/log/mosquitto/" --non-append
ynh_use_logrotate --logfile="/var/log/mosquitto/" --non-append
fi
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." 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 "$app" --description="Domotique open sources" --log="/var/log/$app/$app.log"
if [ ! -z $mqtt_domain ]; then [[ ! -z "$mqtt_domain" ]] && yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
yunohost service add mosquitto --description="Serveur MQTT pour domoticz" --log="/var/log/mosquitto/mosquitto.log"
fi
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3 ynh_script_progression --message="Starting a systemd service..." --weight=3
ynh_systemd_action --service_name=$app --action="start" ynh_systemd_action --service_name="$app" --action="start"
#Restarting mosquitto to take changes from /etc/mosquitto/conf.d/*.conf into account #Restarting mosquitto to take changes from /etc/mosquitto/conf.d/*.conf into account
if [ ! -z $mqtt_domain ]; then [[ ! -z "$mqtt_domain" ]] && ynh_systemd_action --service_name=mosquitto --action="restart"
ynh_systemd_action --service_name=mosquitto --action="restart"
fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================