line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Command::generate::upstart; |
2
|
1
|
|
|
1
|
|
35615
|
use Mojo::Base 'Mojolicious::Command'; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use File::Spec; |
5
|
|
|
|
|
|
|
use Getopt::Long 'GetOptions'; |
6
|
|
|
|
|
|
|
use Mojo::ByteStream 'b'; |
7
|
|
|
|
|
|
|
use Mojo::Util 'dumper'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has description => "Generate application upstart job\n"; |
10
|
|
|
|
|
|
|
has usage => <
|
11
|
|
|
|
|
|
|
usage: $0 generate upstart [OPTIONS] |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
These options are available: |
14
|
|
|
|
|
|
|
--output Set folder to output upstart job (default: .) |
15
|
|
|
|
|
|
|
--deploy Deploy upstart into /etc/init |
16
|
|
|
|
|
|
|
--name Ovewrite name which is used for upstart job |
17
|
|
|
|
|
|
|
EOF |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Mojolicious::Command::generate::upstart - upstart job generator command |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSYS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$ ./mojo_app.pl generate help upstart |
26
|
|
|
|
|
|
|
usage: ./mojo_app.pl generate upstart [OPTIONS] |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
These options are available: |
29
|
|
|
|
|
|
|
--output Set folder to output upstart job (default: .) |
30
|
|
|
|
|
|
|
--deploy Deploy upstart into /etc/init |
31
|
|
|
|
|
|
|
--name Ovewrite name which is used for upstart job |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub run { |
38
|
|
|
|
|
|
|
my ($self, @args) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#$self->app->plugin('DefaultHelpers'); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
GetOptions( |
43
|
|
|
|
|
|
|
'output=s' => \my $output, |
44
|
|
|
|
|
|
|
'deploy' => \my $deploy, |
45
|
|
|
|
|
|
|
'name=s' => \my $name, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if ( !$name ) { |
49
|
|
|
|
|
|
|
my (undef, undef, $filename) = File::Spec->splitpath($0); |
50
|
|
|
|
|
|
|
($name) = $filename =~ m/^(.*?)(?:\.pl)?$/; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$self->app->moniker($name); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if ( !( $deploy || $output ) ) { |
56
|
|
|
|
|
|
|
$output = '.'; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
if ( $deploy && $output ) { |
59
|
|
|
|
|
|
|
die qq{Either --deploy or --output should be specified but not both\n}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
if ( $deploy && !$self->user_is_root ) { |
62
|
|
|
|
|
|
|
$output = '.'; |
63
|
|
|
|
|
|
|
$deploy = 0; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $file = $deploy |
67
|
|
|
|
|
|
|
? File::Spec->join('', 'etc', 'init', $self->app->moniker.'.conf') |
68
|
|
|
|
|
|
|
: File::Spec->join($output, 'etc_init_'.$self->app->moniker.'.conf'); |
69
|
|
|
|
|
|
|
$self->render_to_file('upstart', $file, $self->app); |
70
|
|
|
|
|
|
|
$self->chmod_file($file, 0755); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# config file |
73
|
|
|
|
|
|
|
$file = $deploy |
74
|
|
|
|
|
|
|
? File::Spec->join('', 'etc', 'default', $self->app->moniker) |
75
|
|
|
|
|
|
|
: File::Spec->join($output, 'etc_default_'.$self->app->moniker); |
76
|
|
|
|
|
|
|
$self->render_to_file('config', $file, $self->app); |
77
|
|
|
|
|
|
|
$self->chmod_file($file, 0644); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub user_is_root { $> == 0 || $< == 0 } |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__DATA__ |