Ubic-Service-MongoDB
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Ubic/Service/MongoDB.pm view on Meta::CPAN
package Ubic::Service::MongoDB;
$Ubic::Service::MongoDB::VERSION = '0.02';
use strict;
use warnings;
# ABSTRACT: running MongoDB as Ubic service
use parent qw(Ubic::Service::Common);
use File::Copy qw(move);
use File::Spec::Functions qw(catfile);
use MongoDB 0.502; # MonboDB::MongoClient instead of MongoDB::Connection
use Params::Validate qw(:all);
use Ubic::Daemon qw(:all);
use Ubic::Result qw(:all);
sub new {
my $class = shift;
my $opt_str = { type => SCALAR, optional => 1 };
my $params = validate(@_, {
config => { type => HASHREF },
daemon => { type => SCALAR,
regex => qr/^mongo(d|s)$/,
default => 'mongod' },
status => { type => CODEREF, optional => 1 },
user => $opt_str,
ubic_log => $opt_str,
stdout => $opt_str,
stderr => $opt_str,
pidfile => $opt_str,
gen_cfg => $opt_str,
});
my $self = $params;
bless $self, $class;
$self->{port} = $self->{config}->{port} || 27017;
if (!$params->{pidfile}) {
$params->{pidfile} = "/tmp/$self->{daemon}." . $self->{port} . '.pid';
}
if (!$params->{gen_cfg}) {
$params->{gen_cfg} = "/tmp/$self->{daemon}." . $self->{port} . '.conf';
}
return bless $params => $class;
}
sub bin {
my $self = shift;
my @cmd = ($self->{daemon}, '--config', $self->{gen_cfg});
return \@cmd;
}
sub create_cfg_file {
my $self = shift;
my $fname = $self->{gen_cfg};
my $tmp_fname = $fname . ".tmp";
open(my $tmp_fh, '>', $tmp_fname) or die "Can't open file [$tmp_fname]: $!";
foreach my $k (keys %{$self->{config}}) {
my $v = $self->{config}->{$k};
print $tmp_fh "$k=$v\n";
}
close($tmp_fh) or die "Can't close file [$tmp_fname]: $!";
move($tmp_fname, $fname) or die "Can't mova file [${tmp_fname}] to [$fname]: $!";
}
sub pidfile {
my $self = shift;
return $self->{pidfile};
}
sub user {
my $self = shift;
return $self->{user} if defined $self->{user};
return $self->SUPER::user;
}
sub timeout_options {
return {
start => { trials => 15, step => 0.1 },
stop => { trials => 15, step => 0.1 }
};
}
sub start_impl {
my $self = shift;
$self->create_cfg_file;
my $daemon_opts = {
bin => $self->bin,
term_timeout => 5
};
for (qw/ubic_log stdout stderr pidfile/) {
$daemon_opts->{$_} = $self->{$_} if defined $self->{$_};
}
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.533 second using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )