Page 1 of 1

Problem changing run state from command line

Posted: Mon Sep 26, 2005 2:42 pm
by JohnXVII
Hello all,

I'm having some problems changing run state using the zmpkg.pl script from the command line. I am running ZoneMinder 1.21.3, installed from source (not ebuild), on a Gentoo Linux system. Changing run states from the web interface works fine, just not from the command line.

My cameras are set up with 2 run states: Day and Night. During the day, they are all set to monitor mode, and at night they are all set to modect. I use cron to change modes:

Code: Select all

0 20 * * * /usr/local/bin/zmpkg.pl Night
0 7 * * *  /usr/local/bin/zmpkg.pl Day
Assuming the cameras are not in the "Day" state, here's a few lines from zmpkg.log when I change run state to "Day" via the web interface:

Code: Select all

Command: state
Updating DB: Day
Executing: /usr/local/bin/zmdc.pl check
Executing: /usr/local/bin/zmdc.pl shutdown
Removing shared memory
Executing: /usr/local/bin/zmdc.pl check
Removing shared memory
Executing: /usr/local/bin/zmfix
Executing: /usr/local/bin/zmdc.pl status
Executing: /usr/local/bin/zmdc.pl start zmc -d 0
Executing: /usr/local/bin/zmdc.pl start zmc -d 1
Executing: /usr/local/bin/zmdc.pl start zmc -d 2
Executing: /usr/local/bin/zmdc.pl start zmc -d 3
Executing: /usr/local/bin/zmdc.pl start zmfilter.pl
Executing: /usr/local/bin/zmdc.pl start zmaudit.pl -d 900 -y
Executing: /usr/local/bin/zmdc.pl start zmwatch.pl
Executing: /usr/local/bin/zmdc.pl start zmupdate.pl -c
But this is what happens when I try to change to the "Day" state from the command line (yes, my httpd user is apache):

Code: Select all

Command: state
Updating DB: Day
Executing: su apache --shell=/bin/sh --command='/usr/local/bin/zmdc.pl check'
Executing: su apache --shell=/bin/sh --command='/usr/local/bin/zmdc.pl check'
After using the command line, the cameras' Function column in the web interface changes appropriately, but the cameras are still in the other mode (in this case modect). This is reflected in the fact that the Source column entries are still green, when if they were really in monitor mode they should change to yellow. The same behavior is observed in changing from Day to Night, the Function column turns to a green 'Modect', but the Source column remains yellow, and the cameras do not record events. Again, if I change the run state manually from the web interface everything works perfectly.

I haven't been able to make heads or tails of this problem, and have searched through the forums for a similar problem. I would appreciate any help (or a pointer to the relevent thread if this has been solved before).

-- John

Posted: Mon Sep 26, 2005 9:35 pm
by zoneminder
The zmpkg script will try and su any commands that it must run when it's not running as the web user. I think this is possibly your problem. I know SlackWare for instance uses a different su syntax so you might want to try and edit zmpkg.pl (or the .z version in your build area) and change the line

Code: Select all

$command = “su “.ZM_WEB_USER.” --shell=/bin/sh --command=’$command’”;
to

Code: Select all

$command = “su “.ZM_WEB_USER.” –c ’$command’”;
and see if that works. I'd put a conditional in there to do it automatically if I could figure out how to tell which version was legit on a particular system.

Phil

Posted: Tue Sep 27, 2005 1:59 pm
by JohnXVII
Thanks for the help Phil, su syntax was the issue. Instead of modifying the scripts, I just modified my cron job since it was root's:

Code: Select all

0 20 * * * /usr/bin/sudo -u apache /usr/local/bin/zmpkg.pl Night
0 7 * * *  /usr/bin/sudo -u apache /usr/local/bin/zmpkg.pl Day
-- John