## OpenCA - Public Web-Gateway Command
## (c) 1999-2009 by Massimiliano Pala and OpenCA Group
##
##   File Name: stopAutoCA
##       Brief: stop Auto (On-Line) CA Daemon
##     Version: $Revision: 1.4 $
## Description: this script stops the On-Line CA Daemon
##  Parameters: 

use strict;

sub cmdStopAutoCA {

	my $pidfile = undef;
	my $pid = undef;

	$pidfile = $AUTOCONF{"var_prefix"}."/tmp/openca_autoca.pid";

	if( -f "$pidfile" ) {
		my $result = undef;
		my $FD = undef;

		if( not open ( FD, "<$pidfile" )) {
			generalError("Can not open $pidfile!");
		} else {
			$pid = <FD>;
			close( FD );
		}

		$result = POSIX::kill( $pid, 0);
		if( $result gt 0 ) {
			## The process is active!
			$result = POSIX::kill( $pid, 1);
		#	success( 400, "The On-Line Daemon is now disabled!");
		#} else {
		#	success( 400, "The On-Line Daemon is now disabled!");
		}
		$query->param ('cmd', 'statusAutoCA' );
        	libExecuteCommand ();
	} else {
		cmdStatusAutoCA();
	}

}

1;
