-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBase.pm
110 lines (88 loc) · 2.27 KB
/
Base.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#
# vim: set ts=2 sw=2 tw=0:
# vim: set expandtab:
package Application::Base;
use Moose;
use Rex::Commands::Run;
use Rex::Commands::Service;
use Data::Dumper;
use Application::Download;
has project => ( is => 'ro' );
# control if the configuration should be placed before or after the
# dapplication deployment.
has post_configuration => (
is => 'ro',
default => sub { 0 },
);
# control if the db migration should be done after deployment.
has post_migration => (
is => 'ro',
default => sub { 0 },
);
has defaults => (
is => 'ro',
isa => 'HashRef',
lazy => 1,
default => sub {
my $self = shift;
return {
document_root_directory => "app",
deploy_stash_directory => "deploy",
deploy_configuration_directory => "conf",
data_directory => "shared",
manager_path => "manager",
instance_prefix => ( $ENV{"instance_prefix"} || "i" ),
},
;
},
);
has need_start_before_deploy => (
is => 'ro',
default => sub { 1 },
);
sub download {
my ( $self, $url ) = @_;
if ( -f $url ) { return $url; }
return Application::Download::get($url);
}
sub get_inactive {
my ($self) = @_;
my ($inactive) = grep { !$_->is_active } $self->get_instances;
return $inactive;
}
sub get_active {
my ($self) = @_;
my ($active) = grep { $_->is_active } $self->get_instances;
return $active;
}
sub get_deployable_instance {
my ($self) = @_;
my @instances = $self->get_instances;
my $instance = $self->get_inactive;
if ( !$instance && scalar(@instances) == 1 ) {
$instance = $self->get_active;
}
if ( !$instance ) {
die "Can't find any instances.";
}
return $instance;
}
sub get_instances {
die "Must be overwritten by upper class.";
}
sub switch {
my ($self) = @_;
my $inactive = $self->get_deployable_instance; # this is the inactive one
my $active = $self->get_active;
if ( $inactive == $active ) {
Rex::Logger::info("Instance already active.");
return;
}
sudo sub {
$inactive->activate;
if ($active) {
$active->deactivate;
}
};
}
1;