NAME
ControlFreak::Proxy - Delegate some control to an intermediary process.
DESCRIPTION
There are some cases where you want some services managed in a special way, and it makes no sense to implement this in ControlFreak
itself.
Indeed, one design trait of ControlFreak is its absolute simplicity, we don't want to clutter it with features that are only rarely used or that could make the controller unstable.
One example of that is Memory Sharing. If you have 20 application processes running on one machine all having the same code running, there is a memory benefit into making sure the app is loaded in the parent process of all these applications. Indeed, it would allow all children to initially share parent code and thus potentially reduce the memory footprint of the application by quite a while, maybe. But, it's out of question for the controller
to load that code in its own memory. A better solution is to use a ControlFreak::Proxy
separate process that will:
load the application code once and for all
take commands from the main
controller
(over pipes)fork children when instructed, that exec some user defined commands
SYNOPSIS
$proxy = ControlFreak::Proxy->new(
ctrl => $ctrl,
cmd => '/usr/bin/cfk-share-mem-proxy.pl --preload Some::Module',
);
$proxy->add_service($svc);
$proxy->destroy_service($svc);
$proxy->run;
$proxy->start_service($svc);
$proxy->stop_service($svc);
@list = $proxy->services;
$proxy->shutdown;
$proxy->is_running;
METHODS
new(%param)
status_as_text
Returns the status of the proxy, including its eventual pid in one line of text, where the following fields are seperated with tabs:
name
status ('up' or 'down')
pid, if proxy is up
services
Returns a list of ControlFreak::Service objects related to the proxy.
add_service($svc)
Declares a service under the control of the proxy.
start_service
Given a ControlFreak::Service, check that it is effectively under the control of a ControlFreak::Proxy object and contact the later to instruct it to start the service on our behalf.
add_env($key => $value)
Adds an environment key, value pair to the proxy
clear_env()
Resets proxy environment to empty.
run
Runs the proxy command.
shutdown
Quits the proxy (and consequently stops all related services).
has_stopped
Called when the proxy has exited. It performs a number of cleaning tasks.