#!/usr/bin/perl

  $httpd="/usr/local/httpd/bin/httpd";

        $cgi_php="-DNOPHP";
        $cgi_perl="-DNOPHP";
        $mod_php="";
        $mod_perl="-DNOPHP -DPERL";

        $cmd_file="/tmp/apache_restarter.cmd";

        while (1){
                print "Wait command ...\n";

                while(1){
                        last if (-s $cmd_file);
                        sleep 1;
                }

                chop($cmd=`cat $cmd_file`);
                unlink $cmd_file;
                print "Command $cmd ...\n";

                my $param = '';

                if ($cmd =~ /php/){
                        if($cmd =~ /cgi/){
                                $param = $cgi_php;
                        }else{
                                $param = $mod_php;
                        }
                }elsif($cmd =~ /perl/){
      if($cmd =~ /cgi/){
        $param = $cgi_perl;
      }else{
        $param = $mod_perl;
      }
                }

    unless($cmd eq ""){
                        system("apachectl stop");
                        sleep 10;
                print $param,"\n";
                        system("$httpd $param") ;
                }
        }