NAME
ControlFreak::Service - Object representation of a service.
SYNOPSIS
my $mc = ControlFreak::Service->new(
name => "memcached",
desc => "you should have this one...",
ignore_stderr => 1,
cmd => "/usr/bin/memcached",
);
my $fcgisock = $ctrl->socketmap->{fcgi};
my $web = ControlFreak::Service->new(
name => "fcgi",
desc => "I talk http",
tie_stdin_to => $fcgisock,
cmd => "/usr/bin/plackup -a MyApp -s FCGI",
);
$web->up;
$web->start;
$web->stop;
## A service can mutate
$web->add_tag('prod');
## all set_* accessors are callable from Commands
$web->set_cmd("/usr/bin/plackup -a MyNewApp");
$web->set_ignore_stderr(0);
# ...
$web->running_cmd;
# make the service a proxied service
$web->assign_proxy($proxy);
DESCRIPTION
This allows manipulation of a service and its state.
METHODS
new(%param)
constructor.
is_fail
Returns true if the state is 'failed'
is_backoff
Returns true if the state is 'backoff'
is_fatal
Returns true if the state is 'fatal'
is_running
Returns true if the state is 'runnnig'
is_starting
Returns true if the state is 'starting'
is_stopping
Returns true if the state is 'stopping'
is_stopped
Returns true is service is stopped
is_up
Returns true is service is up
is_down
Returns true unless service is up
fail_reason
Returns a string with the reason of the failure, or undef.
stop(%param)
Initiates service shutdown.
params are:
ok_cb
A callback called when shutdown has been initiated successfuly. Note that it doesn't mean that the service is successfuly stopped, just that nothing prevented the shutdown sequence.
Optional.
err_cb
Called with a text reason when the stop request couldn't be initiated properly.
Optional.
start(%param)
Initiates service startup and returns immediately.
params are:
ok_cb
A callback called when startup has been initiated successfuly. Note that it doesn't mean that the service is successfuly running, just that nothing prevented the startup.
Optional.
err_cb
A callback called when an error occured during startup (For instance if the service is already started), the reason for the failure is passed as the first argument of the callback if is known.
Optional.
has_stopped($reason)
Called when a third party knows that a service has stopped. It marks the service has stopped, no matter what the current status is.
kill
Kills the service. This is the brutal way of getting rid of service's process it will result in the program being uncleanly exited which will be reported later in the status of the service. This command is used when a service hasn't terminated after stopwait_secs
.
up(%param)
XXX up the service (do nothing if already up)
up(%param)
XXX down the service (do nothing if already down)
restart(%param)
Restarts the service. i.e. stops it (if up), then starts it.
proxy_as_text
A descriptive text representing service's proxy.
status_as_text
Returns a text describing the service state. It consists in tab separated list of fields:
name
state
pid
start_time
stop_time
proxy, prefixed with '!' if down
fail_reason
running_cmd
desc_as_text
Returns a text describing the service and how to access it. It consists in tab separated list of fields:
name
tags
desc
proxy
cmd
assign_proxy($proxy)
assign_pid($pid)
tags
Returns a hashref of tags
tags_as_text
Returns tag as a descriptive text.
tag_list
Returns a reference to a list of tags
add_env($key => $value)
Adds an environment key, value pair to the service
clear_env()
Resets service environment to empty.
setup_environment
Executed in the child before exec, to take service's configured env
and populate %ENV
with it.
AUTHOR
Yann Kerherve <yannk@cpan.org>
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.