Since a recent burglary I have been using ZoneMinder to provide CCTV security for my house on my Ubuntu 12.04 machine. I noticed earlier today that zoneminder had stopped running over the weekend and when I tried to start the service again, I got the following error:
Starting ZoneMinder: Bareword "ZM_PATH_LOGS" not allowed while "strict subs" in use at /usr/share/perl5/ZoneMinder/Logger.pm line 153. BEGIN not safe after errors--compilation aborted at /usr/share/perl5/ZoneMinder/Logger.pm line 168. Compilation failed in require at /usr/share/perl5/ZoneMinder.pm line 34. BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder.pm line 34. Compilation failed in require at /usr/bin/zmpkg.pl line 37. BEGIN failed--compilation aborted at /usr/bin/zmpkg.pl line 37. failure
Looking through the ZoneMinder code I discovered that the error indicated that a configuration variable somehow wasn't set. My first thought was that perhaps a new configuration variable had been added in an upgrade but hadn't been automatically added to the configuration file. So I added a line containing ZM_PATH_LOGS to /etc/zm/zm.conf but now when I tried to start zoneminder, I received a similar (but different error):
Starting ZoneMinder: Bareword "ZM_USE_DEEP_STORAGE" not allowed while "strict subs" in use at /usr/share/perl5/ZoneMinder/General.pm line 207. BEGIN not safe after errors--compilation aborted at /usr/share/perl5/ZoneMinder/General.pm line 226. Compilation failed in require at /usr/share/perl5/ZoneMinder.pm line 35. BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder.pm line 35. Compilation failed in require at /usr/bin/zmpkg.pl line 37. BEGIN failed--compilation aborted at /usr/bin/zmpkg.pl line 37. failure
I added a line for this then another similar (but different) error appeared! Clearly this approach isn't correct. So I logged into mysql and had a poke around:
mysql -u XXX -p mysql> show databases; mysql> use zm; mysql> show tables; +----------------+ | Tables_in_zm | +----------------+ | Config | | ControlPresets | | Controls | | Devices | | Events | | Filters | | Frames | | Groups | | Logs | | MonitorPresets | | Monitors | | States | | Stats | | TriggersX10 | | Users | | ZonePresets | | Zones | +----------------+ 17 rows in set (0.00 sec) mysql> select * from Config; 0 rows in set (0.00 sec)
Like in iPhone adverts, the above sequence is shortened. But the surprising result appears at the end: there are no lines in the Config table! This must be the culprit preventing ZoneMinder from starting.
Its not clear how this config table has been reset, as I don't recall updating the ZoneMinder packages recently, so I don't think its a botched database upgrade. I have restarted the machine that it runs on a couple of times over the weekend so perhaps the database got corrupted at shutdown, though I can't find any mysql logs complaining about this. In conclusion, I don't know how it happened! But if it happens again all the info is here.
To resolve this, I download the ubuntu package for zoneminder and had a look in the postinst install script to see how it initialised the database. It turns out there is an sql file at /usr/share/zoneminder/db/zm_create.sql which is applied at package installation. I edited this file and removed all lines that didn't affect the Config table and applied it manually.
Finally zoneminder started up (albeit without my configurations)! After reconfiguring zoneminder, I noticed in ZoneMinder's log database the following entry:
Config mismatch, expected 218 items, read 0. Try running 'zmupdate.pl -f' to reload config.
If this happens again, perhaps 'zmupdate.pl -f' is sufficient to fix it, instead of error-prone sql hacking. (update: according to commenters this does not work!)
And the moral of the story is: always backup your databases!
28 replies on “ZoneMinder: Bareword "ZM_PATH_LOGS" not allowed while "strict subs" in use”
Thank you. This helped fixed my zoneminder setup. And the "zmupdate.pl -f" fails too 🙂 (same error "Bareword "ZM_PATH_LOGS" not allowed while "strict subs") ...
Thanks for this info - my ZM crashed over the weekend with the exact same cause - a completely truncated Config table. Someone over at ZM should probably look into this. And I'll be running mysqldump nightly.
zmupdate.pl -f did not run, as it produced the same error. I had to extract the INSERT statements from zm_create.sql and run them.
Thanks again.
I had a similar issue, and it took me a while to realize what was causing it. It seems that the original zm_create.sql doesn't have a "DROP IF EXISTS" line before table 'Logs'. Adding it allowed me to dump zm_create.sql to the database and everything seems to be working now.
Thanks for this info. I found the same error in my logs after trying to get ZM up & running for the 1st time and you saved me a lot of time & frustration trying to figure it out.
Can anyone provide a little more detail on how to fix this? I have the same problem and am not a SQL expert. Do I only have to run the lines in the "Logs" section?
Thanks.
Make a copy of that sql file and delete everything except the following sections:
You now have an sql file that modifies the zoneminder (zm) database by deleting the config table and recreating it, then it initialises the configuration options to default values. This means you will lose all your settings if you apply this sql file to the database. However as you are seeing this error you have probably already lost all your settings.
To apply the script to the database you can use a command something like the following:
Before you do this, I would recommend that you first verify that your Config table is empty:
You should see "0 rows in set" if the Config table is empty (before you apply the sql script), or something like "218 rows in set" if it is full (after you apply the sql script).
Thanks very much. It fixed my problem and zoneminder is now working again! I will implement a daily cron job to backup the database in case this happens again.
Hi Mr.Wayne i am srinivas please help me regarding above issue. When i am start zonemineder i am getting above error. For recovering that error the tutorial says that edit "/usr/share/zoneminder/db/zm_create.sql" this file. I am getting confusion how to edit that file. please help me regarding this(which lines i have to delete).please help me??????
Thank you for this. Like others, this happened on a server shutdown. I was fortunate enough that I had Config.MYD and .MYI backed off to tape recently, so restoring them allowed me to bring up Zoneminder again.
Thank you so much, it worked for me, i just imported the "insert into config ..." from the sql file.
Hi.
To fix this problem, just access your database, delete every table in it and run the zm_create.sql again.
It solved my problem here.
The disadvantage of deleting all the zoneminder tables is that you'd lose your previous events.
imalinuxnoob but this is how it happened
#VACUUM_CLEANER_BUMP
#TEENPARTY START -U alloffacebook -freeBOOZE
#TEENPARTY STOP -U alloffacebook -freeBOOZE
#TEENDOUBLETAP -on
#VACUUM_CLEANER_BUMP
Thanks a lot frankster! That solved my problems here! =)
Thank you! It took me just 15 minute to fix this issue 🙂
thank you a lot, it works
This worked for me! Might be good to add that how-to in the actual article. Thanks smart people!
Thank you very much, it worked for me too and without any problem!
Thank you very much ...........! Help me a log and saved my tons of time...!!
I am also getting same error, for remove that error you told that edit this file /usr/share/zoneminder/db/zm_create.sql. I am not understand how to edit that file which does not effect config file. please help me.
Many many thanks Frankster, particularly for taking the trouble to provide the detailed instructions.... You've saved me burning the midnight oil....
Cheers,
Jon
I had this problem when I upgraded Ubuntu from 13.04 to 13.10. I followed the instructions here to rebuild the Config table (THANKS for that), and after a reboot
$ sudo service apache2 status
$ sudo service mysql status
$ sudo service zoneminder status
shows that all of these are running. But when I try to access zoneminder locally or remotely by browsing to http:///zm, I get a 404 error.
syslog indicates zoneminder is running and capturing motion detected images, which surprised me because I thought I would have to reconfigure everything. But I can't seem to access zm to see the images or configuration.
Any clues?
I haven't seen this exact problem myself, but I expect the problem lies within the configuration files in your /etc/apache2 directory.
I've been pulling out hair all day. Both /etc/zm/apache.conf and /etc/apache2/conf.d/zoneminder.conf look like:
Alias /zm /usr/share/zoneminder
ScriptAlias /cgi-bin /usr/share/zoneminder/cgi-bin
php_flag register_globals off
Options Indexes FollowSymLinks
DirectoryIndex index.php
/usr/share/zoneminder/index.php looks appropriate.
Yet browsing to localhost/zm/ or localhost/zm/index.php returns "URL /zm/ was not found on this server".
I'm shooting blanks at this point, as I don't understand what directs apache to the zoneminder page.
some of the text zoneminder.conf got stripped out:
"Directory /usr/share/zoneminder" (in brackets) was before php_flag.
"IfModule mod_dir.c" was before DirectoryIndex,
"/IfModule" followed DirectoryIndex.
"/Directory" followed "/IfModule"
From Argentina, I say thank you, thank you very much. I'm installing zoneminder on a raspberry pi 2 and if you don't post the solution I would throw it for my window. Thanks again.
Had the same problem as well, zmupdate.pl -f did not help at first, it since it first loads data from the database, and then wants to have at least some kind of basic config values (same error "Bareword "ZM_PATH_LOGS" not allowed")
My Solution looked a bit like yours but I found several problems/possible bugs in the /usr/share/zoneminder/db/zm_create.sql file:
1) for EVERY table exept the Config table, there is a "DROP TABLE IF EXISTS '[Tablename]';" command - so I had to add this one to be sure - maybe this is to make sure no configuration data gets overwritten... but in this case there is no data in there anyway
2) when this part of the sql file worked, the part after "-- Add in some sample control protocol definitions" did throw errors regarding duplicate keys. Remove it (of make these lines comments by "-- " !never forget the whitespace!)
3) when I manually tried "DROP TABLE IF EXISTS 'Config';" I got a syntax error. "DROP TABLE IF EXISTS Config;" worked (I'm not that firm with sql, but why should it work in the sql-file?
Anyway, after applying the modified file containing only lines for the Config-Table, zmupdate.pl -f did work, the client did start
in my case, in installation manual for ubuntu 14.04 it is asked to import database dump with mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql
this failed and halted due to error with creation of 'Logs' table
edited the sql file to add DROP TABLE IF EXISTS `Logs`;
before CREATE TABLE `Logs` (
then imported the dump successfully
and then zm service started correctly without errors
thks