Puppet Class: elasticsearch

Defined in:
puppet/modules/elasticsearch/manifests/init.pp

Overview

Class: Elasticsearch

Elasticsearch is a powerful open source search and analytics engine, much like Solr, but with a more user-friendly inteface.



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
# File 'puppet/modules/elasticsearch/manifests/init.pp', line 6

class elasticsearch {
    require ::elasticsearch::repository

    require_package('openjdk-8-jre-headless')

    package { 'elasticsearch':
        ensure  => latest,
        name    => 'elasticsearch-oss',
        require => File['/etc/default/elasticsearch'],
    }

    # Install a customized elasticsearch.yml
    file { '/etc/elasticsearch/elasticsearch.yml':
        ensure  => present,
        source  => 'puppet:///modules/elasticsearch/elasticsearch.yml',
        owner   => 'root',
        group   => 'elasticsearch',
        mode    => '0444',
        require => Package['elasticsearch'],
    }

    # This is needed when upgrading from 2.x to 5.x, the directory
    # ends up owned by root and elasticsearch refuses to start
    file { '/var/run/elasticsearch':
        ensure  => directory,
        owner   => 'elasticsearch',
        group   => 'elasticsearch',
        mode    => '0755',
        require => Package['elasticsearch'],
    }

    service { 'elasticsearch':
        ensure  => running,
        enable  => true,
        require => [
            Package['elasticsearch'],
            Package['openjdk-8-jre-headless'],
        ]
    }

    exec { 'wait-for-elasticsearch':
        require => Service['elasticsearch'],
        command => '/usr/bin/wget --tries 20 --retry-connrefused http://127.0.0.1:9200/ -O - >/dev/null',
    }

    file { '/etc/default/elasticsearch':
        source => 'puppet:///modules/elasticsearch/defaults',
        notify => Service['elasticsearch'],
    }

    file { '/etc/elasticsearch/jvm.options':
        source  => 'puppet:///modules/elasticsearch/jvm.options',
        require => Package['elasticsearch'],
        notify  => Service['elasticsearch'],
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
    }

    file { '/etc/elasticsearch/log4j2.properties':
        source  => 'puppet:///modules/elasticsearch/log4j2.properties',
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        require => Package['elasticsearch'],
    }

    file { '/etc/logrotate.d/elasticsearch':
        source => 'puppet:///modules/elasticsearch/logrotate',
        owner  => 'root',
        group  => 'root',
        mode   => '0444',
    }

    # The logrotate above works on size, rather than daily.  For this to work
    # reasonably well logrotate needs to run multiple times per day
    file { '/etc/cron.hourly':
        ensure => 'directory',
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }
    file { '/etc/cron.hourly/logrotate':
        ensure  => 'link',
        target  => '/etc/cron.daily/logrotate',
        require => File['/etc/cron.hourly'],
    }
}