Improvements to service and package handling.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@315 e3e1d417-86f3-4887-817a-d78f3d33393fpull/27/merge
parent
cfc1f30a5c
commit
39b0076bf1
71
scripts/zm.z
71
scripts/zm.z
|
@ -2,48 +2,59 @@
|
||||||
# description: Control ZoneMinder as a Service
|
# description: Control ZoneMinder as a Service
|
||||||
# chkconfig: 2345 99 99
|
# chkconfig: 2345 99 99
|
||||||
|
|
||||||
|
# Source function library.
|
||||||
|
. /etc/rc.d/init.d/functions
|
||||||
|
|
||||||
|
prog=ZoneMinder
|
||||||
command="@prefix@/bin/zmpkg.pl"
|
command="@prefix@/bin/zmpkg.pl"
|
||||||
|
|
||||||
case "$1" in
|
start() {
|
||||||
'start')
|
echo -n "Starting $prog: "
|
||||||
$command start
|
$command start
|
||||||
status=$?
|
RETVAL=$?
|
||||||
if [ "$status" = "0" ]; then
|
[ $RETVAL = 0 ] && echo_success
|
||||||
touch /var/lock/subsys/zm
|
[ $RETVAL != 0 ] && echo_failure
|
||||||
fi
|
echo
|
||||||
;;
|
[ $RETVAL = 0 ] && touch /var/lock/subsys/zm
|
||||||
'stop')
|
return $RETVAL
|
||||||
|
}
|
||||||
|
stop() {
|
||||||
|
echo -n $"Stopping $prog: "
|
||||||
$command stop
|
$command stop
|
||||||
status=$?
|
RETVAL=$?
|
||||||
if [ "$status" = "0" ]; then
|
[ $RETVAL = 0 ] && echo_success
|
||||||
rm -f /var/lock/subsys/zm
|
[ $RETVAL != 0 ] && echo_failure
|
||||||
fi
|
echo
|
||||||
;;
|
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/zm
|
||||||
'restart')
|
}
|
||||||
$command stop
|
status() {
|
||||||
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')
|
|
||||||
result=`$command status`
|
result=`$command status`
|
||||||
if [ "$result" = "running" ]; then
|
if [ "$result" = "running" ]; then
|
||||||
echo "ZoneMinder is running"
|
echo "ZoneMinder is running"
|
||||||
status=0
|
RETVAL=0
|
||||||
else
|
else
|
||||||
echo "ZoneMinder is stopped"
|
echo "ZoneMinder is stopped"
|
||||||
status=1
|
RETVAL=1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
'start')
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
'stop')
|
||||||
|
stop
|
||||||
|
;;
|
||||||
|
'restart')
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
'status')
|
||||||
|
status
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: $0 { start | stop | restart | status }"
|
echo "Usage: $0 { start | stop | restart | status }"
|
||||||
status=1
|
RETVAL=1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
exit $status
|
exit $RETVAL
|
||||||
|
|
|
@ -39,7 +39,7 @@ use constant ZM_PATH_LOGS => "<from zmconfig>";
|
||||||
use constant ZM_OPT_FAST_DELETE => "<from zmconfig>";
|
use constant ZM_OPT_FAST_DELETE => "<from zmconfig>";
|
||||||
use constant ZM_OPT_X10 => "<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 COMMAND_PATH => '@prefix@/bin/';
|
||||||
use constant WEB_USER => '@WEB_USER@/';
|
use constant WEB_USER => '@WEB_USER@/';
|
||||||
use constant VERBOSE => 0; # Whether to output more verbose debug
|
use constant VERBOSE => 0; # Whether to output more verbose debug
|
||||||
|
@ -64,21 +64,42 @@ if ( !$command || $command !~ /^(?:start|stop|restart|status)$/ )
|
||||||
exit( -1 );
|
exit( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
my $log_file = LOG_FILE;
|
sub execute
|
||||||
open( LOG, ">>$log_file" ) or die( "Can't open log file: $!" );
|
{
|
||||||
open( STDOUT, ">&LOG" ) || die( "Can't dup stdout: $!" );
|
my $command = shift;
|
||||||
select( STDOUT ); $| = 1;
|
my $su_command = "su @WEB_USER@ --shell=/bin/sh --command='$command'";
|
||||||
open( STDERR, ">&LOG" ) || die( "Can't dup stderr: $!" );
|
#print( "Executing: $su_command\n" );
|
||||||
select( STDERR ); $| = 1;
|
return( qx( $su_command ) );
|
||||||
select( LOG ); $| = 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;
|
||||||
|
|
||||||
|
my $status = execute( COMMAND_PATH."/zmdc.pl check" );
|
||||||
|
my $retval = 0;
|
||||||
|
|
||||||
|
chomp( $status );
|
||||||
if ( $command =~ /^(?:stop|restart)$/ )
|
if ( $command =~ /^(?:stop|restart)$/ )
|
||||||
{
|
{
|
||||||
|
if ( $status eq "running" )
|
||||||
|
{
|
||||||
execute( COMMAND_PATH."/zmdc.pl shutdown" );
|
execute( COMMAND_PATH."/zmdc.pl shutdown" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$retval = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $command =~ /^(?:start|restart)$/ )
|
if ( $command =~ /^(?:start|restart)$/ )
|
||||||
{
|
{
|
||||||
|
if ( $status eq "stopped" )
|
||||||
|
{
|
||||||
execute( COMMAND_PATH."/zmfix" );
|
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 $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_SERVER, ZM_DB_USERA, ZM_DB_PASSA );
|
||||||
|
@ -109,17 +130,16 @@ if ( $command =~ /^(?:start|restart)$/ )
|
||||||
execute( COMMAND_PATH."/zmdc.pl start zmx10.pl -c start" );
|
execute( COMMAND_PATH."/zmdc.pl start zmx10.pl -c start" );
|
||||||
}
|
}
|
||||||
execute( COMMAND_PATH."/zmdc.pl start zmwatch.pl" );
|
execute( COMMAND_PATH."/zmdc.pl start zmwatch.pl" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$retval = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $command eq "status" )
|
if ( $command eq "status" )
|
||||||
{
|
{
|
||||||
print( execute( COMMAND_PATH."/zmdc.pl check" ) );
|
print( $status."\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub execute
|
exit( $retval );
|
||||||
{
|
|
||||||
my $command = shift;
|
|
||||||
my $su_command = "su @WEB_USER@ --shell=/bin/sh --command='$command'";
|
|
||||||
print( "Executing: $su_command\n" );
|
|
||||||
return( qx( $su_command ) );
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue