#!/afs/athena/contrib/perl/perl


($host = `hostname`) =~ s/\n$//;
$fullhost = $host . ".mit.edu";
$init = shift(@ARGV) || "/site/clh/clh.init";

%ENV = ("PATH",$ENV{"PATH"},"HOME","/site/clh","HOST",$host);

$clhsrv = "/site/clh/bin/clh_server";
$lstsrv = "/site/clh/bin/list_server";

if ($cpid = fork) {		# parent
    print "starting clh_server as pid $cpid\n";
    sleep(30);
    if ($lpid = fork) {		# parent
	print "starting list_server as pid $lpid\n";
    } elsif (defined $lpid)  {	# list-server child
	exec $lstsrv 'marc_do_not_kill_list_server', $fullhost;
	warn "Oops! list_server exec: $!\n";
    } else {
	die "Can't fork: $!\n";
    }
} elsif (defined $cpid)  {	# clh-server child
    exec $clhsrv 'marc_do_not_kill_clh_server', $fullhost, $init;
    warn "Oops! clh_server exec: $!\n";
} else {
    die "Can't fork: $!\n";
}

printf "done.\n";
