Home
About Me!
Projects
Research
Links
Gallery
Travel
   
Random Header Image
Disable Enable
More Info



ZoneMinder Install on Gentoo

Overview:
Installation of ZoneMinder on Gentoo Linux. Shown below are the notes I made when installing the motion detection application ZoneMinder on Gentoo. Some code has to be changed for correct operation on Gentoo. This is related to installing zoneminder as a service.

Notes:
Zone Minder Install (v.1.21.3) on Gentoo

emerge zoneminder
emerge --unmerge ffmpeg
emerge /usr/portage/media-video/ffmpeg/ffmpeg-0.4.8.ebuild
emerge zoneminder

cd /etc/init.d
apache2 -k start -D INFO -D DEFAULT_VHOST -D PHP4

/etc/init.d/mysql start
/usr/bin/mysql_install_db
/etc/init.d/mysql start
/usr/bin/mysqladmin -u root password 'new-password'

cd /usr/share/doc/zoneminder-VERSION
gunzip zmschema.sql.gz && mysql mysql < zmschema.sql
(FAILED)
NOTE: Change zmschema.sql line 7 to "USE zm" instead of "USE zm;"
mysql -p mysql < zmschema.sql
mysql -p mysql
> grant select,insert,update,delete on zm.* to 'zm'@localhost identified by 'zoneminder';
> quit
mysqladmin -p reload

nano /etc/zm.conf (to set db username and password)

NOTE: mysql was not compiled into mod_php. Added mysql into
USE variable in /etc/make.conf
emerge --newuse mod_php

cd /etc/init.d
apache2 -k stop
apache2 -k start -D INFO -D DEFAULT_VHOST -D PHP4

NOTE: zmconfig.pl needs to be run to put important configuration
settings into the database before zoneminder will work properly.
Download the tar from zoneminder website and extract. Then run:
./configure --prefix=/usr --with-webdir=/var/www/localhost/htdocs/ --with-cgidir=/var/www/localhost/cgi-bin/ --with-mysql=/usr/ --with-ffmpeg=/usr/
/usr/bin/mysqladmin -p -u root password ''
perl zmconfig.pl

chmod 777 /var/www/localhost/htdocs/zoneminder/
chmod 777 /var/log/zoneminder/

emerge dev-perl/libwww-perl
emerge dev-perl/DateManip

chmod 666 /dev/video0
chmod 666 /dev/video1
chmod 666 /dev/video2
chmod 666 /dev/video3

tail -n 90 -f /var/log/messages
tail -n 90 -f /var/log/zoneminder/<logfile>

Shared Memory:
Problems arrise if the resolution of the captured images is set to
as high value as it requires more shared memory than is available.
To check your system's shared memory amount:
# cat /proc/sys/kernel/shmall
# cat /proc/sys/kernel/shmmax
To set it to a higher value (128MB) temporarily:
# echo 134217728 >/proc/sys/kernel/shmall
# echo 134217728 >/proc/sys/kernel/shmmax
Permanently you can do this by modifying the parameters kernel.shmall
and kernel.shmmax from /etc/sysctl.conf. (If these parameters don't
exist in sysctl.conf, create them)

change zm_config.php to the following:
//define( "ZM_PATH_WEB", "/usr/share/webapps/zoneminder/1.21.3/htdocs-secure" ); // Path to the ZoneMinder web files, autogenerated do not change (from zmconfig)
define( "ZM_PATH_WEB", "/var/www/localhost/htdocs/zoneminder/" );
//define( "ZM_PATH_CGI", "/usr/share/webapps/zoneminder/1.21.3/hostroot/cgi-bin" ); // Path to the ZoneMinder cgi files, autogenerated do not change (from zmconfig)
define( "ZM_PATH_CGI", "/var/www/localhost/cgi-bin/" );

NOTE: Events directory issue
It appears the an absolute path is required for ZM_DIR_EVENTS to get
the daemon to write successfully to the events directory. This is probably
because the daemon is being run from somewhere outside the web directory.
I am not sure how to find out where it is being run from, or how to change
where it's initial execution directory is. If anyone has any ideas please
let me know.
Solution: My solution was to add the directory into the apache conf file.
I actually added this to the DEFAULT_VHOST section of
/etc/apache2/vhosts.d/00_default_vhost.conf as it appears DEFAULT_VHOST
is defined when running apache using /etc/init.d/apache2 start.

Alias /raid/zoneminder/events /raid/zoneminder/events
<Directory "/raid/zoneminder/events">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

See http://httpd.apache.org/docs/2.2/urlmapping.html

Removed comments around IfDefine of /etc/apache2/modules.d/70_mod_php.conf
so apache runs php4 by default.

rc-update add apache2 default
rc-update add mysql default

UPDATE: The workaround for the events directory issue seems to cause problems
with the streaming server (zms) as it is looking for the directory:
/usr/share/webapps/zoneminder/1.21.3/htdocs-secure//raid/zoneminder/events/...
This suggests the /usr/share/webapps/zoneminder/1.21.3/htdocs-secure/
directory was hardcoded at build time and the ZM_DIR_EVENTS path needs to be
relative rather than abosulte. I may need to recompile zoneminder using
the tar from the zoneminder website (instead of using the gentoo package) so I
can give it the proper location of the zoneminder web and cgi files.
Perhaps this was the reason for the event capture not working too and the error
from zma was not providing the full path (however zms was).

./configure --prefix=/usr --with-webdir=/var/www/localhost/htdocs/zoneminder/ --with-cgidir=/var/www/localhost/cgi-bin/ --with-mysql=/usr/ --with-ffmpeg=/usr/
perl zmconfig.pl (accept all settings)
make
make install

-----------Now works fine!--------
Even with cambozola :) (Just place jar in webdir)

UPDATE: New version available

mysqldump --add-drop-table --databases zm > zm.dump
./configure --prefix=/usr --with-webdir=/var/www/localhost/htdocs/zoneminder/ --with-cgidir=/var/www/localhost/cgi-bin/ --with-mysql=/usr/ --with-ffmpeg=/usr/
perl zmconfig.pl
make
make install
mysql
> grant select,insert,update,delete,alter on zm.* to 'zm'@localhost identified by 'zoneminder';
> quit
zmupdate.pl --version=1.21.3

-----------Update successful!--------

--- To run zoneminder at bootup: ---
emerge app-admin/sudo
Change line 157 of /usr/bin/zmpkg.pl to:
$command = "sudo -u ".ZM_WEB_USER." $command";
This is because the su ... --shell ... command does not work on gentoo.

Then use the following as /etc/init.d/zm

#!/sbin/runscript

depend() {
need net
}

start() {
ebegin "Starting ZoneMinder"
/usr/bin/zmpkg.pl start
eend $?
}

stop() {
ebegin "Stopping ZoneMinder"
/usr/bin/zmpkg.pl stop
eend $?
}

Finally use the following command to add zm to the default runlevel:
rc-update add zm default

-------Logging------

To prevent the syslog from being filled with dubug messages:

You can prevent this information from being emitted by setting the ZM_DBG_LEVEL_zmc environment variable to -1 or less once things are working.

create /etc/env.d/80zoneminder containing:

ZM_DBG_LEVEL_zmc="-1"

then do:
env-update && source /etc/profile

not sure if this needs a restart of zoneminder to kick in?

--------Upgrade to v1.22.0 -----------

mysqldump --add-drop-table --databases zm > zm.dump
./configure --prefix=/usr --with-webdir=/var/www/localhost/htdocs/zoneminder/ --with-cgidir=/var/www/localhost/cgi-bin/ --with-mysql=/usr/ --with-ffmpeg=/usr/
edit zm.conf to set database username and password
make
make install
mysql
> grant select,create,insert,update,delete,alter on zm.* to 'zm'@localhost identified by 'zoneminder';
> quit
zmupdate.pl --version=1.21.4

Instructions to update zmpkg.pl script for gentoo:
Need to use sudo and remove quotes around command by changing the following lines:

    247         my $prefix = "sudo -u ".ZM_WEB_USER;
    248         my $command = $prefix." ".$null_command." ";

    311                 $command = $cmd_prefix." ".$command." ";

----- To enable camera control for the evi-d30 -----
change command for visca pl script from /usr/bin/local to /usr/bin

To do this I had to change go to the database directly as the web interface
complained about using non alphanumeric chars.

mysql
\u zm
update Controls set command = '/usr/bin/...' where command =
'/usr/bin/local...';

emerge dev-perl/Device-SerialPort

To enable serial port access for apache:

cd /dev/tts
chown apache 0

To allow editing of control settings for "Sony VISCA" I needed to change the name to "SonyVISCA". This was necessary to stop the web form complaining of the space in the name.

mysql
\u
zm
update Controls set Name = 'SonyVISCA' where Name = 'Sony VISCA';

NOTE: editing the settings using the webform did not seem to work. I edited the settings directly in the database using commands such as:
update Controls set MaxPanRange = '4000' where Name = 'SonyVISCA';

I reduced the speed, step and range settings for the pan and tilt options for the evi-d30 camera.

The zoom buttons only seem to work at maximum speed (when clicked at the tip of the arrow).