NAME
Ubic::Service::SimpleDaemon - service module for daemonizing any binary
VERSION
version 1.60
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. Unless otherwise specified, 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 details. - group
-
Group under which the service will operate.
Value can be either scalar or arrayref.
Defaults to all groups of service's user.
- pidfile
-
Dir in local filesystem which will be used as a storage of daemon's info. If not defined, then it will be concatenated from simple-daemon pid dir and service's name. It will be created if necessary, assuming that its parent dir exists.
- 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.
- proxy_logs
-
Boolean flag. If enabled,
ubic-guardian
will replace daemon's stdout and stderr filehandles with pipes, proxy all data to the log files, and reopen them onSIGHUP
. - 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.
- term_timeout
-
Number of seconds to wait between sending SIGTERM and SIGKILL to the daemon on stopping.
Zero value means that guardian will send SIGKILL to the daemon immediately.
Default is 10 seconds.
- stop_timeout
-
Number of seconds to wait before raising exception that daemon can't be stopped.
This should always be greater than term_timeout, and defaults to 30 seconds (via Ubic::Daemon's defaults.)
- reload_signal
-
Send given signal to the daemon on
reload
command.Can take either integer value or signal name (i.e., HUP).
The signal will be sent both to the daemon, and to the guardian process. Guardian process will have proxy_logs feature enabled, so it'll reopen stdout, stderr and ubic_log as well.
- 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 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.
- auto_start
-
Autostart flag is off by default. See Ubic::Service
auto_start
method for details.
- pidfile()
-
Get pid filename. It will be concatenated from simple-daemon pid dir and service's name by default.
CUSTOM COMMANDS
All services using this class support two custom commands: sigusr1 and sigusr2. So, ubic sigusr1 your.service.name
will send SIGUSR1 to your daemon (and also send SIGHUP to ubic-guardian, which can result in reopening log files.)
SEE ALSO
Ubic::Daemon - module for daemonizing any binary.
AUTHOR
Vyacheslav Matyukhin <mmcleric@yandex-team.ru>
COPYRIGHT AND LICENSE
This software is copyright (c) 2016 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.