2019-09-24 00:54:27 +08:00
|
|
|
#!@PERL_EXECUTABLE@ -wT
|
2005-12-16 18:05:29 +08:00
|
|
|
#
|
|
|
|
# ==========================================================================
|
|
|
|
#
|
|
|
|
# ZoneMinder Package Control Script, $Date$, $Revision$
|
2008-07-25 17:48:16 +08:00
|
|
|
# Copyright (C) 2001-2008 Philip Coombes
|
2005-12-16 18:05:29 +08:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2016-12-26 23:23:16 +08:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-12-16 18:05:29 +08:00
|
|
|
#
|
|
|
|
# ==========================================================================
|
2015-04-11 20:39:32 +08:00
|
|
|
|
2005-12-16 18:05:29 +08:00
|
|
|
use strict;
|
|
|
|
use bytes;
|
|
|
|
|
|
|
|
# ==========================================================================
|
|
|
|
#
|
|
|
|
# Don't change anything below here
|
|
|
|
#
|
|
|
|
# ==========================================================================
|
|
|
|
|
2009-06-08 17:11:56 +08:00
|
|
|
@EXTRA_PERL_LIB@
|
2005-12-16 18:05:29 +08:00
|
|
|
use ZoneMinder;
|
2022-01-28 02:42:31 +08:00
|
|
|
use ZoneMinder::Monitor;
|
|
|
|
use ZoneMinder::State;
|
2022-02-02 06:23:16 +08:00
|
|
|
use ZoneMinder::Filter;
|
2005-12-16 18:05:29 +08:00
|
|
|
use DBI;
|
|
|
|
use POSIX;
|
|
|
|
use Time::HiRes qw/gettimeofday/;
|
2015-04-11 20:39:32 +08:00
|
|
|
use autouse 'Pod::Usage'=>qw(pod2usage);
|
2005-12-16 18:05:29 +08:00
|
|
|
|
|
|
|
# Detaint our environment
|
2016-03-12 05:28:16 +08:00
|
|
|
$ENV{PATH} = '/bin:/usr/bin:/usr/local/bin';
|
2005-12-16 18:05:29 +08:00
|
|
|
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
|
|
|
|
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
|
2018-06-07 02:05:58 +08:00
|
|
|
my $store_state=''; # PP - will remember state name passed
|
2005-12-16 18:05:29 +08:00
|
|
|
|
2011-06-21 17:19:10 +08:00
|
|
|
logInit();
|
2005-12-21 01:03:33 +08:00
|
|
|
|
2015-04-11 20:41:07 +08:00
|
|
|
my $command = $ARGV[0]||'';
|
2015-01-07 22:05:16 +08:00
|
|
|
if ( $command eq 'version' ) {
|
2017-09-12 10:12:10 +08:00
|
|
|
print ZoneMinder::Base::ZM_VERSION . "\n";
|
|
|
|
exit(0);
|
2015-01-07 22:05:16 +08:00
|
|
|
}
|
2005-12-16 18:05:29 +08:00
|
|
|
|
|
|
|
my $state;
|
|
|
|
|
2018-06-07 02:05:58 +08:00
|
|
|
my $dbh = zmDbConnect();
|
2018-12-28 01:22:06 +08:00
|
|
|
Debug("Command: $command");
|
|
|
|
if ( $command and ( $command !~ /^(?:start|stop|restart|status|logrot|version)$/ ) ) {
|
|
|
|
# Check to see if it's a valid run state
|
2022-03-09 00:10:29 +08:00
|
|
|
if ($state = ZoneMinder::State->find_one(Name=>$command)) {
|
2018-12-28 01:22:06 +08:00
|
|
|
$state->{Definitions} = [];
|
2022-01-28 02:42:31 +08:00
|
|
|
foreach (split(',', $state->{Definition})) {
|
|
|
|
my @state = split(':', $_);
|
|
|
|
my ($id, $capturing, $analysing, $recording);
|
|
|
|
if (@state == 3) {
|
|
|
|
($id, my $function, my $enabled) = @state;
|
|
|
|
if (!$enabled) {
|
|
|
|
($capturing, $analysing, $recording) = ('None','None','None');
|
|
|
|
} elsif ($function eq 'None') {
|
|
|
|
($capturing, $analysing, $recording) = ('None','None','None');
|
|
|
|
} elsif ($function eq 'Monitor') {
|
|
|
|
($capturing, $analysing, $recording) = ('Always','None','None');
|
|
|
|
} elsif ($function eq 'Modect') {
|
|
|
|
($capturing, $analysing, $recording) = ('Always','Always','OnMotion');
|
|
|
|
} elsif ($function eq 'Mocord') {
|
|
|
|
($capturing, $analysing, $recording) = ('Always','Always','OnMotion');
|
|
|
|
} elsif ($function eq 'Record') {
|
|
|
|
($capturing, $analysing, $recording) = ('Always','Always','Always');
|
|
|
|
} else {
|
|
|
|
Error("Unknown function $function, defaulting to Mocord");
|
|
|
|
}
|
|
|
|
} elsif (@state == 4) {
|
|
|
|
($id, $capturing, $analysing, $capturing) = @state;
|
|
|
|
} else {
|
|
|
|
Error("Unknown state in @state");
|
|
|
|
}
|
|
|
|
push @{$state->{Definitions}}, {Id=>$id, Capturing=>$capturing, Analysing=>$analysing, Recording=>$recording};
|
|
|
|
} # end foreach state definition
|
2018-12-28 01:22:06 +08:00
|
|
|
$store_state = $command; # PP - Remember the name that was passed to search in DB
|
|
|
|
$command = 'state';
|
|
|
|
} else {
|
|
|
|
$command = undef;
|
2017-09-12 10:12:10 +08:00
|
|
|
}
|
2018-06-07 02:05:58 +08:00
|
|
|
} # end if not one of the usual commands
|
|
|
|
|
2018-12-28 01:22:06 +08:00
|
|
|
if ( !$command ) {
|
|
|
|
pod2usage(-exitstatus => -1);
|
|
|
|
}
|
|
|
|
|
2015-08-27 00:08:10 +08:00
|
|
|
# PP - Sane state check
|
2015-08-26 23:20:58 +08:00
|
|
|
isActiveSanityCheck();
|
2005-12-16 18:05:29 +08:00
|
|
|
|
|
|
|
# Move to the right place
|
2022-01-28 02:42:31 +08:00
|
|
|
chdir($Config{ZM_PATH_WEB}) or Fatal("Can't chdir to $Config{ZM_PATH_WEB}: $!");
|
2018-06-07 02:05:58 +08:00
|
|
|
|
|
|
|
my $dbg_id = '';
|
|
|
|
|
|
|
|
Info("Command: $command");
|
|
|
|
|
|
|
|
my $retval = 0;
|
|
|
|
|
|
|
|
if ( $command eq 'state' ) {
|
|
|
|
Info("Updating DB: $state->{Name}");
|
2022-01-28 02:42:31 +08:00
|
|
|
foreach my $monitor (ZoneMinder::Monitor->find(
|
|
|
|
($Config{ZM_SERVER_ID} ? (ServerId=>$Config{ZM_SERVER_ID}) : () ), order=>'Id ASC')
|
|
|
|
) {
|
2018-06-07 02:05:58 +08:00
|
|
|
foreach my $definition ( @{$state->{Definitions}} ) {
|
2022-01-28 02:42:31 +08:00
|
|
|
# FIXME WHY a REGEXP
|
2018-06-07 02:05:58 +08:00
|
|
|
if ( $monitor->{Id} =~ /^$definition->{Id}$/ ) {
|
|
|
|
$monitor->{NewFunction} = $definition->{Function};
|
|
|
|
$monitor->{NewEnabled} = $definition->{Enabled};
|
2021-05-12 03:27:36 +08:00
|
|
|
last;
|
2017-09-12 10:12:10 +08:00
|
|
|
}
|
2022-01-28 02:42:31 +08:00
|
|
|
if (
|
|
|
|
($monitor->{Capturing} ne $definition->{Capturing})
|
|
|
|
or
|
|
|
|
($monitor->{Analysing} ne $definition->{Analysing})
|
|
|
|
or
|
|
|
|
($monitor->{Recording} ne $definition->{Recording})
|
|
|
|
) {
|
2022-02-02 06:23:16 +08:00
|
|
|
$monitor->save({ map { $_ => $$definition{$_} } qw(Capturing Analysing Recording) });
|
2022-01-28 02:42:31 +08:00
|
|
|
last; # definition
|
|
|
|
} # end if
|
|
|
|
} # end foreach definition
|
2018-06-07 02:05:58 +08:00
|
|
|
} # end foreach monitor
|
|
|
|
|
|
|
|
# PP - Now mark a specific state as active
|
|
|
|
resetStates();
|
|
|
|
Info("Marking $store_state as Enabled");
|
2022-01-28 02:42:31 +08:00
|
|
|
$state->save({IsActive=>1});
|
2018-06-07 02:05:58 +08:00
|
|
|
|
|
|
|
# PP - zero out other states isActive
|
|
|
|
$command = 'restart';
|
|
|
|
} # end if command = state
|
2005-12-16 18:05:29 +08:00
|
|
|
|
2014-08-10 21:47:11 +08:00
|
|
|
# Check if we are running systemd and if we have been called by the system
|
2017-09-12 10:12:10 +08:00
|
|
|
if ( $command =~ /^(start|stop|restart)$/ ) {
|
|
|
|
# We have to detaint to keep perl from complaining
|
|
|
|
$command = $1;
|
|
|
|
|
|
|
|
if ( systemdRunning() && !calledBysystem() ) {
|
|
|
|
qx(@BINDIR@/zmsystemctl.pl $command);
|
|
|
|
$command = '';
|
|
|
|
}
|
2014-08-10 21:47:11 +08:00
|
|
|
}
|
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
if ( $command =~ /^(?:stop|restart)$/ ) {
|
|
|
|
my $status = runCommand('zmdc.pl check');
|
2018-06-07 02:05:58 +08:00
|
|
|
Debug("zmdc.pl check = $status");
|
2015-04-11 20:39:32 +08:00
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
if ( $status eq 'running' ) {
|
|
|
|
runCommand('zmdc.pl shutdown');
|
|
|
|
zmMemTidy();
|
|
|
|
} else {
|
|
|
|
$retval = 1;
|
|
|
|
}
|
2005-12-16 18:05:29 +08:00
|
|
|
}
|
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
if ( $command =~ /^(?:start|restart)$/ ) {
|
|
|
|
my $status = runCommand('zmdc.pl check');
|
2018-06-07 02:05:58 +08:00
|
|
|
Debug("zmdc.pl check = $status");
|
2017-09-12 10:12:10 +08:00
|
|
|
|
|
|
|
if ( $status eq 'stopped' ) {
|
|
|
|
if ( $Config{ZM_DYN_DB_VERSION}
|
|
|
|
and ( $Config{ZM_DYN_DB_VERSION} ne ZM_VERSION )
|
|
|
|
) {
|
2021-04-29 01:25:01 +08:00
|
|
|
my ( $db_major, $db_minor, $db_micro ) = split(/\./, $Config{ZM_DYN_DB_VERSION});
|
|
|
|
my ( $major, $minor, $micro ) = split(/\./, ZM_VERSION);
|
2021-02-03 22:50:37 +08:00
|
|
|
if ( $db_major != $major or $db_minor != $minor ) {
|
|
|
|
Fatal('Version mismatch, system is version '.ZM_VERSION
|
|
|
|
.', database is '.$Config{ZM_DYN_DB_VERSION}
|
|
|
|
.', please run zmupdate.pl to update.'
|
|
|
|
);
|
|
|
|
exit(-1);
|
|
|
|
} else {
|
|
|
|
Error('Version mismatch, system is version '.ZM_VERSION
|
|
|
|
.', database is '.$Config{ZM_DYN_DB_VERSION}
|
|
|
|
.', please run zmupdate.pl to update.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} # end if version mismatch
|
2011-05-25 17:15:14 +08:00
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
# Recreate the temporary directory if it's been wiped
|
|
|
|
verifyFolder('@ZM_TMPDIR@');
|
2014-10-06 00:25:41 +08:00
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
# Recreate the run directory if it's been wiped
|
|
|
|
verifyFolder('@ZM_RUNDIR@');
|
2014-10-06 00:25:41 +08:00
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
# Recreate the sock directory if it's been wiped
|
|
|
|
verifyFolder('@ZM_SOCKDIR@');
|
2015-04-11 20:39:32 +08:00
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
zmMemTidy();
|
|
|
|
runCommand('zmdc.pl startup');
|
2015-04-11 20:39:32 +08:00
|
|
|
|
2018-01-16 22:31:58 +08:00
|
|
|
my $Server = undef;
|
2022-01-28 02:42:31 +08:00
|
|
|
my @monitors;
|
2017-09-12 10:12:10 +08:00
|
|
|
if ( $Config{ZM_SERVER_ID} ) {
|
2018-01-16 22:31:58 +08:00
|
|
|
require ZoneMinder::Server;
|
2018-06-07 02:05:58 +08:00
|
|
|
Info("Multi-server configuration detected. Starting up services for server $Config{ZM_SERVER_ID}");
|
|
|
|
$Server = new ZoneMinder::Server($Config{ZM_SERVER_ID});
|
2022-01-28 02:42:31 +08:00
|
|
|
@monitors = ZoneMinder::Monitor->find(ServerId=>$Config{ZM_SERVER_ID});
|
2017-09-12 10:12:10 +08:00
|
|
|
} else {
|
|
|
|
Info('Single server configuration detected. Starting up services.');
|
2022-01-28 02:42:31 +08:00
|
|
|
@monitors = ZoneMinder::Monitor->find(ServerId=>$Config{ZM_SERVER_ID});
|
2018-04-04 05:41:32 +08:00
|
|
|
}
|
2018-06-07 02:05:58 +08:00
|
|
|
|
2022-01-28 02:42:31 +08:00
|
|
|
foreach my $monitor (@monitors) {
|
|
|
|
if ( $monitor->{Capturing} ne 'None' && $monitor->{Type} ne 'WebSite' ) {
|
|
|
|
if ( $monitor->{Type} eq 'Local' ) {
|
|
|
|
runCommand("zmdc.pl start zmc -d $monitor->{Device}");
|
|
|
|
} else {
|
|
|
|
runCommand("zmdc.pl start zmc -m $monitor->{Id}");
|
2018-06-07 02:05:58 +08:00
|
|
|
}
|
2022-01-28 02:42:31 +08:00
|
|
|
if ( $Config{ZM_OPT_CONTROL} ) {
|
|
|
|
if ( $monitor->{Controllable} ) {
|
|
|
|
runCommand("zmdc.pl start zmcontrol.pl --id $monitor->{Id}");
|
|
|
|
if ( $monitor->{TrackMotion} ) {
|
2022-02-04 01:37:51 +08:00
|
|
|
if ($monitor->{Analysing} ne 'None') {
|
2022-01-28 02:42:31 +08:00
|
|
|
runCommand("zmdc.pl start zmtrack.pl -m $monitor->{Id}");
|
|
|
|
} else {
|
|
|
|
Warning('Monitor is set to track motion, but does not have motion detection enabled.');
|
|
|
|
} # end if Has motion enabled
|
|
|
|
} # end if track motion
|
|
|
|
} # end if controllable
|
|
|
|
} # end if ZM_OPT_CONTROL
|
|
|
|
} # end if capturing is not none or Website
|
|
|
|
} # end foreach monitor
|
|
|
|
|
|
|
|
my @filters = ZoneMinder::Filter->find(Background=>1);
|
|
|
|
if (@filters) {
|
|
|
|
foreach my $filter (@filters) {
|
|
|
|
runCommand("zmdc.pl start zmfilter.pl --filter_id=$$filter{Id} --daemon");
|
2018-04-04 05:41:32 +08:00
|
|
|
}
|
2022-01-28 02:42:31 +08:00
|
|
|
} else {
|
|
|
|
runCommand('zmdc.pl start zmfilter.pl');
|
2018-04-04 05:41:32 +08:00
|
|
|
}
|
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
if ( $Config{ZM_RUN_AUDIT} ) {
|
2018-08-11 22:08:30 +08:00
|
|
|
if ( $Server and exists $$Server{zmaudit} and ! $$Server{zmaudit} ) {
|
|
|
|
Debug('Not running zmaudit.pl because it is turned off for this server.');
|
2018-01-16 22:31:58 +08:00
|
|
|
} else {
|
|
|
|
runCommand('zmdc.pl start zmaudit.pl -c');
|
|
|
|
}
|
2015-04-11 20:39:32 +08:00
|
|
|
}
|
2017-09-12 10:12:10 +08:00
|
|
|
if ( $Config{ZM_OPT_TRIGGERS} ) {
|
2018-08-11 22:08:30 +08:00
|
|
|
if ( $Server and exists $$Server{zmtrigger} and ! $$Server{zmtrigger} ) {
|
|
|
|
Debug('Not running zmtrigger.pl because it is turned off for this server.');
|
2018-01-16 22:31:58 +08:00
|
|
|
} else {
|
|
|
|
runCommand('zmdc.pl start zmtrigger.pl');
|
|
|
|
}
|
2015-04-11 20:39:32 +08:00
|
|
|
}
|
2017-09-12 10:12:10 +08:00
|
|
|
if ( $Config{ZM_OPT_X10} ) {
|
|
|
|
runCommand('zmdc.pl start zmx10.pl -c start');
|
2015-04-11 20:39:32 +08:00
|
|
|
}
|
2017-09-12 10:12:10 +08:00
|
|
|
runCommand('zmdc.pl start zmwatch.pl');
|
|
|
|
if ( $Config{ZM_CHECK_FOR_UPDATES} ) {
|
|
|
|
runCommand('zmdc.pl start zmupdate.pl -c');
|
2015-04-11 20:39:32 +08:00
|
|
|
}
|
2017-09-12 10:12:10 +08:00
|
|
|
if ( $Config{ZM_TELEMETRY_DATA} ) {
|
|
|
|
runCommand('zmdc.pl start zmtelemetry.pl');
|
|
|
|
}
|
2018-03-29 23:27:31 +08:00
|
|
|
if ($Config{ZM_OPT_USE_EVENTNOTIFICATION} ) {
|
2022-01-28 02:42:31 +08:00
|
|
|
if ( $Server and exists $$Server{zmeventnotification} and ! $$Server{zmeventnotification} ) {
|
|
|
|
Debug('Not running zmnotification.pl because it is turned off for this server.');
|
2019-02-27 22:28:15 +08:00
|
|
|
} else {
|
2018-03-29 20:47:55 +08:00
|
|
|
runCommand('zmdc.pl start zmeventnotification.pl');
|
2019-02-27 22:28:15 +08:00
|
|
|
}
|
2018-03-29 20:47:55 +08:00
|
|
|
}
|
2018-08-11 22:08:30 +08:00
|
|
|
if ( $Server and exists $$Server{zmstats} and ! $$Server{zmstats} ) {
|
|
|
|
Debug('Not running zmstats.pl because it is turned off for this server.');
|
2018-01-16 22:31:58 +08:00
|
|
|
} else {
|
|
|
|
runCommand('zmdc.pl start zmstats.pl');
|
|
|
|
}
|
2021-03-02 02:34:26 +08:00
|
|
|
if ( $Config{ZM_MIN_RTSP_PORT} ) {
|
|
|
|
runCommand('zmdc.pl start zm_rtsp_server');
|
|
|
|
}
|
2017-09-12 10:12:10 +08:00
|
|
|
} else {
|
|
|
|
$retval = 1;
|
|
|
|
}
|
2018-06-07 02:05:58 +08:00
|
|
|
} # end if command is start or restart
|
2005-12-16 18:05:29 +08:00
|
|
|
|
2022-01-28 02:42:31 +08:00
|
|
|
if ($command eq 'status') {
|
2017-09-12 10:12:10 +08:00
|
|
|
my $status = runCommand('zmdc.pl check');
|
2005-12-16 18:05:29 +08:00
|
|
|
|
2018-06-07 02:05:58 +08:00
|
|
|
print(STDOUT $status."\n");
|
2022-01-28 02:42:31 +08:00
|
|
|
} elsif ($command eq 'logrot') {
|
2017-09-12 10:12:10 +08:00
|
|
|
runCommand('zmdc.pl logrot');
|
2006-07-04 18:34:21 +08:00
|
|
|
}
|
|
|
|
|
2018-06-07 02:05:58 +08:00
|
|
|
exit($retval);
|
2013-12-17 05:32:02 +08:00
|
|
|
|
2015-08-26 23:20:58 +08:00
|
|
|
# PP - Make sure isActive is on and only one
|
2017-09-12 10:12:10 +08:00
|
|
|
sub isActiveSanityCheck {
|
2017-11-22 01:28:41 +08:00
|
|
|
Info('Sanity checking States table...');
|
2017-09-12 10:12:10 +08:00
|
|
|
$dbh = zmDbConnect() if ! $dbh;
|
|
|
|
|
|
|
|
# PP - First, make sure default exists and there is only one
|
2022-01-28 02:42:31 +08:00
|
|
|
my @states = ZoneMinder::State->find(Name=>'default', order=>'Id ASC');
|
2017-09-12 10:12:10 +08:00
|
|
|
# PP - no row, or too many rows. Either case is an error
|
|
|
|
|
2022-01-28 02:42:31 +08:00
|
|
|
my $default_state;
|
|
|
|
while (@states > 1) {
|
|
|
|
my $state = shift @states;
|
|
|
|
$state->delete();
|
|
|
|
}
|
|
|
|
if (!@states) {
|
|
|
|
$default_state = new ZoneMinder::State();
|
|
|
|
$default_state->save({Name=>'default', Definition=>'', IsActive=>1});
|
|
|
|
} else {
|
|
|
|
$default_state = shift @states;
|
|
|
|
}
|
2017-09-12 10:12:10 +08:00
|
|
|
|
2022-01-28 02:42:31 +08:00
|
|
|
@states = ZoneMinder::State->find(IsActive=>1);
|
|
|
|
if (@states != 1) {
|
2018-06-07 02:05:58 +08:00
|
|
|
Info('Fixing States table so only one run state is active');
|
2017-09-12 10:12:10 +08:00
|
|
|
resetStates();
|
2022-01-28 02:42:31 +08:00
|
|
|
$default_state->save({IsActive=>1});
|
2017-09-12 10:12:10 +08:00
|
|
|
}
|
2018-06-07 02:05:58 +08:00
|
|
|
} # end sub isActiveSanityCheck
|
2015-08-26 23:20:58 +08:00
|
|
|
|
|
|
|
# PP - zeroes out isActive for all states
|
2017-09-12 10:12:10 +08:00
|
|
|
sub resetStates {
|
|
|
|
$dbh = zmDbConnect() if ! $dbh;
|
2019-08-25 23:36:23 +08:00
|
|
|
$dbh->do('UPDATE `States` SET `IsActive`=0')
|
2018-12-28 01:22:06 +08:00
|
|
|
or Fatal("Can't execute: ".$dbh->errstr());
|
2015-06-21 21:30:46 +08:00
|
|
|
}
|
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
sub systemdRunning {
|
|
|
|
my $output = qx(ps -o comm="" -p 1);
|
2018-06-07 02:05:58 +08:00
|
|
|
return scalar ( $output =~ /systemd/ );
|
2014-08-10 21:47:11 +08:00
|
|
|
}
|
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
sub calledBysystem {
|
|
|
|
my $ppid = getppid();
|
2014-08-10 21:47:11 +08:00
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
my $output = qx(ps -o comm="" -p $ppid);
|
2018-06-07 02:05:58 +08:00
|
|
|
#chomp( $output );
|
2014-08-10 21:47:11 +08:00
|
|
|
|
2018-06-07 02:05:58 +08:00
|
|
|
return ($output =~ /^(?:systemd|init)$/);
|
2014-08-10 21:47:11 +08:00
|
|
|
}
|
2014-10-06 00:25:41 +08:00
|
|
|
|
2017-09-12 10:12:10 +08:00
|
|
|
sub verifyFolder {
|
|
|
|
my $folder = shift;
|
|
|
|
|
|
|
|
# Recreate the temporary directory if it's been wiped
|
|
|
|
if ( !-e $folder ) {
|
2018-06-07 02:05:58 +08:00
|
|
|
Debug("Recreating directory '$folder'");
|
|
|
|
mkdir($folder, 0774)
|
2017-09-12 10:12:10 +08:00
|
|
|
or Fatal( "Can't create missing temporary directory '$folder': $!" );
|
2018-06-07 02:05:58 +08:00
|
|
|
my ( $runName ) = getpwuid($>);
|
2017-09-12 10:12:10 +08:00
|
|
|
if ( $runName ne $Config{ZM_WEB_USER} ) {
|
|
|
|
# Not running as web user, so should be root in which case
|
|
|
|
# chown the directory
|
2018-06-07 02:05:58 +08:00
|
|
|
my ( $webName, $webPass, $webUid, $webGid ) = getpwnam($Config{ZM_WEB_USER})
|
|
|
|
or Fatal("Can't get details for web user '$Config{ZM_WEB_USER}': $!");
|
|
|
|
chown($webUid, $webGid, $folder)
|
|
|
|
or Fatal("Can't change ownership of '$folder' to '"
|
|
|
|
.$Config{ZM_WEB_USER}.':'.$Config{ZM_WEB_GROUP}."': $!"
|
2017-09-12 10:12:10 +08:00
|
|
|
);
|
2018-06-07 02:05:58 +08:00
|
|
|
} # end if runName ne ZM_WEB_USER
|
|
|
|
} # end if folder doesn't exist
|
|
|
|
} # end sub verifyFolder
|
2017-09-12 10:12:10 +08:00
|
|
|
|
|
|
|
1;
|
2013-12-17 05:32:02 +08:00
|
|
|
__END__
|
2017-09-12 10:12:10 +08:00
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
zmpkg.pl - ZoneMinder Package Control Script
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2018-12-28 01:24:50 +08:00
|
|
|
zmpkg.pl {start|stop|restart|status|logrot|state|version}
|
2017-09-12 10:12:10 +08:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This script is used to start and stop the ZoneMinder package primarily to
|
|
|
|
allow command line control for automatic restart on reboot (see zm script)
|
|
|
|
|
|
|
|
=cut
|