Making a port for ZoneMinder

I'm making the port for ZoneMinder, I have several questions:

1. I need writable directory under /usr/local/www/zoneminder
I try to do it in post-install section of Makefile
Code:
@${MKDIR} ${STAGEDIR}${WWWDIR}/images
@${CHOWN} ${WWWOWN}:${WWWGRP} ${STAGEDIR}${WWWDIR}/images
I see directory in stage folder with right permissions, however it installs with default one. How to change them?
2. Application introduces ELF in cgi-bin. Should I put it /usr/local/libexec as hier suggests or I can leave it in that folder? (webserver will run it).
3. Application generates HUGE number of files (it writes video as jpegs), however they should be in www root. Upstream has plans to move it elsewhere and now they make symlinks. However, this will break chrooted php-fpm installations, but HUGE number of files are candidates to /var according hier Can I keep them in www root ? I saw different approach where to keep big folders depending on slice layout. (/home, /var /usr). If someone want to move them, he can symlink my himself.
4. Application uses /dev/shm Should I suggest users to mount it as tempfs or change defaults to /tmp, mentioning that this will be perfomance hog if placed outside of tmpfs (but, it least it will work).
5. Betatesters, maybe ? This is my first port :)

PS: Ohh, and they type FreeBSD incorrectly! https://github.com/ZoneMinder/ZoneMinder/blob/master/CMakeLists.txt#L185 Should I patch CMake files or emorage in their irc should be enough? :-D
 
I did build and install the Zoneminder version in the ports tree (multimedia/zoneminder) on a FreeBSD system, but I never got it to work satisfactorily with my chosen cameras (Hikvision DS‑2CD2032‑I) . Be aware that version of Zoneminder (1.25.0) is about 5 years old. I found that Zoneminder 1.28.x on a Linux box worked much better than earlier versions, and am testing 1.29.x on one machine.
 
Any idea where I went wrong?Thanks
Yes. pid under Linux can't exceed smallint datatype. This is wrong for FreeBSD. You must change pid datatype of Logs table to INT
Also, I gone www/nginx, I just dislike www/apache bloatware.
"just works" on FreeBSD. Have you tried it?
Yes, it just works, but we must package it and put stuff in right directories. My questions are mostly about correct packaging.

At the moment, I have
Code:
# $FreeBSD$

PORTNAME=   zoneminder
PORTVERSION=   1.29.0
DISTVERSION = ecb8c48
CATEGORIES=   multimedia

MAINTAINER=   foo@bar
COMMENT=   Complete security camera solution, fully web based with image analysis

LICENSE=   GPLv2

USE_GITHUB=   yes
GH_ACCOUNT=   FriendsOfCake:crud
GH_PROJECT=   crud:crud
GH_TAGNAME=   c3976f1:crud

WRKSRC= ${WRKDIR}/ZoneMinder-${DISTVERSION}

BUILD_DEPENDS=   p5-DBI>=0:${PORTSDIR}/databases/p5-DBI \
         p5-DBD-mysql>=0:${PORTSDIR}/databases/p5-DBD-mysql \
         p5-Date-Manip>=0:${PORTSDIR}/devel/p5-Date-Manip \
         p5-Test-LWP-UserAgent>=0:${PORTSDIR}/www/p5-Test-LWP-UserAgent \
         p5-Sys-Mmap>=0:${PORTSDIR}/devel/p5-Sys-Mmap \
         p5-LWP-Protocol-https>=0:${PORTSDIR}/www/p5-LWP-Protocol-https
LIB_DEPENDS=   libpolkit-gobject-1.so:${PORTSDIR}/sysutils/polkit
RUN_DEPENDS=   ${BUILD_DEPENDS}

USES=     cmake jpeg perl5 shebangfix
USE_MYSQL= yes

ZM_RUNDIR=   /var/run/zm
ZM_TMPDIR=   /var/tmp/zm

SHEBANG_FILES=   scripts/zmaudit.pl.in \
         scripts/zmcamtool.pl.in \
         scripts/zmcontrol.pl.in \
         scripts/zmdc.pl.in \
         scripts/zmfilter.pl.in \
         scripts/zmpkg.pl.in \
         scripts/zmsystemctl.pl.in \
         scripts/zmtelemetry.pl.in \
         scripts/zmtrack.pl.in \
         scripts/zmtrigger.pl.in \
         scripts/zmupdate.pl.in \
         scripts/zmvideo.pl.in \
         scripts/zmwatch.pl.in \
         scripts/zmx10.pl.in

CMAKE_ARGS+=   -DZM_PERL_MM_PARMS=INSTALLDIRS=site \
         -DZM_CONFIG_DIR=/usr/local/etc \
         -DZM_WEBDIR=${WWWDIR} \
         -DZM_CGIDIR=${WWWDIR}/cgi-bin \
         -DZM_CONTENTDIR=${WWWDIR}
#CMAKE_ARGS+=   -DCMAKE_VERBOSE_MAKEFILE=ON

post-extract:
   @${MV} ${WRKSRC_crud}/* ${WRKSRC}/web/api/app/Plugin/Crud

post-install:
   ${CP} ${STAGEDIR}${PREFIX}/etc/zm.conf ${STAGEDIR}${PREFIX}/etc/zm.conf.sample
   ${INSTALL} -d -g ${WWWGRP} -o ${WWWOWN} ${STAGEDIR}${WWWDIR}/images
   ${INSTALL} -d -g ${WWWGRP} -o ${WWWOWN} ${STAGEDIR}${WWWDIR}/events
   ${INSTALL} -d -g ${WWWGRP} -o ${WWWOWN} ${STAGEDIR}${ZM_RUNDIR}
   ${INSTALL} -d -g ${WWWGRP} -o ${WWWOWN} ${STAGEDIR}${ZM_TMPDIR}

.include <bsd.port.mk>
The most confusing thing about ${INSTALL}. It generates correct folders in stage dir, but resets permissions on install
Code:
abishai@freezm:~/zoneminder % ls -ld /home/abishai/zoneminder/work/stage/var/tmp/zm
drwxr-xr-x  2 www  www  512 Mar 26 12:55 /home/abishai/zoneminder/work/stage/var/tmp/zm
abishai@freezm:~/zoneminder % ls -ld /var/tmp/zm
drwxr-xr-x  2 root  wheel  512 Mar 26 12:55 /var/tmp/zm
So, I don't know how to create writable directories for ZM automatically.
 
How can i make this change?
mysql -u root -p
use zm;
alter table Logs modify column Pid int default null;

Then, disable STRICT_TRANS_TABLES removing it from sql_mode line on /usr/local/my.cnf
And change index.php error_reporting( E_ALL ); to error_reporting( E_ALL & ~E_NOTICE);

At the moment I have working mostly ZM under www/nginx
1. IP camera in MJPEG works using built-in ZM capture.
2. Detection works
3. Event writing works.

Doesn't work:
1. Montage with more than 1 camera
2. Event replay (signal 4 in zms on attempt to playback)

Not tested:
1. V4L, I even not compiled it as I don't have USB or analog cameras.
2. multimedia/ffmpeg. Not compiled it as well.
3. H264 cameras using ZM capture daemon.
4. It will be nice to test capture with multimedia/ffmpeg backend as well.

I will share entire port files when someone enlighten me how to create directories with proper owner.
 
FYI - the montage doesn't work quite right on the Linux system where I'm testing 1.29.0, so the problem you're seeing with that might not be FreeBSD specific. The grid options don't seem to work right, although it will show multiple cameras. Your code base is probably newer than mine (I installed pre-built images on 10-Feb-2016 from the ppa:iconnor/zoneminder repository).
 
Signal 4 workarounded - I disabled sendfile support as crash was in sendfile() function call - it should fall back to less optimal solution on playback, but at least it works. Now we have almost working Zoneminder here https://github.com/abishai/Zoneminder-port
Known issues are:
1. Only for x64 https://github.com/ZoneMinder/ZoneMinder/issues/1423
2. Stale sock files in /var/run/zm https://github.com/ZoneMinder/ZoneMinder/issues/1424
3. V4L support can't be compiled - no local or analog cameras.
4. vlc support not tested and disabled (someone need it?)
5. Some pl scripts are lacking some deps, but nothing critical, I'm lazy to check them yet.
6. Timestamp lacks of camera name - add leading % to timestamp mask manually in monitor settings. https://github.com/ZoneMinder/ZoneMinder/issues/1426
7. pid file contains pid and killall command errors - amazing! https://github.com/ZoneMinder/ZoneMinder/pull/1422

But, more or less, ZM core is working on my 10.3-BETA1: capture, analysis, record, playback. multimedia/ffmpeg backend tested and works.

Probably, I should write a manual how to get it working with www/nginx and other stuff as it has some tricks. It's a pity I do all of this alone - I'm not a programmer and this is my first port, I recon someone familiar with porting could do all of this and even more in one hour :(
 
I was able to start ZM following your instructions. The web UI loaded up and i was able to add a remote camera. However, i got the following error in the web log:
Code:
ERR Memory map file '/dev/shm/zm.mmap.1' does not exist. zmc might not be running. zmwatch.pl 
FAT Can't open memory map file /dev/shm/zm.mmap.1, probably not enough space free: No such file or directory

My intention is to run ZM in a jail on my server. Can ZM work in a jail?

I also tried pass the following to the jail

Code:
export jail_zm_parameters="allow.sysvipc=1"

But it did not make a difference.
 
That's one of the tricks. We don't have /dev/shm, but we can mount tempfs somewhere (I suggest /tmp). Stop zoneminder and point it to the path, webconfig should have this path somewhere. It can work even on 'normal' directory, however, it will kill your I/O if not tempfs. I think, we should patch default path later and mention that in readme.
 
Probably, I should write a manual how to get it working with www/nginx and other stuff as it has some tricks. It's a pity I do all of this alone - I'm not a programmer and this is my first port, I recon someone familiar with porting could do all of this and even more in one hour :(
Can you upload a sharfile of what you have so far?
 
That's one of the tricks. We don't have /dev/shm, but we can mount tempfs somewhere (I suggest /tmp). Stop zoneminder and point it to the path, webconfig should have this path somewhere. It can work even on 'normal' directory, however, it will kill your I/O if not tempfs. I think, we should patch default path later and mention that in readme.

Ok, I created tmpfs on the host and mounted in the jail.

On Host
Code:
#cat /etc/fstab.zm
/usr/jails/basejail /usr/jails/zm/basejail nullfs ro 0 0
tmpfs /usr/jails/zm/tmp/shm tmpfs rw,mode=777 0 0

In the jail, the memory is available
Code:
root@zm:~ # ls -lad /tmp/shm
drwxrwxrwx  2 root  wheel  0 Apr 18 21:40 /tmp/shm

Changed the PATH_MAP variable in ZM webconfig, but I still get the error
Code:
Can't open memory map file /tmp/shm/zm.mmap.1, probably not enough space free: Permission denied
---------------------------------------------
UPDATE: After doing a chown www:www /tmp/shm, I can see mmap files being created. 'Modect' works fine and alarm frames do get created.
 
The advantage of the shar archive is that anyone can just download and save it and then unpack it immediately by executing it, no extra tools needed.
 
Uuuh, this is evil:

Code:
post-extract:
        @${MV} ${WRKSRC_crud}/* ${WRKSRC}/web/api/app/Plugin/Crud
${WRKSRC_crud} is not set, so running this as root moved /* to ${WRKSRC}/web/api/app/Plugin/Crud :p

Apart from that it's not so bad. :) I checked with portlint -ac and fixed all errors and warnings. The result is attached.
Note before that I haven't tested the port yet. I just fixed the messages, created a new distinfo and ran make patch which worked.

Please try to build and use it. :)
 

Attachments

  • zoneminder_lme.zip
    43.7 KB · Views: 310
Oh, sorry, I didn't realize you're fetching multiple distfiles. I changed the GH variables, so it didn't work for me. Then you should re-add this in my version of the port.
 
Oh, sorry, I didn't realize you're fetching multiple distfiles. I changed the GH variables, so it didn't work for me. Then you should re-add this in my version of the port.
See? I'm not bad after all :)

I have an error during stagify:
Code:
===>  zoneminder-1.29.1.a.20160420 depends on package: perl5>=5.20<5.21 - found
install  -m 0644 /usr/home/abishai/zoneminder/work/stage/usr/local/etc/zm.conf /usr/home/abishai/zoneminder/work/stage/usr/local/etc/zm.conf.sample
install: /usr/home/abishai/zoneminder/work/stage/usr/local/etc/zm.conf: No such file or directory
I copied zm.conf to zm.conf.sample there for reference. Looks like ${INSTALL_DATA} makes something else?
 
Last edited by a moderator:
Back
Top