Improvements to service and package handling.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@315 e3e1d417-86f3-4887-817a-d78f3d33393f
pull/27/merge
stan 2003-01-14 12:37:47 +00:00
parent cfc1f30a5c
commit 39b0076bf1
2 changed files with 115 additions and 84 deletions

View File

@ -2,48 +2,59 @@
# description: Control ZoneMinder as a Service
# chkconfig: 2345 99 99
# Source function library.
. /etc/rc.d/init.d/functions
prog=ZoneMinder
command="@prefix@/bin/zmpkg.pl"
case "$1" in
'start')
start() {
echo -n "Starting $prog: "
$command start
status=$?
if [ "$status" = "0" ]; then
touch /var/lock/subsys/zm
fi
;;
'stop')
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/zm
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
$command stop
status=$?
if [ "$status" = "0" ]; then
rm -f /var/lock/subsys/zm
fi
;;
'restart')
$command stop
status=$?
if [ "$status" = "0" ]; then
rm -f /var/lock/subsys/zm
fi
$command start
status=$?
if [ "$status" = "0" ]; then
touch /var/lock/subsys/zm
fi
;;
'status')
RETVAL=$?
[ $RETVAL = 0 ] && echo_success
[ $RETVAL != 0 ] && echo_failure
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/zm
}
status() {
result=`$command status`
if [ "$result" = "running" ]; then
echo "ZoneMinder is running"
status=0
RETVAL=0
else
echo "ZoneMinder is stopped"
status=1
RETVAL=1
fi
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
status
;;
*)
echo "Usage: $0 { start | stop | restart | status }"
status=1
RETVAL=1
;;
esac
exit $status
exit $RETVAL

View File

@ -39,7 +39,7 @@ use constant ZM_PATH_LOGS => "<from zmconfig>";
use constant ZM_OPT_FAST_DELETE => "<from zmconfig>";
use constant ZM_OPT_X10 => "<from zmconfig>";
use constant LOG_FILE => ZM_PATH_LOGS.'/zmpkg.log';
#use constant LOG_FILE => ZM_PATH_LOGS.'/zmpkg.log';
use constant COMMAND_PATH => '@prefix@/bin/';
use constant WEB_USER => '@WEB_USER@/';
use constant VERBOSE => 0; # Whether to output more verbose debug
@ -64,62 +64,82 @@ if ( !$command || $command !~ /^(?:start|stop|restart|status)$/ )
exit( -1 );
}
my $log_file = LOG_FILE;
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
select( STDOUT ); $| = 1;
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
select( STDERR ); $| = 1;
select( LOG ); $| = 1;
if ( $command =~ /^(?:stop|restart)$/ )
{
execute( COMMAND_PATH."/zmdc.pl shutdown" );
}
if ( $command =~ /^(?:start|restart)$/ )
{
execute( COMMAND_PATH."/zmfix" );
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_SERVER, ZM_DB_USERA, ZM_DB_PASSA );
my $sql = "select * from Monitors";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
while( my $monitor = $sth->fetchrow_hashref() )
{
if ( $monitor->{Function} ne 'None' )
{
execute( COMMAND_PATH."/zmdc.pl start zmc -d $monitor->{Device}" );
if ( $monitor->{Function} ne 'Passive' )
{
execute( COMMAND_PATH."/zmdc.pl start zma -m $monitor->{Id}" );
}
}
execute( COMMAND_PATH."/zmdc.pl start zmfilter.pl -m $monitor->{Id} -e -1" );
}
$sth->finish();
if ( ZM_OPT_FAST_DELETE )
{
execute( COMMAND_PATH."/zmdc.pl start zmaudit.pl -d 900 -y" );
}
if ( ZM_OPT_X10 )
{
execute( COMMAND_PATH."/zmdc.pl start zmx10.pl -c start" );
}
execute( COMMAND_PATH."/zmdc.pl start zmwatch.pl" );
}
if ( $command eq "status" )
{
print( execute( COMMAND_PATH."/zmdc.pl check" ) );
}
sub execute
{
my $command = shift;
my $su_command = "su @WEB_USER@ --shell=/bin/sh --command='$command'";
print( "Executing: $su_command\n" );
#print( "Executing: $su_command\n" );
return( qx( $su_command ) );
}
#my $log_file = LOG_FILE;
#open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
#open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
#select( STDOUT ); $| = 1;
#open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
#select( STDERR ); $| = 1;
#select( LOG ); $| = 1;
my $status = execute( COMMAND_PATH."/zmdc.pl check" );
my $retval = 0;
chomp( $status );
if ( $command =~ /^(?:stop|restart)$/ )
{
if ( $status eq "running" )
{
execute( COMMAND_PATH."/zmdc.pl shutdown" );
}
else
{
$retval = 1;
}
}
if ( $command =~ /^(?:start|restart)$/ )
{
if ( $status eq "stopped" )
{
execute( COMMAND_PATH."/zmfix" );
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_SERVER, ZM_DB_USERA, ZM_DB_PASSA );
my $sql = "select * from Monitors";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
while( my $monitor = $sth->fetchrow_hashref() )
{
if ( $monitor->{Function} ne 'None' )
{
execute( COMMAND_PATH."/zmdc.pl start zmc -d $monitor->{Device}" );
if ( $monitor->{Function} ne 'Passive' )
{
execute( COMMAND_PATH."/zmdc.pl start zma -m $monitor->{Id}" );
}
}
execute( COMMAND_PATH."/zmdc.pl start zmfilter.pl -m $monitor->{Id} -e -1" );
}
$sth->finish();
if ( ZM_OPT_FAST_DELETE )
{
execute( COMMAND_PATH."/zmdc.pl start zmaudit.pl -d 900 -y" );
}
if ( ZM_OPT_X10 )
{
execute( COMMAND_PATH."/zmdc.pl start zmx10.pl -c start" );
}
execute( COMMAND_PATH."/zmdc.pl start zmwatch.pl" );
}
else
{
$retval = 1;
}
}
if ( $command eq "status" )
{
print( $status."\n" );
}
exit( $retval );