#!/usr/local/bin/perl
# stop.cgi
# Stop the PostgreSQL database server

require './postgresql-lib.pl';
&error_setup($text{'stop_err'});
$access{'stop'} || &error($text{'stop_ecannot'});
if ($config{'stop_cmd'}) {
	$out = &backquote_logged("$config{'stop_cmd'} 2>&1");
	if ($?) {
		&error("<pre>$?\n$out</pre>");
		}
	}
else {
	open(PID, $config{'pid_file'});
	($pid = <PID>) =~ s/\r|\n//g;
	close(PID);
	$pid || &error(&text('stop_epidfile', "<tt>$config{'pid_file'}</tt>"));
	&kill_logged('TERM', $pid) ||
		&error(&text('stop_ekill', "<tt>$pid</tt>", "<tt>$!</tt>"));
	}
sleep(2);
&webmin_log("stop");
&redirect("");

