lib/Mojo/IOLoop/ReadWriteProcess/Container.pm

filter: Statementstmt 97.2% 106 / 109 Branchbran 84.2% 32 / 38 Conditioncond 72.2% 13 / 18 MC/DCmcdc 54.5% 6 / 11 Subroutinesub 94.4% 34 / 36 Podpod 87.5% 7 / 8 totaltotal 90.0% 198 / 220 CC 26 SCAR 15.2
CC
26
Cov
92%
start
13.3
__ANON__
5.4
__ANON__
5.1
CRAP 4.6
« lib/Mojo/IOLoop/ReadWriteProcess/Shared/Lock.pm ↑ Summary builder/custom.pm »
1 package Mojo::IOLoop::ReadWriteProcess::Container;
2  
3 13 ▶use Mojo::Base 'Mojo::EventEmitter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use Mojo::IOLoop::ReadWriteProcess::CGroup;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Mojo::IOLoop::ReadWriteProcess;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use Mojo::IOLoop::ReadWriteProcess::Namespace qw( CLONE_NEWPID CLONE_NEWNS );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use Mojo::IOLoop::ReadWriteProcess;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Mojo::IOLoop::ReadWriteProcess::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Mojo::Collection 'c';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 our @EXPORT_OK = qw(container);
12 13 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 13 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 13 has 'name';
16 13 has 'group';
17  
18 # Roughly a container
19 0 ▶has process => sub { Mojo::IOLoop::ReadWriteProcess->new };
Subroutine __ANON__: not called CC=1 SCAR=1.2
20 59 ▶has cgroups => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
21 59 c(Mojo::IOLoop::ReadWriteProcess::CGroup::v1->new(controller => 'pids'));
22 13 };
23 5 ▶has namespace => sub { Mojo::IOLoop::ReadWriteProcess::Namespace->new };
Subroutine __ANON__: called CC=1 SCAR=0.0
24 65 ▶has session => sub { Mojo::IOLoop::ReadWriteProcess::Session->singleton };
Subroutine __ANON__: called CC=1 SCAR=0.0
25 58 ▶has pid_isolation => sub { 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
26 13 has unshare => undef;
27 13 has subreaper => 0;
28 13 has pre_migrate => 0;
29 13 has clean_cgroup => 0;
30  
31 13 ▶use constant DEBUG => $ENV{MOJO_PROCESS_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 76 ▶sub container { __PACKAGE__->new(@_) }
Subroutine container: called CC=1 SCAR=0.0
Pod undocumented
34  
35 76 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
36 76 my $self = shift->SUPER::new(@_);
37 76 ▶ $self->cgroups(c($self->cgroups))
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self->cgroups) and $self->cgroups->isa("Mojo::Collection") 9 67 76
Condition66%2/3
builtin::blessed($self->cgroups) and $self->cgroups->isa("Mojo::Collection")
!ll&&!rl&&r
0967
MC/DC50%1/2
builtin::blessed($self->cgroups) and $self->cgroups->isa("Mojo::Collection")
builtin::blessed($self->cgroups) $self->cgroups->isa("Mojo::Collection")
Truth table66%2/3
A and B
A= builtin::blessed($self->cgroups)B= $self->cgroups->isa("Mojo::Collection")
ABresult
0X0
100
111
38 unless blessed $self->cgroups && $self->cgroups->isa('Mojo::Collection');
39 76 $self;
40 }
41  
42 36 ▶sub migrate_process {
Subroutine migrate_process: called CC=1 SCAR=0.0
Pod documented
43 36 my $p = pop();
44 36 ▶ shift->cgroups->each(sub { shift->add_process($p) });
Subroutine __ANON__: called CC=1 SCAR=0.0
45 }
46  
47 76 ▶sub start {
Subroutine start: called CC=13 SCAR=25.9
Pod documented
48 76 my $self = shift;
49 76 ▶ croak
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self->process) and $self->process->isa("Mojo::IOLoop::ReadWriteProcess") or ref $self->process eq "CODE" 11 65 76
Condition83%5/6
builtin::blessed($self->process) and $self->process->isa("Mojo::IOLoop::ReadWriteProcess") or ref $self->process eq "CODE"
l!l&&r!l&&!r
541111
builtin::blessed($self->process) and $self->process->isa("Mojo::IOLoop::ReadWriteProcess")
!ll&&!rl&&r
22054
MC/DC66%2/3
builtin::blessed($self->process) and $self->process->isa("Mojo::IOLoop::ReadWriteProcess") or ref $self->process eq "CODE"
builtin::blessed($self->process) $self->process->isa("Mojo::IOLoop::ReadWriteProcess") ref $self->process eq "CODE"
Truth table60%3/5
A and B or C
A= builtin::blessed($self->process)B= $self->process->isa("Mojo::IOLoop::ReadWriteProcess")C= ref $self->process eq "CODE"
ABCresult
11X1
0X11
1011
0X00
1000
50 'You need either to pass a Mojo::IOLoop::ReadWriteProcess object or a callback'
51 unless (blessed $self->process
52 && $self->process->isa("Mojo::IOLoop::ReadWriteProcess"))
53 || ref $self->process eq 'CODE';
54  
55 65 ▶ $self->process(Mojo::IOLoop::ReadWriteProcess->new($self->process))
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self->process) 11 54 65
56 unless blessed $self->process;
57  
58 $self->cgroups->map(
59 65 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.8
60 65 ▶ return $_ if $_->name || $_->parent;
Branch: 1 branch
BranchTrueFalseTotal
if $_->name or $_->parent 17 48 65
Condition66%2/3
$_->name or $_->parent
l!l&&r!l&&!r
17048
MC/DC50%1/2
$_->name or $_->parent
$_->name $_->parent
Truth table66%2/3
A or B
A= $_->nameB= $_->parent
ABresult
1X1
011
000
61 48 ▶ $_ = $_->name($self->group)->create if $self->group;
Branch: 1 branch
BranchTrueFalseTotal
if $self->group 48 0 48
62 48 ▶ $_ = $_->child($self->name)->create if $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->name 48 0 48
63 65 ▶ }) if defined $self->group || defined $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->group or defined $self->name 65 0 65
Condition33%1/3
defined $self->group or defined $self->name
l!l&&r!l&&!r
6500
MC/DC0%0/2
defined $self->group or defined $self->name
defined $self->group defined $self->name
Truth table33%1/3
A or B
A= defined $self->groupB= defined $self->name
ABresult
1X1
011
000
64  
65 65 ▶ $self->process->subreaper(1) if $self->subreaper;
Branch: 1 branch
BranchTrueFalseTotal
if $self->subreaper 38 27 65
66  
67 65 ▶ $self->unshare(CLONE_NEWPID | CLONE_NEWNS) if $self->pid_isolation;
Branch: 1 branch
BranchTrueFalseTotal
if $self->pid_isolation 7 58 65
68 $self->process->once(
69 30 ▶ start => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
70 30 $self->migrate_process($self->process->pid);
71 65 ▶ }) unless $self->pre_migrate;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->pre_migrate 34 31 65
72  
73 $self->process->once(
74 55 ▶ stop => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
75 $self->cgroups->each(
76 55 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
77 $_[0]->processes->each(
78 55 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
79 55 my $pid = shift;
80 55 my $p = Mojo::IOLoop::ReadWriteProcess->new(
81 process_id => $pid,
82 blocking_stop => 1
83 );
84 55 $self->session->register($pid => $p);
85 55 $p->stop();
86 55 });
87 55 ▶ $_[0]->remove() if $self->clean_cgroup;
Branch: 1 branch
BranchTrueFalseTotal
if $self->clean_cgroup 28 27 55
88 55 });
89 65 });
90  
91 65 ▶ $self->process->once(stop => sub { shift; $self->emit(stop => @_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
92 65 ▶ $self->process->once(start => sub { shift; $self->emit(start => @_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
93  
94 65 my $fn = $self->process->code();
95  
96 2 ▶ $self->process->code(sub { $self->migrate_process($$); $fn->(@_) })
Subroutine __ANON__: called CC=1 SCAR=0.0
97 65 ▶ if $self->pre_migrate;
Branch: 1 branch
BranchTrueFalseTotal
if $self->pre_migrate 31 34 65
98  
99 $self->process->code(
100 5 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
101 5 ▶ $self->migrate_process($$) if $self->pre_migrate;
Branch: 1 branch
BranchTrueFalseTotal
if $self->pre_migrate 4 1 5
102  
103 5 ▶ if ( $self->unshare & CLONE_NEWPID
Branch: 2 branches
BranchTrueFalseTotal
if ($self->unshare & 536870912 and $self->namespace->unshare($self->unshare) == 0) { } 1 4 5
elsif ($self->namespace->unshare($self->unshare) != 0) { } 2 2 4
Condition100%3/3
$self->unshare & 536870912 and $self->namespace->unshare($self->unshare) == 0
!ll&&!rl&&r
311
MC/DC100%2/2
$self->unshare & 536870912 and $self->namespace->unshare($self->unshare) == 0
$self->unshare & 536870912 $self->namespace->unshare($self->unshare) == 0
Truth table100%3/3
A and B
A= $self->unshare & 536870912B= $self->namespace->unshare($self->unshare) == 0
ABresult
0X0
100
111
104 && $self->namespace->unshare($self->unshare) == 0)
105 {
106  
107 # In such case, we have to spawn another process
108 my $init = Mojo::IOLoop::ReadWriteProcess->new(
109 set_pipes => 0,
110 internal_pipes => 1,
111 1 ▶ code => sub {
Subroutine __ANON__: called CC=3 SCAR=11.7
112 1 ▶ $_[0]->enable_subreaper if $self->subreaper;
Branch: 1 branch
BranchTrueFalseTotal
if $self->subreaper 0 1 1
113 1 ▶ $self->namespace->isolate() if $self->unshare & CLONE_NEWNS;
Branch: 1 branch
BranchTrueFalseTotal
if $self->unshare & 131072 1 0 1
114 1 $fn->(@_);
115 1 });
116 1 $init->start()->wait_stop;
117  
118 #return $init->return_status if defined $init->return_status;
119 0 $init->_exit($init->exit_status);
120 }
121 elsif ($self->namespace->unshare($self->unshare) != 0) {
122 2 warn "Unshare failed";
123 }
124  
125 4 $fn->(@_);
126 65 ▶ }) if defined $self->unshare;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->unshare 21 44 65
127  
128 65 if (DEBUG) {
129 $self->process->diag("Starting container");
130 $self->process->diag("\tName: " . $self->name) if defined $self->name;
131 $self->process->diag("\tGroup: " . $self->group) if defined $self->group;
132 $self->cgroups->each(
133 0 ▶ sub { $self->process->diag("CGroup: " . $_->_cgroup) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
134 }
135  
136 65 local ($@, $!);
137 65 eval { $self->process->start(); };
138 55 ▶ $self->emit(container_error => [$@, $!]) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 55 55
139  
140 55 $self;
141 }
142  
143 9 ▶sub stop { shift->emit('stop')->process->stop() }
Subroutine stop: called CC=1 SCAR=0.0
Pod documented
144  
145 299 ▶sub is_running { shift->process->is_running }
Subroutine is_running: called CC=1 SCAR=0.0
Pod documented
146  
147 45 ▶sub wait_stop { shift->process->wait_stop }
Subroutine wait_stop: called CC=1 SCAR=0.0
Pod documented
148  
149 10 ▶sub wait { shift->process->wait }
Subroutine wait: called CC=1 SCAR=0.0
Pod documented
150  
151 =encoding utf-8
152  
153 =head1 NAME
154  
155 Mojo::IOLoop::ReadWriteProcess::Container - (kinda) Pure Perl containers.
156  
157 =head1 SYNOPSIS
158  
159 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
160 use Mojo::IOLoop::ReadWriteProcess qw(process);
161  
162 my $container = container(
163 pid_isolation => 1, # Best-effort, as depends on where you run it (you need CAP_SYS_ADMIN)
164 subreaper => 1,
165 group => "my_org",
166 name => "my_process",
167 process => process(
168 sub {
169 # Exec, fork ..
170 process(sub { warn "\o/"; sleep 42; })->start;
171 process(sub { warn "\o/"; sleep 42; })->start;
172 process(
173 sub {
174 process(
175 sub {
176 process(sub { warn "\o/"; sleep 42; })->start;
177 warn "\o/";
178 sleep 400;
179 warn "\o/";
180 })->start;
181 warn "Hey";
182 sleep 42;
183 warn "\o/";
184 })->start;
185 sleep 42;
186 }
187 )->separate_err(0));
188  
189 $container->start();
190 $container->is_running;
191 $container->stop;
192  
193 my @procs = $container->cgroups->first->processes;
194 $container->cgroups->first->pid->max(300);
195  
196 $container->process->on(stop => sub { print "Main container process stopped!" });
197  
198 =head1 DESCRIPTION
199  
200 L<Mojo::IOLoop::ReadWriteProcess::Container> ties anonymous functions or a L<Mojo::IOLoop::ReadWriteProcess> object to different
201 sets of L<Mojo::IOLoop::ReadWriteProcess::CGroup> implementations.
202  
203 When the C<pid_isolation> attribute is set, it needs special permissions (CAP_SYS_ADMIN capabilities).
204 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.
205  
206 =head1 EVENTS
207  
208 L<Mojo::IOLoop::ReadWriteProcess> inherits all events from L<Mojo::EventEmitter> and can emit
209 the following new ones.
210  
211 =head2 start
212  
213 $container->on(start => sub {
214 my ($process) = @_;
215 ...
216 });
217  
218 Emitted when the container starts.
219  
220 =head2 stop
221  
222 $container->on(stop => sub {
223 my ($container) = @_;
224 ...
225 });
226  
227 Emitted when the container stops.
228  
229 =head2 process_error
230  
231 $container->on(container_error => sub {
232 my ($e) = @_;
233 my @errors = @{$e};
234 });
235  
236 Emitted when the container produce errors.
237  
238 =head1 METHODS
239  
240 L<Mojo::IOLoop::ReadWriteProcess::Container> inherits all methods from L<Mojo::EventEmitter> and implements
241 the following new ones.
242  
243 =head2 start
244  
245 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
246 use Mojo::IOLoop::ReadWriteProcess qw(process);
247  
248 my $c = container( name=>"test", process => sub { print "Hello!" });
249 $c->start();
250  
251 Starts the container, it's main process is a L<Mojo::IOLoop::ReadWriteProcess>,
252 contained in the C<process()> attribute. On stop it will terminate every process included in the L<cgroups> attribute.
253  
254 =head2 is_running
255  
256 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
257 use Mojo::IOLoop::ReadWriteProcess qw(process);
258  
259 my $c = container( name=>"test", process => sub { print "Hello!" });
260 $c->is_running();
261  
262 Returns 1 if the container is running.
263  
264 =head2 stop
265  
266 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
267 use Mojo::IOLoop::ReadWriteProcess qw(process);
268  
269 my $c = container( name=>"test", process => sub { print "Hello!" })->start;
270 $c->stop();
271  
272 Stops the container and kill all the processes belonging to the cgroup.
273 It also registers all the unknown processes to the current L<Mojo::IOLoop::ReadWriteProcess::Session>.
274  
275 =head2 wait_stop
276  
277 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
278 use Mojo::IOLoop::ReadWriteProcess qw(process);
279  
280 my $c = container( name=>"test", process => sub { print "Hello!" })->start;
281 $c->wait_stop();
282  
283 Wait before stopping the container.
284  
285 =head2 wait
286  
287 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
288 use Mojo::IOLoop::ReadWriteProcess qw(process);
289  
290 my $c = container( name=>"test", process => sub { print "Hello!" })->start;
291 $c->wait();
292  
293 Wait the container to stop
294  
295 =head2 migrate_process
296  
297 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
298 use Mojo::IOLoop::ReadWriteProcess qw(process);
299  
300 my $c = container( name=>"test", process => sub { print "Hello!" })->start;
301 $c->migrate_process(42);
302  
303 Migrate the given process to the container cgroup.
304  
305 =head1 ATTRIBUTES
306  
307 L<Mojo::IOLoop::ReadWriteProcess::Container> inherits all attributes from L<Mojo::EventEmitter> and implements
308 the following new ones.
309  
310 =head2 name
311  
312 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
313 use Mojo::IOLoop::ReadWriteProcess qw(process);
314 use Mojo::IOLoop::ReadWriteProcess::CGroup qw(cgroupv1);
315 use Mojo::Collection 'c';
316  
317 my $container = container( name => "test", process => sub { print "Hello!" } );
318  
319 $container->session->on(register => sub { ... });
320 $container->start();
321  
322 Sets the container name. It creates in the indicated (or default) cgroups a sub-tree with the container name.
323  
324 This means that cgroups settings can be done also outside of the container object:
325  
326 use Mojo::IOLoop::ReadWriteProcess::CGroup qw(cgroupv1);
327 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
328  
329 my $container = container( name => "test", process => sub { print "Hello!" } );
330  
331 cgroupv1->from($continer->cgroups->first->_group)->pid->max(100);
332  
333 As cgroups are represented by path, you can set options directly from controllers objects that are pointing to the same cgroup slice.
334  
335 =head2 group
336  
337 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
338 use Mojo::IOLoop::ReadWriteProcess qw(process);
339 use Mojo::IOLoop::ReadWriteProcess::CGroup qw(cgroupv2);
340 use Mojo::Collection 'c';
341  
342 my $container = container( name => "bar", group => "foo", process => sub { print "Hello!" } );
343 my $container2 = container( name => "bar2", group => "foo", process => sub { print "Hello!" } );
344  
345 $container->start();
346 $container2->start();
347  
348 my $group_cgroup = cgroupv2->from($container2->cgroups->first->parent);
349  
350 $group_cgroup->pid->max(200);
351  
352 Sets the container group. If containers are sharing the same group they will inherit the same CGroup parent path,
353 in such way it is possible to create controllers pointing to it and set specific options for the whole group.
354  
355 =head2 pid_isolation
356  
357 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
358 use Mojo::IOLoop::ReadWriteProcess qw(process);
359 use Mojo::IOLoop::ReadWriteProcess::CGroup qw(cgroupv1);
360 use Mojo::Collection 'c';
361  
362 my $container = container( pid_isolation => 1, process => sub { print "Hello!" } );
363  
364 $container->session->on(register => sub { ... });
365 $container->start();
366  
367 If set, the process will see itself as PID 1. It needs CAP_SYS_ADMIN capabilities set on the executable (or run as root).
368  
369 =head2 pre_migrate
370  
371 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
372 use Mojo::IOLoop::ReadWriteProcess qw(process);
373  
374 my $container = container( pre_migrate => 1, process => sub { print "Hello!" } );
375  
376 $container->session->on(register => sub { ... });
377 $container->start();
378  
379 If set, the process will migrate itself into the cgroup.
380  
381 =head2 clean_cgroup
382  
383 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
384 use Mojo::IOLoop::ReadWriteProcess qw(process);
385  
386 my $container = container( clean_cgroup => 1, process => sub { print "Hello!" });
387  
388 $container->session->on(register => sub { ... });
389 $container->start();
390  
391 If set, attempts to destroy the cgroup after the process terminated its execution.
392  
393 =head2 subreaper
394  
395 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
396 use Mojo::IOLoop::ReadWriteProcess qw(process);
397  
398 my $c = container(subreaper => 1, name=>"test", process => sub { print "Hello!" });
399 $c->start();
400  
401 Enable subreaper mode inside the child process.
402  
403 =head2 process
404  
405 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
406 use Mojo::IOLoop::ReadWriteProcess qw(process);
407  
408 my $c = container(process => sub { print "Hello!" });
409 my $c = container(process => sub { print "Hello!" });
410  
411 $c->start();
412  
413 The process to run. It can be an anonymous function or a L<Mojo::IOLoop::ReadWriteProcess> object.
414  
415 =head2 namespace
416  
417 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
418 use Mojo::IOLoop::ReadWriteProcess qw(process);
419  
420 my $c = container(process => sub { print "Hello!" });
421 $c->namespace->unshare(0); # All
422 $c->start();
423  
424 Set/Return L<Mojo::IOLoop::ReadWriteProcess::Namespace> object. It's main use is to invoke syscalls.
425  
426 =head2 session
427  
428 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
429 use Mojo::IOLoop::ReadWriteProcess qw(process);
430  
431 my $c = container(process => process(sub { print "Hello!" }));
432 $c->session->on(register => sub { ... });
433 $c->start();
434  
435 Returns/Set the L<Mojo::IOLoop::ReadWriteProcess::Session> singleton object.
436  
437 =head2 unshare
438  
439 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
440 use Mojo::IOLoop::ReadWriteProcess qw(process);
441 use Mojo::IOLoop::ReadWriteProcess::Namespace qw( CLONE_NEWPID CLONE_NEWNS );
442  
443 my $c = container( unshare=> CLONE_NEWPID | CLONE_NEWNS, process => sub { print "Hello!" } );
444 $c->session->on(register => sub { ... });
445 $c->start();
446  
447 Returns/Set the unshare syscall options. See man unshare(2) for further documentation.
448  
449 =head2 cgroups
450  
451 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
452 use Mojo::IOLoop::ReadWriteProcess qw(process);
453 use Mojo::IOLoop::ReadWriteProcess::CGroup qw(cgroupv1);
454 use Mojo::Collection 'c';
455  
456 my $container = container(process => sub { print "Hello!" });
457 $container->cgroups( c(cgroupv1(controller => 'pids'), cgroupv1(controller => 'memory')) );
458  
459 $container->session->on(register => sub { ... });
460 $container->start();
461  
462 Returns/Set a L<Mojo::Collection> collection of CGroups where the process should belong to.
463 If used with a single CGroup, you don't need to pass the L<Mojo::Collection> object:
464  
465 use Mojo::IOLoop::ReadWriteProcess::Container qw(container);
466 use Mojo::IOLoop::ReadWriteProcess qw(process);
467 use Mojo::IOLoop::ReadWriteProcess::CGroup qw(cgroupv1);
468 use Mojo::Collection 'c';
469  
470 my $container = container(cgroups=> cgroupv1(controller => 'pids'), process => sub { print "Hello!" });
471  
472 $container->session->on(register => sub { ... });
473 $container->start();
474  
475 =head1 DEBUGGING
476  
477 You can set the MOJO_EVENTEMITTER_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.
478  
479 MOJO_EVENTEMITTER_DEBUG=1
480  
481 Also, you can set MOJO_PROCESS_DEBUG environment variable to get diagnostics about the process execution.
482  
483 MOJO_PROCESS_DEBUG=1
484  
485 =head1 LICENSE
486  
487 Copyright (C) Ettore Di Giacinto.
488  
489 This library is free software; you can redistribute it and/or modify
490 it under the same terms as Perl itself.
491  
492 =head1 AUTHOR
493  
494 Ettore Di Giacinto E<lt>edigiacinto@suse.comE<gt>
495  
496 =cut
497  
498 13 1;
« lib/Mojo/IOLoop/ReadWriteProcess/Shared/Lock.pm ↑ Summary builder/custom.pm »