Apr 25 2007

ZoneMinder Ubuntu

Published by Mugwug at 08:37:23 under Budget CCTV

In the process of getting ZoneMinder to work properly on my Ubuntu computer I’ve installed and reinstalled both several times. It seems Ubuntu is really not the best Linux distribution for Zoneminder according to the support forums. It will work, but it will take some effort.

I’m pleased to say that this most recent attempt functions as it should, and I’ve yet to see any problems. To save myself the effort next time around I figured I’d record the installation procedure that worked for me. I know most readers don’t care about this, so the instructions are below the cut.

I’ve installed Zoneminder on Ubuntu 6.0.6 using these instructions from the ZoneMinder Wikis instructions for Ubuntu 6.06 alternate installation with a few minor changes.

Modify Synaptic to include all repositories, then search for and install the following;

  • install
  • apache2
  • php5
  • php5-mysql
  • libapache2-mod-auth-mysql
  • mysql-server
  • g++
  • make
  • netpbm
  • libssl-dev
  • libjpeg62-dev
  • libmime-perl
  • libwww-perl
  • libarchive-tar-perl
  • libdate-manip-perl
  • libarchive-zip-perl
  • libmime-lite-perl
  • libdbi-perl
  • libdbd-mysql-perl
  • libpcre3-dev
  • libmysqlclient12-dev
  • libcurl3-openssl-dev
  • libjpeg-mmx-dev
  • liblwp-protocol-http-socketunix-perl
  • mc
  • ffmpeg

[Note: Original instructions include xawtv on this list, but I've never used it in my various installs so I've omitted it here]

Restart apache: (for those unfamiliar with Ubuntu go to accessories and select terminal, you’ll need the command line for the rest of these instructions.)

sudo /etc/init.d/apache2 restart

Configure and Compile Zoneminder:

cd /usr/local/src
sudo wget http://www2.zoneminder.com/downloads/ZoneMinder-1.22.3.tar.gz
sudo tar -xvzf ZoneMinder-1.22.3.tar.gz
cd ZoneMinder-1.22.3
sudo ./configure –with-webdir=/var/www/zm –with-cgidir=/usr/lib/cgi-bin –with-webuser=www-data –with-webgroup=www-data

Configure MySql:

At the command line type the following;

sudo mysql < db/zm_create.sql
sudo mysql mysql
GRANT ALL PRIVILEGES ON zm.* TO 'zmuser'@localhost identified by 'zmpass';
quit

Now reload the MySql databases;

sudo mysqladmin reload

Install Zoneminder:

cd /usr/local/src/ZoneMinder-1.22.3
sudo make install

Configure Zoneminder auto-start:

Create a file /etc/init.d/zm containing the following:


#!/bin/sh
# description: Control ZoneMinder as a Service
# chkconfig: 2345 99 00
# Source function library.
#. /etc/rc.d/init.d/functions

prog=ZoneMinder
ZM_VERSION=”1.22.3″
ZM_PATH_BIN=”/usr/local/bin”
ZM_CONFIG=”/usr/local/etc/zm.conf”
command=”$ZM_PATH_BIN/zmpkg.pl”

loadconf()
{
if [ -f $ZM_CONFIG ]; then
. $ZM_CONFIG
else
echo “ERROR: $ZM_CONFIG not found.”
return 1
fi
}

# Check for old config and update if needed
checkcfg()
{
# Check config
if [ "$ZM_DB_HOST" = "" -o "$ZM_DB_NAME" = "" -o "$ZM_DB_USER" = "" -o "$ZM_DB_PASS" = "" ]; then
if [ "$ZM_DB_SERVER" != "" -a "$ZM_DB_NAME" != "" -a "$ZM_DB_USERA" != "" -a "$ZM_DB_PASSA" != "" ]; then
echo -n “Converting $ZM_CONFIG”
cp $ZM_CONFIG $ZM_CONFIG.old && \
cat $ZM_CONFIG.old | \
grep -v ZM_DB_USERB | \
grep -v ZM_DB_PASSB | \
sed -e ’s/ZM_DB_USERA/ZM_DB_USER/’ | \
sed -e ’s/ZM_DB_PASSA/ZM_DB_PASS/’ >$ZM_CONFIG && \
rm -f $ZM_CONFIG.old
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
fi
if [ "$ZM_DB_SERVER" != "" -a "$ZM_DB_NAME" != "" -a "$ZM_DB_USER" != "" -a "$ZM_DB_PASS" != "" ]; then
echo -n “Converting $ZM_CONFIG to 1.22.0″
cp $ZM_CONFIG $ZM_CONFIG.old
rm -f $ZM_CONFIG
cat $ZM_CONFIG.old | \
sed -e ’s/ZM_DB_SERVER/ZM_DB_HOST/’ >/tmp/$$
. /tmp/$$
cp $ZM_CONFIG.rpmnew $ZM_CONFIG && chmod 644 $ZM_CONFIG
for n in ZM_DB_HOST ZM_DB_NAME ZM_DB_USER ZM_DB_PASS; do
eval “val=\$$n”
if [ "$val" != "" ]; then
cp $ZM_CONFIG /tmp/$$.rpmnew &&
sed ’s/^’$n=’.*$/’$n=$val’/g’ /tmp/$$.rpmnew >$ZM_CONFIG
fi
done
rm /tmp/$$
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
else
echo “In $ZM_CONFIG there should not be null values.”
return 1
fi
loadconf
fi
}

checkdb()
{
# Check database exisits and version
GetVer=”select Value from Config where Name=’ZM_DYN_DB_VERSION’”
OLD_VERSION=`echo $GetVer | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v ‘^Value’`
if [ "$OLD_VERSION" = "" ]; then
GetVer=”select Value from Config where Name=’ZM_DYN_CURR_VERSION’”
OLD_VERSION=`echo $GetVer | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v ‘^Value’`
if [ "$OLD_VERSION" = "" ]; then
echo -n “You must run zmupdate.pl manualy”
return 1
fi
fi
RETVAL=$?

if [ $RETVAL != 0 ]; then
tbls=`mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS -s -e ’show tables’ $ZM_DB_NAME`
RETVAL=$?
if [ $RETVAL = 0 ]; then
echo -n “Initialize $prog database: ”
echo tbls | grep Config >/dev/null 2>&1
RETVAL=$?
if [ $RETVAL != 0 ]; then
mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME < $ZM_PATH_UPDATE/zm_create.sql
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
return $RETVAL
fi
( cd $ZM_PATH_UPDATE; perl $ZM_PATH_BIN/zmupdate.pl -f )
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
return $RETVAL
else
echo "No access to ZoneMinder database. Run $ZM_PATH_BIN/zminit manually."
return $RETVAL
fi
else
[ "$ZM_VERSION" = "$OLD_VERSION" ] && return 0
echo -n "Upgrade $prog database: "
$ZM_PATH_BIN/zmupdate.pl --version=$OLD_VERSION --noi && ( cd $ZM_PATH_UPDATE; perl $ZM_PATH_BIN/zmupdate.pl -f )
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
return $RETVAL
fi
}

start()
{
loadconf || return $?
checkcfg || return $?
checkdb || return $?
#/usr/local/sbin/motd.sh > /etc/motd
echo -n “Starting $prog: ”
[ ! -d /var/run/zm ] \
&& mkdir -m 774 /var/run/zm \
&& chown $ZM_WEB_USER:$ZM_WEB_GROUP /var/run/zm
GetPath=”select Value from Config where Name=’ZM_PATH_SOCKS’”
ZM_PATH_SOCK=`echo $GetPath | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v ‘^Value’`
[ ! -d $ZM_PATH_SOCK ] \
&& mkdir -m 774 $ZM_PATH_SOCK \
&&chown $ZM_WEB_USER:$ZM_WEB_GROUP $ZM_PATH_SOCK
$command start
RETVAL=$?
[ $RETVAL = 0 ] && echo success
[ $RETVAL != 0 ] && echo failure
echo
[ $RETVAL = 0 ] && touch /var/lock/zm
return $RETVAL
}

stop()
{
echo -n $”Stopping $prog: ”
$command stop
RETVAL=$?
[ $RETVAL = 0 ] && echo success
[ $RETVAL != 0 ] && echo failure
echo
[ $RETVAL = 0 ] && rm -f /var/lock/zm
}

status()
{
result=`$command status`
if [ "$result" = "running" ]; then
echo “ZoneMinder is running”
RETVAL=0
else
echo “ZoneMinder is stopped”
RETVAL=1
fi
}

case “$1″ in
’start’)
start
;;
’stop’)
stop
;;
‘restart’)
stop
start
;;
‘condrestart’)
loadconf
checkcfg
result=`$ZM_PATH_BIN/zmdc.pl check`
if [ "$result" = "running" ]; then
$ZM_PATH_BIN/zmdc.pl shutdown > /dev/null
start
fi
;;
’status’)
status
;;
*)
echo “Usage: $0 { start | stop | restart | condrestart | status }”
RETVAL=1
;;
esac
exit $RETVAL

Make the ZoneMinder startup executable, make it run at all default levels, and then start it up:

sudo chmod +x /etc/init.d/zm
sudo update-rc.d zm defaults
sudo /etc/init.d/zm restart

Install Cambozola:

sudo apt-get install ant
cd /usr/local/src
sudo wget http://www.charliemouse.com/code/cambozola/cambozola-latest.tar.gz
sudo tar xvfz cambozola-latest.tar.gz
sudo cp /usr/local/src/cambozola-0.68/dist/cambozola.jar /var/www/zm
sudo chmod 775 /var/www/zm/cambozola.jar

[You will need to check the box indicating Cambozola has been install in the ZoneMinder options page]

Now start your browser and point it to:

localhost/zm

You should be good to go.

7 Responses to “ZoneMinder Ubuntu”

  1. Pieteron 25 Apr 2007 at 20:05:36

    Good lord.
    This post cured me of ever wanting to work on linux.

  2. Mugwugon 25 Apr 2007 at 21:04:40

    Actually Piet it has been an education. I commented to Dad in one of my many updates that Linux has entirely failed to anger me the way Windows problems do. Oh, no mistake I’ve been puzzled and befuddled by differences between the two OSs (lord knows I’ve been mucking with windows since it became windows), but Linux has (so far) failed to shitcan with no good explanation.

    I’ve been impressed so far, and I feel like I’m learning my way around it (Ubuntu anyway). It’s not something I want to repeat regularly, but lord knows the reason I went with Linux and ZoneMinder was because the windows apps had shown themselves to be universally unstable or inadequate to the task at hand.

    Zoneminder has already shown itself to be better thought out, more flexibile and just generally more intuitive than the other three specific applications I had tried to get to work without success.

    Of course, if you ever find yourself wanting to run ZoneMinder you can cheat. They offer, in the downloads section a CD image that includes both a linux distribution and an install package for Zoneminder. Pop the CD into the selected computer and it will take care of the rest.

    Cool, eh?

  3. Mattion 26 Apr 2007 at 08:57:10

    ‘Real men’ use Linux ;-)

    Actually, Piet … if you skip all that PERL code, there’s not a whole lot there. This is all very similar to setting up an HTTP (web) server.

    I wouldn’t be surprised, seeing what a hash Microsoft has made of Vista, if a lot more people didn’t start drifting over to Linux.

  4. Mugwugon 26 Apr 2007 at 09:09:50

    Hehe, funny that. I mentioned Linux when Lisa, Jilly and I went over to Moms for dinner with Doug (Unka Dougie) and Mona. Doug was suprisingly vocal about the shortcomings of Linux, focusing on the “What apps are you going to use?” I pointed out Ubuntu comes loaded with an open source word processor capable of using RTF (not sure if there’s a capability to read “word” documents, but RTF is sufficient for cross platform documents, no?).

    Sadly there were three noisy distractions running around that prevented any meaningful discussion on the relative merits of Linux vs. Windows, and this WAS a conversation I wanted to have.

    I guess it speaks volumes that despite my recent good experience with Linux my desktop remains a Windows XP machine. The only reason I can think of for keeping it so are the occasional (and I mean now and again) video games I play on it, but honestly I s’pose I could just use the laptop for that sort of thing.

    I guess we’ll have to wait and see what happens when it comes time to (inevitably) format the hard drive and reinstall windows, it’s been over two years since I installed a fresh copy of XP on this machine and it’s already starting to cludge more than a bit. I’d estimate we got another six months tops before I get frustrated and it’s time for a reinstallation.

    As for the ease of use, Dads right. Excluding the script in the middle the bulk are just command line instructions little different from DOS. There are oodles of tutorials and dozens of forums dedicated to Linux, and help is readily available. This alone is steps beyond diagnosing and repairing Windows problems.

    Ah well… time will tell. This I can tell you however, I am NOT plunking down another $100+ for yet ANOTHER Microsoft operating system. Considering the money I’ve spent, and the headaches I’ve had I’m not willingly giving them another dime.

  5. freddyboomboomon 28 Apr 2007 at 04:18:26

    The Open Office that comes in Ubuntu (or can be installed in many other flavors of Linux, Mac OS X, Solaris, and even Windows) will open and create documents for MS Word, Excel, Powerpoint…

    If/when you reformat that XP box, I’d suggest SuSE or Fedora for Linux flavors. Both are excellent and easy to install and run.

    Ubuntu does make for an excellent desktop OS, though…

  6. Mattion 28 Apr 2007 at 09:04:39

    Freddy is exactly right. OpenOffice can handle most Microsoft Office file formats (i.e. read AND write) except for some of the more complex scripting stuff (which one would have to be a nutcase to use in any event) … http://download.openoffice.org/2.2.0/

    Unka Dougie does have a point, especially when you get into multimedia.

    However, the *nix community has produced a slew of the most commonly required apps that are often much better than the commercial Windows products. Sometimes there’s even a port to Windows ;-)

    Windows is great for unsophisticated users … until something ‘goes wrong’ (imagine that!) and then it’s hopeless. Call in the Geek Squad :-(

    Linus users tend to be more knowledgeable and willing to get their hands dirty … LOL!!

  7. Mugwugon 28 Apr 2007 at 17:54:44

    Oh yes, I’ve read a bit about Linuxs relative shortcomings with respect to multimedia stuff (Theodore? Anything to add here?) but generally speaking I’d be fairly confident that I could muddle through with Linux (except for the video games).

    I’m impressed with the Linux community so far, help while setting up ZoneMinder / Ubuntu was rarely more than a quick google search away, I hardly even needed to ask a question on the assorted forums as there was already answers a-plenty there.

    Meh…

Trackback URI | Comments RSS

Leave a Reply