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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'manifests/init.pp', line 14
class solr (
String $user,
Boolean $manage_user,
String $group,
Boolean $manage_group,
String $install_dir,
String $service_name,
String $version,
String $archive_url,
String $archive_name,
String $checksum_type,
Integer $port,
String $memory,
Boolean $jmx_remote,
String $data_dir,
Optional[Array[String]] $zk_hosts,
) {
#------------------------------------------------------------------------------#
# Code #
#------------------------------------------------------------------------------#
# So far based on https://lucene.apache.org/solr/guide/7_1/taking-solr-to-production.html#taking-solr-to-production
if $manage_group {
group { $group:
ensure => 'present',
}
}
if $manage_user {
user { $user:
ensure => 'present',
gid => $group,
}
}
# solr dependency on RedHat servers
package { 'lsof':
ensure => 'installed',
}
# Download the installer archive and extract the install script
$install_archive = "${install_dir}/${archive_name}"
archive { $install_archive:
checksum_type => $checksum_type,
checksum_url => "${archive_url}/${archive_name}.${checksum_type}",
cleanup => false,
creates => 'dummy_value', # extract every time. This is needed because archive has unexpected behaviour without it. (seems to be mandatory, instead of optional)
extract => true,
extract_path => $install_dir,
source => "${archive_url}/${archive_name}"
}
# Create instance data folder
file { $data_dir:
recurse => true,
owner => $user,
group => $group,
}
# Solr is extracted & installed here
$home_dir = "${install_dir}/solr-${$version}"
# triggers install script as defined in the solr docu
$install_command = "${home_dir}/bin/install_solr_service.sh ${install_archive} -n -i ${install_dir} -d ${data_dir} -u ${user} -s ${service_name} -p ${port}"
exec { "Solr install for Solr-${version}" :
command => $install_command,
timeout => 200,
path => '/usr/bin:/bin',
unless => "/usr/bin/test -e ${home_dir}/.solr-${version}-installed-flag",
require => [
File[$data_dir],
Archive[$install_archive],
];
}
# Leave breadcrumbs/flags to indicate that the installation + restarts was already performed and should not be repeated next time!
file { "Solr-${version} - Leave breadcrumbs to indicate that the Solr-${version} was already installed." :
ensure => present,
path => "${home_dir}/.solr-${version}-installed-flag",
owner => $user,
mode => '0644',
content => "This file indicates that solr was already installed in this version and doesn\'t need to be repeated on every puppet run!",
require => [
Exec["Solr install for Solr-${version}"],
];
}
# default solr config file
$config_file = "/etc/default/${service_name}.in.sh"
file { $config_file:
ensure => present,
path => $config_file,
require => [
Exec["Solr install for Solr-${version}"],
];
}
if $memory {
file_line { 'Append memory setting to the default config file for the solr service':
notify => Service[$service_name],
path => $config_file,
line => "SOLR_JAVA_MEM=\"${memory}\"",
match => '.*SOLR_JAVA_MEM=.*',
require => File[$config_file],
}
}
if $jmx_remote {
file_line { 'Enable JMX remote':
notify => Service[$service_name],
path => $config_file,
line => "ENABLE_REMOTE_JMX_OPTS=\"true\"",
match => '.*ENABLE_REMOTE_JMX_OPTS=.*',
require => File[$config_file],
}
}
if $zk_hosts {
$zk_hosts_options = $zk_hosts.join(',')
file_line { 'Append zookeeper settings to the default config file for the solr service':
notify => Service[$service_name],
path => $config_file,
line => "ZK_HOST=\"${zk_hosts_options}\"",
match => '.*ZK_HOST=.*',
require => File[$config_file],
}
}
# start and enable solr service
service { $service_name:
ensure => running,
enable => true,
}
}
|