-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__module__.pm
134 lines (115 loc) · 4.08 KB
/
__module__.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#
# (c) 2016 Jan Gehring
#
package Nginx;
use strict;
use warnings;
use Rex -minimal;
use Rex::Resource::Common;
use Rex::Commands::Pkg;
use Rex::Commands::Service;
use Rex::Commands::File;
use Rex::Helper::Rexfile::ParamLookup;
eval {
# For Rex > 1
use Rex::Commands::Template;
use Rex::Commands::Task;
};
task "setup", sub {
my $ensure = param_lookup "ensure", "latest";
my $conf_ensure = param_lookup "conf_ensure",
( $ensure ne "absent" ? "present" : "absent" );
my $service_ensure = param_lookup "service_ensure", "running";
my $nginx_conf = param_lookup "nginx_conf", "/etc/nginx/nginx.conf";
my $nginx_conf_template = param_lookup "nginx_conf_template",
"templates/nginx/nginx.conf.tpl";
my $mime_type_conf = param_lookup "mime_type_conf", "/etc/nginx/mime.types";
my $mime_type_conf_template = param_lookup "mime_type_conf_template",
"templates/nginx/mime.types.tpl";
my $user = param_lookup "user", "nginx";
my $worker_processes = param_lookup "worker_processes", 1;
my $error_log_file = param_lookup "error_log_file",
"/var/log/nginx/error.log";
my $error_log_level = param_lookup "error_log_level", "warn";
my $pid_file = param_lookup "pid_file", "/var/run/nginx.pid";
my $worker_connections = param_lookup "worker_connections", 1024;
my $mime_type_file = param_lookup "mime_type_file", "/etc/nginx/mime.types";
my $default_type = param_lookup "default_type", "application/octet-stream";
my $log_format_main = param_lookup "log_format_main",
'$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
my $access_log = param_lookup "access_log", "/var/log/nginx/access.log";
my $sendfile = param_lookup "sendfile", "on";
my $keepalive_timeout = param_lookup "keepalive_timeout", 65;
my $gzip = param_lookup "gzip", "on";
my $http_options = param_lookup "http_options", [];
my $http_include_files = param_lookup "http_include_files",
["/etc/nginx/conf.d/*.conf"];
my $events_options = param_lookup "events_options", [];
my $main_options = param_lookup "main_options", [];
pkg "nginx",
ensure => $ensure,
on_change => sub { service nginx => "restart"; };
file $nginx_conf,
ensure => $conf_ensure,
content => template($nginx_conf_template),
owner => 'root',
group => 'root',
mode => '0644',
on_change => sub {
if ( $ensure ne "absent" ) {
service nginx => "reload";
}
};
file $mime_type_conf,
ensure => $conf_ensure,
content => template($mime_type_conf_template),
owner => 'root',
group => 'root',
mode => '0644',
on_change => sub {
if ( $ensure ne "absent" ) {
service nginx => "reload";
}
};
service "nginx", ensure => $service_ensure
if ( $ensure ne "absent" );
};
resource "vhost", sub {
my $name = resource_name;
my $ensure = param_lookup "ensure", "latest";
my $conf_dir = param_lookup "configuration_dir", "/etc/nginx/conf.d";
my $on_change = param_lookup "on_change", sub { service nginx => "reload"; };
my $listen = param_lookup "listen", 80;
my $server_name = param_lookup "server_name", $name;
my $access_log = param_lookup "access_log", "/var/log/nginx/$name.access.log";
my $access_log_format = param_lookup "access_log_format", "main";
my $locations = param_lookup "locations",
{
'/' => {
root => '/usr/share/nginx/html',
index => 'index.html index.htm',
},
'~ /\.ht' => {
deny => 'all',
},
};
my $error_pages = param_lookup "error_pages",
{
404 => '/404.html',
'500 502 503 504' => '/50x.html',
};
my $conf = param_lookup "configuration",
template("templates/nginx/vhost.tpl");
file "$conf_dir",
ensure => "directory",
owner => 'root',
group => 'root',
mode => '0755';
file "$conf_dir/$name.conf",
content => $conf,
owner => 'root',
group => 'root',
mode => '0644',
on_change => $on_change;
};
1;