The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Ubic::Service::SimpleDaemon - service module for daemonizing any binary

VERSION

version 1.44

SYNOPSIS

    use Ubic::Service::SimpleDaemon;
    my $service = Ubic::Service::SimpleDaemon->new(
        bin => "sleep 1000",
        stdout => "/var/log/sleep.log",
        stderr => "/var/log/sleep.err.log",
        ubic_log => "/var/log/sleep.ubic.log",
        user => "nobody",
    );

DESCRIPTION

Use this class to turn any binary into ubic service.

This module uses Ubic::Daemon module for process daemonization. All pidfiles are stored in ubic data dir, with their names based on service names.

METHODS

new($params)

Constructor.

Parameters:

bin

Daemon binary.

Can be a plain string (i.e., sleep 10000), or arrayref with separate arguments (i.e., ['sleep', '1000']).

This is the only mandatory parameter, everything else is optional.

user

User under which the service will operate.

Default user depends on the configuration chosen at ubic-admin setup stage. See Ubic::Settings for more defails.

group

Group under which the service will operate.

Value can be either scalar or arrayref.

Defaults to all groups of service's user.

stdout

File into which daemon's stdout will be redirected. None by default.

stderr

File into which daemon's stderr will be redirected. None by default.

ubic_log

Optional filename of ubic log. Log will contain some technical information about running daemon.

None by default.

cwd

Change working directory before starting a daemon.

env

Modify environment before starting a daemon.

Must be a plain hashref if specified.

ulimit

Set resource limits before starting a daemon.

Must be a plain hashref with resource names as keys if specified. For example: ulimit => { RLIMIT_NOFILE => 100 }. Pass -1 as a value to make the resource unlimited.

These limits won't affect anything outside of this service code.

If your service's user is root and daemon_user is something else, you can not just lower limits but raise them as well.

BSD::Resource must be installed to use this feature.

reload_signal

Send given signal to the daemon on reload command.

Can take either integer value or signal name (i.e., HUP).

Note that this signal won't reopen stdout, stderr or ubic_log logs. Sorry.

daemon_user
daemon_group

Change credentials to the given user and group before execing into daemon.

The difference between these options and user/group options is that for daemon_* options, credentials will be set just before before starting the actual daemon. All other service operations will be done using default user. Refer to "Permissions and security" in Ubic::Manual::Overview for the further explanations.

name

Service's name.

Name will usually be set by upper-level multiservice. Don't set it unless you know what you're doing.

pidfile()

Get pid filename. It will be concatenated from simple-daemon pid dir and service's name.

SEE ALSO

Ubic::Daemon - module for daemonizing any binary.

AUTHOR

Vyacheslav Matyukhin <mmcleric@yandex-team.ru>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Yandex LLC.

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