Exobrain

 view release on metacpan or  search on metacpan

bin/exobrain  view on Meta::CPAN


if (not $command) {
    ubic_services();
}
elsif ($command eq 'setup') {
    my @comps = @args;
    
    # If there are components listed, set them up...
    
    if (@comps) {
        my $exobrain = Exobrain->new;
        foreach my $comp (@comps) {
            my $comp_module = 'Exobrain::' . $comp;
            eval "use $comp_module";

            if ($@) { die "Loading $comp_module failed. Did you install it first? (cpanm $comp_module)\n"; }

            say "Configuring $comp_module...\n";

            $comp_module->new->setup;
        }
        exit 0;
    }

    # Otherwise, configure exobrain itself.

    say "Setting up exobrain...";

    my $ubic = "$ENV{HOME}/ubic";
    if (not -d $ubic) {
        say "It doesn't look like ubic is installed; at least, I can't find $ubic.";
        say "Have you run `cpanm Ubic` and `ubic-admin setup`?\n\n";
        die "Halting (Ubic not found)\n";
    }

    my $exobrain_log = "$ubic/log/exobrain";

    if (-d $exobrain_log) {
        say "We already have $exobrain_log, skipping...";
    }
    else {
        say "Creating $exobrain_log";
        mkdir($exobrain_log);
    }

    my $exe     = $0;
    my $service = "$ubic/service/";
    
    say "Copying $exe to $service";
    copy($0, $service);

    say "Done!\n";
    say "\nYou should use 'ubic start exobrain.core' to start exobrain.";

}
elsif ($command eq "debug") {
    my $exobrain = Exobrain->new;

    # Options handling

    local @ARGV  = @args;
    my %opts = ( v => 0 );
    getopts('v', \%opts);

    # Loop forever showing packets off the bus, either verbosely
    # or not. These use the lowest-level functions available, so
    # should catch even malformed packets.

    while (1) {
        if ($opts{v}) {
            say $exobrain->sub->get->dump;
            say "-" x 50;
        }
        else {
            say $exobrain->sub->get->summary;
        }
    }
}
elsif ($command eq "run") {
    my ($class) = @args;
    $class or die "Usage: $0 run class";

    Exobrain->run($class);
}
else {
    # Apparently ubic calls us with service names when it wants
    # to know stuff. So assume that a weird argument is ubic
    # doing its thing
    ubic_services();
    # die "$0: Unknown command: $command @args\n";
}

sub daemon {
    my ($bin) = @_;

    return Ubic::Service::SimpleDaemon->new(
        common_options($bin),
        bin      => $bin,
    );
}

sub agent {
    my ($name, $class) = @_;

    # If our class can't be run, then don't return anything
    if (not Exobrain->can_run($class)) { return () }

    # Run is ourselves, with the run command.
    my @run = ( __FILE__ , "run" );

    my @opts = ( common_options($class), bin => "@run $class" );

    return ($name => Ubic::Service::SimpleDaemon->new( @opts ) );

}

sub common_options {
    my ($name) = @_;

    my $LOG_HOME = "$ENV{HOME}/ubic/log/exobrain";



( run in 2.327 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )