NAME

Myriad::Bootstrap - dæmon functionality and hot-reload for Myriad

DESCRIPTION

Controller process for managing an application.

Provides a minimal parent process which starts up a child process for running the real application code. A pipe is maintained between parent and child for exchanging status information, with a secondary UNIX domain socket for filedescriptor handover.

The parent process loads only two additional modules - strict and warnings - with the rest of the app-specific modules being loaded in the child. This is enforced: any other modules found in %INC will cause the process to exit immediately.

Signals:

  • HUP - Request to recycle all child processes

  • TERM - Shut down all child processes gracefully

  • KILL - Immediate shutdown for all child processes

The purpose of this class is to support development usage: it provides a minimal base set of code that can load up the real modules in separate forks, and tear them down again when dependencies or local files change.

We avoid even the standard CPAN modules because one of the changes we're watching for is cpanfile content changing, if there's a new module or updated version we want to be very sure that it's properly loaded.

One thing we explicitly don't try to do is handle Perl version or executable changing from underneath us - so this is very much a fork-and-call approach, rather than fork-and-exec.

METHODS - Class

allow_modules

Add modules to the whitelist.

Takes a list of module names in the same format as %INC keys.

Don't ever use this.

open_pipe

use socketpair to establish communication between parent/child later.

make_pipe_noneblocking

Takes a pipe and makes it nonblocking by applying O_NONBLOCK

boot

Given a target coderef or classname, prepares the fork and communication pipe, then starts the code.

AUTHOR

Deriv Group Services Ltd. DERIV@cpan.org

LICENSE

Copyright Deriv Group Services Ltd 2020-2022. Licensed under the same terms as Perl itself.