ZoneMinder - Shared Memory Docker /dev/shm

Cribz

Cadet
Joined
Feb 4, 2021
Messages
6
Hi,

Apologies if this question has been answered elsewhere however I've searched the TruenNAS Scale Project forum and was not able to locate any information about it. Again I know Scale is in Alpha and there are things that wont work. Any help is appreciated.

Currently Running : TrueNAS-SCALE-21.02-MASTER-20210209-032917

Having issues where I'm running ZoneMinder via docker on my TrueNAS Scale box and unable to record more than 1 camera due to the shared memory at /dev/shm reaching it's limit. There is a docker argument to include to increase the shared memory (--shm-size="5G") however I am unsure on how to do this via the TrueNAS application UI.

Any help will be appreciated.
 

ornias

Wizard
Joined
Mar 6, 2020
Messages
1,458
Hi,

Apologies if this question has been answered elsewhere however I've searched the TruenNAS Scale Project forum and was not able to locate any information about it. Again I know Scale is in Alpha and there are things that wont work. Any help is appreciated.

Currently Running : TrueNAS-SCALE-21.02-MASTER-20210209-032917

Having issues where I'm running ZoneMinder via docker on my TrueNAS Scale box and unable to record more than 1 camera due to the shared memory at /dev/shm reaching it's limit. There is a docker argument to include to increase the shared memory (--shm-size="5G") however I am unsure on how to do this via the TrueNAS application UI.

Any help will be appreciated.
Both arguments and environment variables are clearly labeled and available in the SCALE docker-container installation wizard afaik. So I don't really get what you are asking here....
 

Cribz

Cadet
Joined
Feb 4, 2021
Messages
6
tried putting --shm-size="5G" via the application UI in either one of the fields "Container CMD" or "Container Args" however the container refuses to run i.e. stuck on "deploying" on the UI.

Basically all I'm wanting to do is increase the default shared memory (64m) that gets assigned to the container. Totally possible if you're running docker natively and just tested it out on a Linux box. However not sure how to do the same in Scale.

Code:
docker run -d --name="Zoneminder" \
--net="bridge" \
--privileged="false" \
--shm-size="5G" \
-p 8443:443/tcp \
-p 9000:9000/tcp \
-e TZ="America/New_York" \
-e PUID="99" \
-e PGID="100" \
-e INSTALL_HOOK="0" \
-e INSTALL_FACE="0" \
-e INSTALL_TINY_YOLOV3="0" \
-e INSTALL_YOLOV3="0" \
-e INSTALL_TINY_YOLOV4="0" \
-e INSTALL_YOLOV4="0" \
-e MULTI_PORT_START="0" \
-e MULTI_PORT_END="0" \
-v "/mnt/Zoneminder":"/config":rw \
-v "/mnt/Zoneminder/data":"/var/cache/zoneminder":rw \
dlandon/zoneminder


 

shadofall

Contributor
Joined
Jun 2, 2020
Messages
100
So I did a little digging. and I fully admit I could be wrong. but everything I saw in regards to shm-size and kubernetes kept bringing me back to needing something like this

Code:
volumeMounts:
  - mountPath: /dev/shm
    name: dshm
volumes:
- name: dshm
      emptyDir:
        medium: Memory
       
 
Last edited:

ornias

Wizard
Joined
Mar 6, 2020
Messages
1,458
So I did a little digging. and I fully admit I could be wrong. but everything I saw in regards to shm-size and kubernetes kept bringing me back to needing something like this

Code:
volumeMounts:
  - mountPath: /dev/shm
    name: dshm
volumes:
- name: dshm
      emptyDir:
        medium: Memory
       
Damn you're right @shadofall It's a known k8s bug/issue.
Your dshm solution should work just fine :)
 

Cribz

Cadet
Joined
Feb 4, 2021
Messages
6
Thanks so much. Finally got it working. Added the below to the deployment and it worked.

volumeMounts:
- mountPath: /dev/shm
name: dshm

volumes:
- emptyDir:
medium: Memory
name: dshm
 

nicolasvi

Dabbler
Joined
Jul 22, 2020
Messages
10
Hi, this thread helped me uderstand a way to solve this issue. I didnt understand where Cribz used that commands. This is how i solved it:

Created a dataset with this permisions in TrueNAS Scale:
Captura de pantalla (401).png


Aded this HOST PATH VOLUME in docker edit:
Captura de pantalla (400).png


Maybe there is a better way to do it, this was mine

Thanks!
 

overeat

Dabbler
Joined
Aug 31, 2021
Messages
20
tried putting --shm-size="5G" via the application UI in either one of the fields "Container CMD" or "Container Args" however the container refuses to run i.e. stuck on "deploying" on the UI.

I have the exact same problem and was attempting to add this via "Configure Container Args -> Add" but when I do this, deploy or start simply hangs.

I'm not personally creating my own deploy scripts and am just attempting to add this argument via "Launch Docker Image" to a pre-existing docker scripts.

What's the best way to get this done if I'm not rolling my own deployment scripts (or where do the scripts end up so I can edit them on the file system)


Hi, this thread helped me uderstand a way to solve this issue. I didnt understand where Cribz used that commands. This is how i solved it:
I don't believe this is ideal, as /dev/shm is shared memory so it would be fast. The way you're doing it (i believe) is on disk and would be slow. It should work, but it won't perform well.

Something like this would be better, but not ideal as it eats memory even when your docker isnt running. You would also have to add it to /etc/fstab to make it permanent, unless there's some kind of pre-exec and post-exec script for these docker images.

You can create a tmpfs (which is memory) file system


Code:
mkdir /mnt/YOURPOOL/zoneminder/shm
mount -t tmpfs -o size=8g tmpfs /mnt/YOURPOOL/zoneminder/shm


Then mount /mnt/YOURPOOL/zoneminder/shm to /dev/shm via the docker UI
 
Last edited:

shadofall

Contributor
Joined
Jun 2, 2020
Messages
100
I have the exact same problem and was attempting to add this via "Configure Container Args -> Add" but when I do this, deploy or start simply hangs.

I'm not personally creating my own deploy scripts and am just attempting to add this argument via "Launch Docker Image" to a pre-existing docker scripts.

What's the best way to get this done if I'm not rolling my own deployment scripts (or where do the scripts end up so I can edit them on the file system)
so currently for truecharts apps you can specify a emptydir with a type of memory and specify the /dev/shm mount path. (dont know if would need to use the lables for the dshm name)

but in theory that should work

course there is no zoneminder app in truecharts at the moment. so you would have to use the currently in testing (incubator train so still in testing) custom app to test it (which is an in development version of the big blue docker button for truecharts) so it can and possible will break and change and need to be reinstalled in the future but for testing go for it say., but i'm speculating at this point as I have no way to test it my self
 

overeat

Dabbler
Joined
Aug 31, 2021
Messages
20
so currently for truecharts apps you can specify a emptydir with a type of memory and specify the /dev/shm mount path. (dont know if would need to use the lables for the dshm name)

but in theory that should work

course there is no zoneminder app in truecharts at the moment. so you would have to use the currently in testing (incubator train so still in testing) custom app to test it (which is an in development version of the big blue docker button for truecharts) so it can and possible will break and change and need to be reinstalled in the future but for testing go for it say., but i'm speculating at this point as I have no way to test it my self
Thanks for the reply. I realize there'a way to do this with helm. I cloned the directory and was looking at the sample templates to attempt to make one for zoneminder, but because I'm unfamiliar with kubernates and helm, this was going to take longer than I was willing to invest yesterday. I want to figure out a way to simply hack this together. It helps me learn kubernates anyways, so will help with me making helms in the future.

I did think it would be a good idea to make a helm which simply runs a docker compose file, so idiots like me can just do bare minimum and hack the docker compose files and kind of ignore helm.

Another issue:

I have an issue with my tmpfs method. I have nightly snapshots running currently (they always reboot my system for unknown reasons and fail, but that's another issue). I did notice the snapshot also backed up the tmpfs filesystem and still has it mounted upon reboot, which takes up 8gb of memory. I assume that's not a good thing and will cause problems.

Is that a bug, or intended behaviour with zfs snapshots. I'm new to Truenas so excuse my ignorance.

Also it appeared to remove my /etc/fstab stuff upon reboot, so I need to figure out another way to do this.
 

stavros-k

Patron
Joined
Dec 26, 2020
Messages
231
I did think it would be a good idea to make a helm which simply runs a docker compose file, so idiots like me can just do bare minimum and hack the docker compose files and kind of ignore helm.
I don't think this will ever be happening, not because people don't want to, but because it's nearly impossible. Not all docker functions map to k8s and vice/versa.


Also it appeared to remove my /etc/fstab stuff upon reboot, so I need to figure out another way to do this.
You can add scripts to run after reboot on TrueNAS (IIRC it's on system settings)

Thanks for the reply. I realize there'a way to do this with helm. I cloned the directory and was looking at the sample templates to attempt to make one for zoneminder
I wouldn't recommend starting all this journey with something like zoneminder. It's way too complicated!
If you would like to learn, start with small, simple apps and grow from there!
 

li_chang

Dabbler
Joined
May 31, 2017
Messages
35
Hello, I am struggling with setting shm with zoneminder as well... There is a "Configure Memory Backed VolumesAdd" section in the settting, does it work if something is set here correctly? Thank you.

Screen Shot 2021-10-22 at 9.08.07 AM.png




update: after trying this option out (put /dev/shm inside "Mount Path" here), it works like a charm! can verify it with df -h in the container (32GB physical memory)

Code:
root@zm-ml-ix-chart-8784f998f-ggwvm:~# df -h  | grep /dev/shm
tmpfs                                                                                          16G  128M   16G   1% /dev/shm


Screenshot 2021-11-20 052017.jpg
 
Last edited:

shadofall

Contributor
Joined
Jun 2, 2020
Messages
100
haven't actually tried it, but that sounds exactly like where /dev/shm should be entered
 

cptkoolbeenz

Cadet
Joined
Feb 3, 2022
Messages
7
Checking to see how to properly increase /dev/shm
I used the following to configure shm for my zoneminder instance. It increased the shm size from 64MB to 64GB. Great! But where is the 64GB value coming from?

1660153453039.png
 

NugentS

MVP
Joined
Apr 16, 2020
Messages
2,947
so currently for truecharts apps you can specify a emptydir with a type of memory and specify the /dev/shm mount path. (dont know if would need to use the lables for the dshm name)

but in theory that should work

course there is no zoneminder app in truecharts at the moment. so you would have to use the currently in testing (incubator train so still in testing) custom app to test it (which is an in development version of the big blue docker button for truecharts) so it can and possible will break and change and need to be reinstalled in the future but for testing go for it say., but i'm speculating at this point as I have no way to test it my self
Actually there is - its in the incubator branch.
It is however very old / quite old, needs a minor mod to the URL if you press the open button AND won't work with my test camera for whatever reason.
 

shadofall

Contributor
Joined
Jun 2, 2020
Messages
100
Actually there is - its in the incubator branch.
It is however very old / quite old, needs a minor mod to the URL if you press the open button AND won't work with my test camera for whatever reason.
Well there is now. But not when I posted that and 2021. However given that the upstream container was deprecated some time ago. And I don't think anyone's put out a new project on it. I would be skeptical on it making it to stable. And even if it did I wouldn't recommend it since that container will no longer get new versions or security updates
 

NugentS

MVP
Joined
Apr 16, 2020
Messages
2,947
That was my impression too. I have deleted it since
 

shadofall

Contributor
Joined
Jun 2, 2020
Messages
100
I just check out the zone minder forums. Seems they are attempting an official image. But apparently they can't follow best practices for docker as they have no real docker dev so it's apparently not a very good image. At least that was the gist I got from the thread
 
Top