NAME

Mojo::IOLoop::ReadWriteProcess::Container - Start Mojo::IOLoop::ReadWriteProcess as containers.

SYNOPSIS

use Mojo::IOLoop::ReadWriteProcess::Container qw(container);

my $container = container(
  pid_isolation => 1,  # Best-effort, as depends on where you run it (you need CAP_SYS_ADMIN)
  subreaper => 1,
  group   => "my_org",
  name    => "my_process",
  process => process(
    sub {
      process(sub { warn "\o/"; sleep 42;  })->start;
      process(sub { warn "\o/"; sleep 42; })->start;
      process(
        sub {
          process(
            sub {
              process(sub { warn "\o/"; sleep 42; })->start;
              warn "\o/";
              sleep 400;
              warn "\o/";
            })->start;
          warn "Hey";
          sleep 42;
          warn "\o/";
        })->start;
      sleep 42;
    }
  )->separate_err(0));

$container->start();
$container->is_running;
$container->stop;

my @procs = $container->cgroup->processes;
$container->cgroup->pid->max(300);

$container->process->on(stop => sub { print "Main container process stopped!" });

DESCRIPTION

This module uses features that are only available on Linux, and requires cgroups and capability (CAP_SYS_ADMIN) for unshare syscalls to achieve pid isolation.

METHODS

Mojo::IOLoop::ReadWriteProcess::Container inherits all methods from Mojo::EventEmitter and implements the following new ones.

start

use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
use Mojo::IOLoop::ReadWriteProcess qw(process);

my $c = container( name=>"test", process => process(sub { print "Hello!" }));
$c->start();

Starts the container, it's main process is a Mojo::IOLoop::ReadWriteProcess, contained in the process() attribute.

is_running

use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
use Mojo::IOLoop::ReadWriteProcess qw(process);

my $c = container( name=>"test", process => process(sub { print "Hello!" }));
$c->is_running();

Returns 1 if the container is running.

stop

use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
use Mojo::IOLoop::ReadWriteProcess qw(process);

my $c = container( name=>"test", process => process(sub { print "Hello!" }))->start;
$c->stop();

Stops the container and kill all the processes belonging to the cgroup. It also registers all the unknown processes to the current Mojo::IOLoop::ReadWriteProcess::Session.

wait_stop

use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
use Mojo::IOLoop::ReadWriteProcess qw(process);

my $c = container( name=>"test", process => process(sub { print "Hello!" }))->start;
$c->wait_stop();

Wait before stopping the container.

wait

use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
use Mojo::IOLoop::ReadWriteProcess qw(process);

my $c = container( name=>"test", process => process(sub { print "Hello!" }))->start;
$c->wait();

Wait the container to stop

LICENSE

Copyright (C) Ettore Di Giacinto.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Ettore Di Giacinto <edigiacinto@suse.com>