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
|
||||
# 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
|
||||
|
|
|
@ -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,21 +64,42 @@ 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;
|
||||
sub execute
|
||||
{
|
||||
my $command = shift;
|
||||
my $su_command = "su @WEB_USER@ --shell=/bin/sh --command='$command'";
|
||||
#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 );
|
||||
|
@ -109,17 +130,16 @@ if ( $command =~ /^(?:start|restart)$/ )
|
|||
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( execute( COMMAND_PATH."/zmdc.pl check" ) );
|
||||
print( $status."\n" );
|
||||
}
|
||||
|
||||
sub execute
|
||||
{
|
||||
my $command = shift;
|
||||
my $su_command = "su @WEB_USER@ --shell=/bin/sh --command='$command'";
|
||||
print( "Executing: $su_command\n" );
|
||||
return( qx( $su_command ) );
|
||||
}
|
||||
exit( $retval );
|
||||
|
|
Loading…
Reference in New Issue