Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 # == Class: adblockplus::web::mimeo | 1 # == Class: adblockplus::web::mimeo |
2 # | 2 # |
3 # A [mimeograph](https://en.wikipedia.org/wiki/Mimeograph) (also known as stenci l duplicator) is a low-cost duplicating | 3 # Class adblockplus::web::mimeo registers the information received in a |
4 # machine. Mimeo is used here since it is the abbreviation and it sounds better. | 4 # http/s petition with an specified format in an specific output. |
5 # | 5 # |
6 # The pourpose of this class is to log the information received in a http/s | |
7 # petition with an specified format. | |
8 # === Parameters: | 6 # === Parameters: |
9 # | 7 # |
10 # [*format*] | 8 # [*format*] |
11 # A systemd escaped string containing the desired format for logging. | 9 # A string containing the desired format for logging. |
12 # | 10 # |
13 # '$remote_addr - - [$time_local] "$request" $status $bytes_sent "$http_refere r"' | 11 # '$remote_addr - - [$time_local] "$request" $status $bytes_sent "$http_refere r"' |
14 # | |
15 # This is an example of how the format would look like in the log file. | |
16 # | |
17 # \x24remote_addr\x20\x2d\x20\x2d\x20\x5b\x24time_local\x5d\x20\x22\x24request \x22\x20\x24status\x20\x24bytes_sent\x20\x22\x24http_referer\x22 | |
18 # | |
19 # And this is how it looks escaped, for escaping is necessary to use | |
20 # `systemd-escape` command, since this parameter is passed to a systemd | |
21 # unit file. | |
22 # | 12 # |
23 # [*port*] | 13 # [*port*] |
24 # An integer to setup the port where the script will be listening, defaults | 14 # An integer to setup the port where the script will be listening, defaults |
25 # to 8000. | 15 # to 8000. |
26 # | 16 # |
27 # [*response*] | 17 # [*response*] |
28 # A systemd escaped string (like format parameter) representing the response | 18 # A string (like format parameter) representing the response sent to the |
29 # sent to the client. | 19 # client. |
30 # | 20 # |
31 # [*log_file*] | |
32 # A string containg the path to the file where the logs will be written. | |
33 class adblockplus::web::mimeo ( | 21 class adblockplus::web::mimeo ( |
34 $format = '', | 22 $format = '', |
35 $port = 8000, | 23 $port = 8000, |
36 $response = '', | 24 $response = '', |
37 $log_file = '/var/log/mimeo.log', | |
38 ){ | 25 ){ |
26 include adblockplus | |
39 | 27 |
40 ensure_packages(['python3']) | 28 ensure_packages(['python3']) |
41 | 29 |
42 file {"/opt/mimeo": | 30 realize(File['/var/adblockplus']) |
31 | |
32 file {'/var/adblockplus/mimeo': | |
43 ensure => 'directory', | 33 ensure => 'directory', |
34 mode => '0755', | |
44 owner => 'root', | 35 owner => 'root', |
45 group => 'root', | 36 require => File['/var/adblockplus'], |
46 } | 37 } |
47 | 38 |
48 file {"/opt/mimeo/mimeo.py": | 39 file {'/usr/local/bin/mimeo.py': |
49 ensure => 'present', | 40 ensure => 'present', |
50 owner => 'root', | 41 owner => 'root', |
51 group => 'root', | 42 group => 'root', |
52 mode => 0644, | 43 mode => 0755, |
53 content => file('adblockplus/mimeo.py'), | 44 source => 'puppet:///modules/adblockplus/mimeo.py', |
54 require => File["/opt/mimeo"], | 45 require => Package['python3'], |
55 } | 46 } |
56 | 47 |
57 file {"/etc/systemd/system/mimeo.service": | 48 file {'/etc/systemd/system/mimeo.service': |
58 ensure => 'present', | 49 ensure => 'present', |
59 owner => 'root', | 50 owner => 'root', |
60 group => 'root', | 51 group => 'root', |
61 mode => 0644, | 52 mode => 0644, |
62 content => template('adblockplus/mimeo.service.erb'), | 53 content => template('adblockplus/mimeo.service.erb'), |
54 require => File['/usr/local/bin/mimeo.py'], | |
63 } | 55 } |
64 | 56 |
65 Exec{ | 57 Exec{ |
66 path => ['/usr/bin', '/bin'], | 58 path => ['/usr/bin', '/bin'], |
67 } | 59 } |
68 | 60 |
69 exec {"enable-service-mimeo": | 61 exec {'enable-service-mimeo': |
70 command => 'systemctl enable mimeo.service', | 62 command => 'systemctl enable mimeo.service', |
71 user => 'root', | 63 user => 'root', |
72 onlyif => 'systemctl status mimeo.service | grep disabled', | 64 unless => 'systemctl is-enabled mimeo.service', |
mathias
2017/08/08 07:51:46
Why not use `systemctl is-enabled` for this test?
f.lopez
2017/08/09 19:50:48
Done.
| |
73 require => File["/etc/systemd/system/mimeo.service"], | 65 require => File['/etc/systemd/system/mimeo.service'], |
74 } | 66 } |
75 | 67 |
76 service {"mimeo.service": | 68 service {'mimeo': |
77 ensure => 'running', | 69 ensure => 'running', |
78 hasrestart => false, | 70 hasrestart => false, |
79 provider => 'systemd', | 71 provider => 'systemd', |
80 require => [ | 72 require => Exec['enable-service-mimeo'], |
81 Exec["enable-service-mimeo"], | 73 subscribe => File['/usr/local/bin/mimeo.py'], |
82 Package["python3"], | |
83 ], | |
84 } | 74 } |
85 | 75 |
86 exec {"reload-daemons": | 76 exec {'reload-mimeo-daemon': |
mathias
2017/08/08 07:51:46
This is a way too global operation to be placed in
f.lopez
2017/08/09 19:50:48
Done.
| |
77 notify => Service['mimeo'], | |
87 command => 'systemctl daemon-reload', | 78 command => 'systemctl daemon-reload', |
88 subscribe => File["/etc/systemd/system/mimeo.service"], | 79 subscribe => File['/etc/systemd/system/mimeo.service'], |
89 refreshonly => true, | 80 refreshonly => true, |
90 } | 81 } |
91 } | 82 } |
92 | 83 |
LEFT | RIGHT |