jgcb00
March 4, 2022, 9:02pm
21
Ok, that’s what I don’t understand well:
Does this correspond to the default values? Or to what is currently being used on Docker? Because if it’s what’s currently running on Docker, it’s easy to retrieve. So I’m convinced I don’t understand the problem well since the solution seems simple to me.
VonOx
March 4, 2022, 9:06pm
22
Well that’s simple but if your path is /here/toto there’s no way to guess that it’s the mount on the host.
That could work but we’ll see what others think.
I’m trying to anticipate problems
I edited my previous message
jgcb00
March 4, 2022, 9:16pm
23
So in my case, you get:
[
'/var/run/docker.sock:/var/run/docker.sock',
'/run/udev:/run/udev',
'/dev:/dev',
'/mnt/user/appdata/Gladys:/var/lib/gladysassistant'
]
But on the right side, it’s always the same thing /var/lib/gladysassistant/ it never changes, so that’s what allows you to identify it, right?
Edit after seeing your edit: yes, I completely agree with you, but you seemed to have found a method to do it automatically, right or wrong?
VonOx
March 4, 2022, 9:20pm
24
In theory, yes, it does not change.
Edit: yes, the idea is to list the mounts, look for /var/lib/gladysassistant and take the value on the left
The /var/lib/gladysassistant comes from the SQLITE_FILE_PATH, so I wouldn’t say it never moves either, but yes it is known in the code
So to summarize, two options:
Option 1: Extract the folder from the mounted volumes, by finding the right folder thanks to the SQLITE_FILE_PATH
Option 2: Environment variable, like GLADYS_FOLDER_PATH_ON_HOST, which is perhaps more explicit and more predictable. Especially since in the case where we launch Gladys via Syno or Unraid, we can very well add this variable.
guim31
March 7, 2022, 9:09am
26
I, who have been using UNRAID for quite some time, think that option 2 is the best. All the more so since it is easy in the Unraid template to comment on the fields to be filled in to guide the user if necessary
To bounce back on all this, I went to see the code to try to see if I could do it, but in fact all this is already coded so I don’t understand anything anymore
The Zigbee2mqtt integration indeed calls the basePath function:
filters: { name: [containerDescriptor.name] },
});
let [container] = dockerContainers;
if (dockerContainers.length === 0) {
let containerMqtt;
try {
logger.info('MQTT broker is being installed as Docker container...');
logger.info(`Pulling ${containerDescriptor.Image} image...`);
await this.gladys.system.pull(containerDescriptor.Image);
// Prepare broker env
logger.info(`Preparing broker environment...`);
const containerDescriptorToMutate = cloneDeep(containerDescriptor);
const { basePathOnContainer, basePathOnHost } = await this.gladys.system.getGladysBasePath();
const mosquittoFolderPath = path.join(basePathOnContainer, '/zigbee2mqtt/mqtt');
const mosquittoConfigFilePath = path.join(mosquittoFolderPath, 'mosquitto.conf');
const mosquittoPasswordFilePath = path.join(mosquittoFolderPath, 'mosquitto.passwd');
logger.info(`Writing Mosquitto config file in ${mosquittoConfigFilePath}`);
const { basePathOnContainer, basePathOnHost } = await this.basePath();
Which itself returns the host side path:
https://github.com/GladysAssistant/Gladys/blob/master/server/services/zigbee2mqtt/lib/basePath.js#L23
So I don’t understand why it doesn’t work, the code is there!
@cicoub13 tell me if that rings a bell!
VonOx
March 7, 2022, 5:29pm
29
In reading the code, I get the impression that it’s reversed, that we’re retrieving the path on the container side, am I wrong?
});
let [container] = dockerContainers;
if (dockerContainers.length === 0) {
let containerMqtt;
try {
logger.info('MQTT broker is being installed as Docker container...');
logger.info(`Pulling ${containerDescriptor.Image} image...`);
await this.gladys.system.pull(containerDescriptor.Image);
// Prepare broker env
logger.info(`Preparing broker environment...`);
const containerDescriptorToMutate = cloneDeep(containerDescriptor);
const { basePathOnContainer, basePathOnHost } = await this.gladys.system.getGladysBasePath();
const mosquittoFolderPath = path.join(basePathOnContainer, '/zigbee2mqtt/mqtt');
const mosquittoConfigFilePath = path.join(mosquittoFolderPath, 'mosquitto.conf');
const mosquittoPasswordFilePath = path.join(mosquittoFolderPath, 'mosquitto.passwd');
logger.info(`Writing Mosquitto config file in ${mosquittoConfigFilePath}`);
gladys-z2m-mqtt-env.sh ${basePathOnContainer}
This is normal, this part takes place in the container.
The place where the volume is defined is here:
if (dockerContainers.length === 0) {
let containerMqtt;
try {
logger.info('MQTT broker is being installed as Docker container...');
logger.info(`Pulling ${containerDescriptor.Image} image...`);
await this.gladys.system.pull(containerDescriptor.Image);
// Prepare broker env
logger.info(`Preparing broker environment...`);
const containerDescriptorToMutate = cloneDeep(containerDescriptor);
const { basePathOnContainer, basePathOnHost } = await this.gladys.system.getGladysBasePath();
const mosquittoFolderPath = path.join(basePathOnContainer, '/zigbee2mqtt/mqtt');
const mosquittoConfigFilePath = path.join(mosquittoFolderPath, 'mosquitto.conf');
const mosquittoPasswordFilePath = path.join(mosquittoFolderPath, 'mosquitto.passwd');
logger.info(`Writing Mosquitto config file in ${mosquittoConfigFilePath}`);
// Ensure that the mosquitto folder exist
await fse.ensureDir(mosquittoFolderPath);
However, there is something that doesn’t work, this line mutates the global json object, so it pushes every time this function is called, and it affects the global variable, that’s not good.
VonOx
March 7, 2022, 5:37pm
33
Do you think that’s the problem?
I don’t think this is the bug here, but in any case it’s certain that this issue is causing bugs
I launched a small VM to test all this.
I started a container with the following parameters:
docker run -d \
# removed for readability
-v /var/lib/gladysassistant_other_folder:/var/lib/gladysassistant \
gladysassistant/gladys:v4
I added some logs, and I started a Zigbee2mqtt container, and here’s what it gives:
2022-03-07T18:55:44+0100 <info> installMqttContainer.js:25 (Zigbee2mqttManager.installMqttContainer) MQTT broker is being installed as Docker container...
2022-03-07T18:55:44+0100 <info> installMqttContainer.js:26 (Zigbee2mqttManager.installMqttContainer) Pulling eclipse-mosquitto:2 image...
2022-03-07T18:55:47+0100 <info> installMqttContainer.js:30 (Zigbee2mqttManager.installMqttContainer) Preparing broker environment...
{
basePathOnContainer: '/var/lib/gladysassistant',
basePathOnHost: '/var/lib/gladysassistant'
}
[ '/var/lib/gladysassistant/zigbee2mqtt/mqtt:/mosquitto/config' ]
2022-03-07T18:55:47+0100 <info> installMqttContainer.js:37 (Zigbee2mqttManager.installMqttContainer) Creating container...
2022-03-07T18:55:47+0100 <info> installMqttContainer.js:51 (Zigbee2mqttManager.installMqttContainer) MQTT broker is restarting...
The basePathOnHost is not correct, there is a bug in the basePath function
I am investigating…
I’m going further after adding logs, the call:
const gladysMounts = await this.gladys.system.getContainerMounts(os.hostname());
Returns an empty array… So, gladysMounts is empty and the default is applied..
I continue my investigation
I think I understand, the function expects a containerId:
const { PlatformNotCompatible } = require('../../utils/coreErrors');
/**
* @description Return list of mounts for this container.
* @param {string} containerId - Id of the container.
* @returns {Promise} Resolve with list of mounts.
* @example
* const binds = await getContainerMounts('e24ae1745d91');
*/
async function getContainerMounts(containerId) {
if (!this.dockerode) {
throw new PlatformNotCompatible('SYSTEM_NOT_RUNNING_DOCKER');
}
const containers = await this.dockerode.listContainers({
filters: { id: [containerId] },
});
const [container] = containers;
if (!container) {
return [];
And behind the function sends the hostname:
https://github.com/GladysAssistant/Gladys/blob/master/server/services/zigbee2mqtt/lib/basePath.js#L17
We should send the current container’s id
I created a GitHub issue with the details:
ouvert 06:10PM - 07 Mar 22 UTC
fermé 09:42AM - 29 Mar 22 UTC
bug
zigbee2mqtt
The function here needs the containerId => https://github.com/GladysAssistant/Gl… adys/blob/master/server/lib/system/system.getContainerMounts.js#L10
But instead, sends the os.hostname() =>
https://github.com/GladysAssistant/Gladys/blob/master/server/services/zigbee2mqtt/lib/basePath.js#L17
Discussions here =>
https://community.gladysassistant.com/t/gladys-sur-unraid/6959/37?u=pierre-gilles
And:
ouvert 06:12PM - 07 Mar 22 UTC
fermé 09:43AM - 29 Mar 22 UTC
bug
zigbee2mqtt
Push mutate the global object :
https://github.com/GladysAssistant/Gladys/bl… ob/master/server/services/zigbee2mqtt/lib/installZ2mContainer.js#L37
https://github.com/GladysAssistant/Gladys/blob/master/server/services/zigbee2mqtt/lib/installMqttContainer.js#L34
jgcb00
March 8, 2022, 9:24pm
39
Thanks a lot for these advancements,
With the release of 4.8, this will be an opportunity to test the update on unraid because I don’t run watchtower…
Therefore, I’m waiting to see if it offers to update the docker image with a new one
Keep us posted! However, what I mentioned about Unraid (the fixes related to Zigbee2mqtt) are not in this 4.8, it will be available in the next update I worked on it this morning, it was too late to include in 4.8.
jgcb00
March 8, 2022, 9:29pm
41
Yes, I suspected as much, no problem, the instance is working on my side, we are not in a hurry, the more time passes, the more Gladys becomes competitive, so it’s better to leave some time.
Thanks a lot anyway, the update is very nice!