Bot-Cobalt

 view release on metacpan or  search on metacpan

bin/cobalt2  view on Meta::CPAN

    "   --rcfile=/path/to/rcfile \n",
    "     Specify a rcfile. Defaults to \$HOME/.cobalt2rc \n",
    "   --base=/path/to/basedir \n",
    "     Specify base path for 'etc/' and 'var/' for this instance\n",
    "     Overrides rcfile. \n",
  );

  exit 0
}

sub _rc_check {
  unless (-e $rcfile) {
    say ">! rcfile $rcfile not found.";
    say ">! You can specify one via --rcfile=";
    say ">! If this is your first time running cobalt2, try `cobalt2-installer`";
    die "rcfile not found"
  } else {
    return 1
  }
}

sub _check_dirs {
  my %paths = (
    etcdir => $etcdir,
    vardir => $vardir,
  );
  for my $thisname (keys %paths) {
    my $thispath = $paths{$thisname};
    unless (-e $thispath) {
      say ">! $thisname ($thispath) doesn't appear to exist.";
      say ">! Your rcfile ($rcfile) may be broken.";
      say ">! Perhaps try `cobalt2-installer`";
      die "$thisname not a directory"
    }
  }
}

sub _check_cfs {
  ## Check if required confs exist in etcdir
  ## Otherwise suggest cobalt2-installer

  my @required = qw/ cobalt.conf channels.conf plugins.conf /;

  for my $file (@required) {
    unless (-e File::Spec->catfile($etcdir, $file) ) {
      say ">! Missing core conf: $file";
      say ">! (etcdir: $etcdir)";
      say ">! You may want to try `cobalt2-installer`";
      die "missing core conf: $file"
    }
  }
}


sub _start_cobalt {
  my $pid = Proc::PID::File->new(
    dir => $vardir,
    name => 'cobalt',
  );
  die "cobalt appears to be already running\n"
    if $pid->alive;

  ## POSIX fork dance
  use POSIX ();
  if ($opt_detach)
  {
    say "Starting cobalt in background";
    my $fork = fork;
    exit 1 if not defined $fork;
    exit 0 if $fork;
    POSIX::setsid();
    $fork = fork;
    exit 1 if not defined $fork;
    exit 0 if $fork;
    chdir('/');
    open(STDIN, '<', '/dev/null');
    open(STDOUT, '>>', '/dev/null');
    open(STDERR, '>>', '/dev/null');
    umask(022);
  }
  $pid->touch();

  require Bot::Cobalt::Conf;
  require Bot::Cobalt::Core;

  ## FIXME could take paths to specific confs now
  my $cfg = Bot::Cobalt::Conf->new(
    etc   => $etcdir,
    debug => $opt_debug,
  );

  Bot::Cobalt::Core->instance(
    cfg => $cfg,
    var => $vardir,
    loglevel => $loglevel,
    debug    => $opt_debug,
    detached => $opt_detach,
  )->init;

  POE::Kernel->run;
}


say "-> debug ON, overrides loglevel" if $opt_debug;
## Bot::Cobalt::Core does this anyway, but just for the validator:
$loglevel = $opt_debug ? 'debug' : lc $loglevel ;
## Check specified loglevel
my @loglevels = qw/debug info notice warn warning
                   err error crit critical alert
                   emerg emergency/;

unless ($loglevel && grep { $_ eq $loglevel } @loglevels) {
  say("Invalid loglevel ($loglevel)");
  say("Possible loglevels, most verbose to least: ".join(' ',@loglevels));
  say("Setting loglevel to INFO");

  $loglevel = 'info';
}


if ($basedir) {



( run in 1.960 second using v1.01-cache-2.11-cpan-437f7b0c052 )