Ubic - polymorphic service manager
Configure ubic: $ ubic-admin setup Write the service config: $ cat >/etc/ubic/service/foo.ini [options] bin = /usr/bin/foo.pl Start your service: $ ubic start foo Enjoy your daemonized, monitored service.
This module is a perl frontend to ubic services.
It is a singleton OOP class. All of its methods should be invoked as class methods:
Ubic->start('foo'); Ubic->stop('foo'); my $status = Ubic->status('foo');
Ubic is a polymorphic service manager.
if you are looking for a general introduction to Ubic, see Ubic::Manual::Intro;
if you want to use ubic from the command line, see ubic;
if you want to manage ubic services from the perl scripts, read this POD;
if you want to write your own service, see Ubic::Service and other
All methods in this package can be invoked as class methods, but sometimes you may need to override some status dirs. In this case you should construct your own
Note that you can't create several instances in one process and have them work independently. So, this constructor is actually just a weird way to override service_dir and data_dir.
Constructor options (all of them are optional):
See LSB documentation for init-script method specifications.
Following methods are trying to conform, except that all dashes in method names are replaced with underscores.
These methods return the result objects, i.e., instances of the
Start the service.
Stop the service.
Restart the service; start it if it's not running.
Restart the service if it is enabled.
Reload the service.
This method will do reloading if the service implements
reload(); it will throw an exception otherwise.
Reload the service if reloading is implemented, otherwise restart it.
Does nothing if service is disabled.
Get the service status.
Enable the service.
Enabled service means that service should be running.
Watchdog will periodically check its status, attempt to restart it and mark it as broken if it won't succeed.
Check whether the service is enabled.
Returns true or false.
Disable the service.
Disabled service means that the service is ignored by ubic.
Its state will no longer be checked by the watchdog, and
ubic status will report that the service is down.
Get cached status of the service.
Unlike other methods, it can be invoked by any user.
Execute the custom command
$command for the given service.
Get service object by name.
Check whether the service named
Get the list of all services.
Get the list of all service names.
Get the root multiservice object.
Root service doesn't have a name and returns all top-level services with
services() method. You can use it to traverse the whole service tree.
Get the list of autocompletion variants for a given service prefix.
Write the new status into the service's status file.
Get the data dir.
Set the data dir, creating it if necessary.
Data dir is a directory with service statuses and locks. (See
Ubic::Settings for more details on how it's chosen).
This setting will be propagated into subprocesses using environment, so the following code works:
Ubic->set_data_dir('tfiles/ubic'); Ubic->set_service_dir('etc/ubic/service'); system('ubic start some_service'); system('ubic stop some_service');
Deprecated. This method got renamed to
Set default user for all services.
This is a simple proxy for
Get the ubic services dir.
Set the ubic services dir.
You shouldn't call these from a code which doesn't belong to core Ubic distribution.
These methods can be changed or removed without further notice.
Get the status file name by a service's name.
Get the status persistent object by a service's name.
It's a bad idea to call this from any other class than
Ubic, but if you'll ever want to do this, at least don't forget to create
Get the readonly, nonlocked status persistent object (see Ubic::Persistent) by a service's name.
Get an access guard (Ubic::AccessGuard object) for the given service.
Acquire lock object for given service.
You can lock one object twice from the same process, but not from different processes.
Run any code and wrap any result or exception into a result object.
$cmd method from the service named
$name and wrap any result or exception in a result object.
$callback in a subprocess and return its return value.
Interaction happens through a temporary file in
Andrei Mishchenko <firstname.lastname@example.org>
Yury Zavarin <email@example.com>
Christian Walde <firstname.lastname@example.org>
Ivan Bessarabov <email@example.com>
Most Ubic-related links are collected on github wiki: http://github.com/berekuk/Ubic/wiki.
Daemon::Control lets you write init scripts in perl.
Our IRC channel is irc://irc.perl.org#ubic.
There's also a mailing list at firstname.lastname@example.org. Send an empty message to email@example.com to subscribe.
Vyacheslav Matyukhin <firstname.lastname@example.org>
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.