RunApp::Control::AppControl - Class for controlling daemon with App::Control


RunApp documentation Contained in the RunApp distribution.

Index


Code Index:

NAME

Top

RunApp::Control::AppControl - Class for controlling daemon with App::Control

SYNOPSIS

Top

 see RunApp::Apache

DESCRIPTION

Top

The class writes to a perl script that uses App::Control to control the daemon in the build phase of RunApp, and invokes the control script in other phases.

SEE ALSO

Top

App::Control

AUTHORS

Top

Chia-liang Kao <clkao@clkao.org>

COPYRIGHT

Top


RunApp documentation Contained in the RunApp distribution.

package RunApp::Control::AppControl;
use strict;
require App::Control::Apache;
require YAML;
use base qw(RunApp::Control);
use Config;

sub build {
  my $self = shift;
  my ($conf) = @_;

  $self->{CONTROL} ||= 'App::Control';
  $self->load($self->{CONTROL});

  $self->{control} = $self->{CONTROL}->new
      ( EXEC => $self->{binary},
        ARGS => $self->{args},
        PIDFILE => $conf->{pidfile},
        SLEEP => 1,
        LOOP => 1);

  $self->write;
}

sub dispatch {
  my ($self, $cmd) = @_;
  if ($self->{control}) {
    $self->{control}->$cmd;
  } else {
    system ($self->{file}, $cmd);
  }
}

sub write {
  my $self = shift;
  open my $fh, '>', $self->{file} or die "$self->{file}: $!";
  #warn ". building $self->{file}\n";
  my $control = YAML::Dump ($self->{control});

  my $perl = $Config{'perlpath'};
  $perl = $^X if $^O eq 'VMS';

  print $fh (<< ".");
#!$perl -w
use strict;
use App::Control::Apache;
require YAML;
my \$cmd = shift or die "\$0: <start|stop|restart|graceful|hup|status>\\n";
YAML::Load ( << 'YAML')->dispatch (\$cmd);
$control
YAML

.
}

1;