shotgunefx has asked for the wisdom of the Perl Monks concerning the following question:

I was experimenting with Expect.pm and ran into a problem.

I was trying to write a script that would reboot an SSL server that has it's cert protected with a passphrase.
(Not normally a good idea I know, but nothing very sensitive on this particular machine though.)

The script starts the server fine (According to the output of apachectl anyway) but it appears that the server is immediately dispatched. I just get a defunct apachectl process.

I tried using the soft_close method but it doesn't make any difference. I tried leaving the script around sleeping thinking Expect was killing it on exit but even then, it dies instantaneously (the soft_close was after the sleep). Is this normal behavior? Is there some concept I'm missing? I don't understand this behavior and I'm guessing it shouldn't be doing this. I don't see any errors in any of the logs. I've tried turning Expect's debugging on and don't see any indication of an error either.

Here's the code...
#!/usr/bin/perl use Expect; my $apache = "/usr/local/apache-ssl/bin/apachectl"; $command = Expect->spawn($apache, 'startssl') or die "Couldn't start program: $!\n"; # prevent the program's output from being shown on STDOUT # $command->log_stdout(0); # wait 10 seconds for pass phrase unless ($command->expect(20, -re => "Enter pass phrase ?")) { # timed out } # send passphrase print $command "NotARealPassPhrase\r"; ## wait 10 seconds for confirmation of server start. unless ($command->expect(10, -re => "Ok: Pass Phrase Dialog successful +.")) { die "Passphrase excepted!\n"; } ## wait 10 seconds for confirmation of server start. Otherwise, die unless ($command->expect(10, -re => "startssl: httpd started")) { die "SSL Didn't start!\n"; } # program will terminate by itself, finish with $command->soft_close();


-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re: Trouble starting Daemon with Expect.pm
by shotgunefx (Parson) on Jul 31, 2001 at 13:12 UTC
    " Is there some concept I'm missing? I don't understand this behavior and I'm guessing it shouldn't be doing this. "

    Just a clarification. What I meant is that I would assume that apache would disassociate itself from the controling terminal like it does under a normal TTY.

    -Lee

    "To be civilized is to deny one's nature."
Re: Trouble starting Daemon with Expect.pm
by da (Friar) on Aug 03, 2001 at 23:45 UTC
    The script starts the server fine (According to the output of apachectl anyway) but it appears that the server is immediately dispatched. I just get a defunct apachectl process.

    I've not used expect before, but I do know that apachectl isn't supposed to hang around after starting apache; it should exit in good order. That would suggest to me an apache/ssl startup problem.

    I just glanced at the expect FAQ, which has this:

    Q: How come when I automate the passwd program to change passwords for me passwd dies before changing the password sometimes/every time? A: What's happening is you are closing the handle before passwd exits. When you close the handle to a process it is sent a signal (SIGPIPE?) telling it that STDOUT has gone away. The default behavior for processes is to die in this circumstance. Two ways you can make this not happen are: $process->soft_close(); Which is new in 1.04. This will wait 15 seconds for a process to finish up before killing it. $process->expect(undef); This will wait forever for the process to match an empty set of patterns. It will return when the process hits an EOF.
    Is it possible your sleep isn't long enough for apachectl to return? You might see what happens with
    $process->expect(0)

    ___ -DA > perl -MPOSIX -le '$ENV{TZ}="EST";print ctime(1000000000)' Sat Sep 8 20:46:40 2001
      Thanks for the suggestions. I've tried all of the above and still no dice. Apachectl runs to completion and reports success but still no server is started. It does the same thing when I try to start the binary directly without using the apachectl script. Nothing in the error logs either. I'm stumped.

      -Lee

      "To be civilized is to deny one's nature."