line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convos::Control; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Convos::Control - Base class for init scripts |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
L is a base class for L |
10
|
|
|
|
|
|
|
and L. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
331
|
use Mojo::Base 'Daemon::Control'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
15
|
|
|
|
|
|
|
use File::Spec; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 directory |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Defaults to L. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 init_config |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
File to source environment variables for init script. Default to |
26
|
|
|
|
|
|
|
"/etc/default/convos". |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has directory => sub { |
31
|
|
|
|
|
|
|
local $ENV{MOJO_LOG_LEVEL} = 'warn'; |
32
|
|
|
|
|
|
|
require Convos; |
33
|
|
|
|
|
|
|
return Convos->new->home; |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has init_config => sub { $ENV{CONVOS_INIT_CONFIG_FILE} || '/etc/default/convos' }; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 do_env |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
For internal usage and debug purpose only. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Will print environment to screen. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub do_env { |
49
|
|
|
|
|
|
|
my $self = shift; |
50
|
|
|
|
|
|
|
print "$_=$ENV{$_}\n" for sort keys %ENV; |
51
|
|
|
|
|
|
|
return 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 do_help |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Will print help to screen. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub do_help { |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
my $command = ref($self) =~ /frontend/i ? 'frontend' : 'backend'; |
63
|
|
|
|
|
|
|
print "Usage: convos $command {start|stop|reload|restart|foreground|status|get_init_file}\n"; |
64
|
|
|
|
|
|
|
return 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 run_template |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Will inject C before sourcing of L. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub run_template { |
74
|
|
|
|
|
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
my $out = $self->SUPER::run_template(@_); |
76
|
|
|
|
|
|
|
my $init_config = $self->init_config; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
if ($out =~ /$init_config/) { |
79
|
|
|
|
|
|
|
$ENV{MOJO_MODE} or die "MOJO_MODE need to be set."; |
80
|
|
|
|
|
|
|
$out = "set -a;\nMOJO_MODE='$ENV{MOJO_MODE}';\n$out"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return $out; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Copyright (C) 2014, Jan Henning Thorsen |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
91
|
|
|
|
|
|
|
the terms of the Artistic License version 2.0. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Jan Henning Thorsen - C |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |