forked from DSpace/vagrant-dspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.pp
275 lines (237 loc) · 10.7 KB
/
setup.pp
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# Setup Puppet Script
#
# This Puppet script does the following:
# 1. Initializes the VM
# 2. Installs base DSpace prerequisites (Java, Maven, Ant) via our custom "dspace" Puppet module
# 3. Installs PostgreSQL (via a third party Puppet module)
# 4. Installs Tomcat (via a third party Puppet module)
# 5. Installs DSpace via our custom "dspace" Puppet Module
#
# Tested on:
# - Ubuntu 14.04
# Global default to requiring all packages be installed & apt-update to be run first
Package {
ensure => latest, # requires latest version of each package to be installed
require => Exec["apt-get-update"],
}
# Ensure the rcconf package is installed, we'll use it later to set runlevels of services
package { "rcconf":
ensure => "installed"
}
# Global default path settings for all 'exec' commands
Exec {
path => "/usr/bin:/usr/sbin/:/bin:/sbin:/usr/local/bin:/usr/local/sbin",
}
#-----------------------
# Server initialization
#-----------------------
# Add the 'partner' repositry to apt
# NOTE: $lsbdistcodename is a "fact" which represents the ubuntu codename (e.g. 'precise')
file { "partner.list":
path => "/etc/apt/sources.list.d/partner.list",
ensure => file,
owner => "root",
group => "root",
content => "deb http://archive.canonical.com/ubuntu ${lsbdistcodename} partner
deb-src http://archive.canonical.com/ubuntu ${lsbdistcodename} partner",
notify => Exec["apt-get-update"],
}
# Run apt-get update before installing anything
exec {"apt-get-update":
command => "/usr/bin/apt-get update",
refreshonly => true, # only run if notified
}
#--------------------------------------------------
# Initialize base pre-requisites (Java, Maven, Ant)
#--------------------------------------------------
# Initialize the DSpace module in order to install base prerequisites.
# These prerequisites are simply installed via the OS package manager
# in the DSpace module's init.pp script
include dspace
#------------------------
# Install PostgreSQL
#------------------------
# Init PostgreSQL module
# (We use https://github.com/puppetlabs/puppetlabs-postgresql/)
# DSpace requires UTF-8 encoding in PostgreSQL
# DSpace also requires version 9.4 or above. We'll use 9.4
class { 'postgresql::globals':
encoding => 'UTF-8',
# Setup the official Postgresql apt repos (in sources).
# Necessary to install a newer version of Postgres than what is in apt by default
manage_package_repo => true,
version => '9.4',
}
->
# Setup/Configure PostgreSQL server
class { 'postgresql::server':
ip_mask_deny_postgres_user => '0.0.0.0/32', # allows 'postgres' user to connect from any IP
ip_mask_allow_all_users => '0.0.0.0/0', # allow other users to connect from any IP
listen_addresses => '*', # accept connections from any IP/machine
postgres_password => 'dspace', # set password for "postgres"
}
# Ensure the PostgreSQL contrib package is installed
# (includes various extensions, like pgcrypto which is required by DSpace)
class { 'postgresql::server::contrib': }
# Create a 'dspace' database & 'dspace' user account (which owns the database)
postgresql::server::db { 'dspace':
user => 'dspace',
password => 'dspace'
}
# Activate the 'pgcrypto' extension on our 'dspace' database
# This is REQUIRED by DSpace 6 and above
postgresql::server::extension { 'pgcrypto':
database => 'dspace',
}
#-----------------------
# Install Tomcat
#-----------------------
# Lookup Tomcat installation settings from Hiera
# These settings should all be specified in default.yaml
$tomcat_package = hiera('tomcat_package')
$tomcat_service = hiera('tomcat_service')
$catalina_home = hiera('catalina_home')
$catalina_base = hiera('catalina_base')
$catalina_opts = hiera('catalina_opts')
# Init Tomcat module
# (We use https://github.com/puppetlabs/puppetlabs-tomcat/)
class {'tomcat':
install_from_source => false, # Do NOT install from source, we'll use package manager
catalina_home => $catalina_home,
manage_user => false, # Don't let Tomcat module manage which user/group to start with, package does this already
manage_group => false,
require => Class['dspace'], # Require DSpace was initialized, so that Java is installed
}
->
# Create a new Tomcat instance & install from package manager
tomcat::instance { 'default':
package_name => $tomcat_package, # Name of the tomcat package to install
package_ensure => installed, # Ensure package is installed
}
->
# Override the default Tomcat <Host name='localhost'> entry
# and point it at the DSpace webapps directory (so that it loads all DSpace webapps)
tomcat::config::server::host { 'localhost':
app_base => '/home/vagrant/dspace/webapps', # Tell Tomcat to load webapps from this directory
host_ensure => present,
catalina_base => $catalina_base, # Tomcat install this pertains to
additional_attributes => { # Additional Tomcat <Host> attributes
'autoDeploy' => 'true',
'unpackWARs' => 'true',
},
notify => Service['tomcat'], # If changes are made, notify Tomcat to restart
}
->
# Temporarily stop Tomcat, so that we can modify which user it runs as
# (We cannot tweak the Tomcat run-as user while it is running)
exec { 'Stop default Tomcat temporarily':
command => "service ${tomcat_service} stop",
}
->
# Modify the Tomcat "defaults" file to make Tomcat run as the 'vagrant' user
# NOTE: This seems to be the ONLY way to do this in Ubuntu, which is disappointing
file_line { 'Update Tomcat to run as vagrant user':
path => "/etc/default/${tomcat_service}", # File to modify
line => "TOMCAT7_USER=vagrant", # Line to add to file
match => "^TOMCAT7_USER=.*$", # Regex for line to replace (if found)
notify => Service['tomcat'], # If changes are made, notify Tomcat to restart
}
->
# Modify the Tomcat "defaults" file to set custom JAVA_OPTS based on the "catalina_opts"
# config in hiera. Again, seems to be the only way to easily do this in Ubuntu.
file_line { 'Update Tomcat run options':
path => "/etc/default/${tomcat_service}", # File to modify
line => "JAVA_OPTS=\"${catalina_opts}\"", # Line to add to file
match => "^JAVA_OPTS=.*$", # Regex for line to replace (if found)
notify => Service['tomcat'], # If changes are made, notify Tomcat to restart
}
->
# In order for Tomcat to function properly, the entire CATALINA_BASE directory
# and all subdirectories need to be owned by 'vagrant'
file { $catalina_base:
ensure => directory,
owner => vagrant, # Change owner to 'vagrant'
recurse => true, # Also change owner of subdirectories/files
links => follow, # Follow any links to and change ownership there too
}
->
# This service is auto-created by package manager when installing Tomcat
# But, we just want to make sure it is running & starts on boot
service {'tomcat':
name => $tomcat_service,
enable => 'true',
ensure => 'running',
}
#---------------------
# Install DSpace
#---------------------
# Lookup DSpace installation settings from Hiera
# These settings should all be specified in default.yaml
$git_repo = hiera('git_repo')
$git_branch = hiera('git_branch')
$ant_installer_dir = hiera('ant_installer_dir', '/home/vagrant/dspace-src/dspace/target/dspace-installer') # Default value, if unspecified in hiera
$mvn_params = hiera('mvn_params')
$admin_firstname = hiera('admin_firstname')
$admin_lastname = hiera('admin_lastname')
$admin_email = hiera('admin_email')
$admin_passwd = hiera('admin_passwd')
$admin_language = hiera('admin_language')
# Check which Git Repo URL to use (SSH vs HTTPS)
# If the configured Git Repo is HTTPS, just use that. The user must want it that way.
# If the configured Git Repo is SSH, check the "git_ssh_status" Fact to see if our SSH connection
# to GitHub is working (=1). If it is not working (!=1), transform it to the HTTPS repo URL.
$final_git_repo = inline_template('<%= @git_repo.include?("https") ? @git_repo : @github_ssh_status.to_i==1 ? @git_repo : @git_repo.split(":")[1].prepend("https://github.com/") %>')
# Notify which GitHub repo we are using
notify { "GitHub Repo":
message => "Using DSpace GitHub Repo at ${final_git_repo}"
}
# Kickoff a DSpace installation for the 'vagrant' default user,
# using the specified GitHub repository & branch.
dspace::install { 'vagrant-dspace':
owner => vagrant, # DSpace should be owned by the default vagrant user
version => '6.0-SNAPSHOT',
git_repo => $final_git_repo,
git_branch => $git_branch,
mvn_params => $mvn_params,
ant_installer_dir => $ant_installer_dir,
admin_firstname => $admin_firstname,
admin_lastname => $admin_lastname,
admin_email => $admin_email,
admin_passwd => $admin_passwd,
admin_language => $admin_language,
require => Postgresql::Server::Db['dspace'], # Require that PostgreSQL is setup
notify => Service['tomcat'],
}
#---------------------
# Install PSI Probe
#---------------------
# For convenience in troubleshooting Tomcat, let's install Psi-probe
# http://psi-probe.googlecode.com/
$probe_version = "2.3.3"
exec {"Download and install the PSI Probe v${probe_version} war":
command => "wget --quiet --continue https://psi-probe.googlecode.com/files/probe-${probe_version}.zip && unzip -u probe-${probe_version}.zip && rm probe-${probe_version}.zip",
cwd => "${catalina_base}/webapps",
creates => "${catalina_base}/webapps/probe.war",
user => "vagrant",
logoutput => true,
tries => 3, # In case of a network hiccup, try this download 3 times
require => File[$catalina_base], # CATALINA_BASE must exist before downloading
}
->
# Add a context fragment file for Psi-probe, and restart tomcat
file { "${catalina_base}/conf/Catalina/localhost/probe.xml" :
ensure => file,
owner => vagrant,
group => vagrant,
content => template("dspace/probe.xml.erb"),
notify => Service['tomcat'],
}
->
# Add a "dspace" Tomcat User (password="vagrant") who can login to PSI Probe
# (NOTE: This line will only be added after <tomcat-users> if it doesn't already exist there)
file_line { 'Add \'dspace\' Tomcat user for PSI Probe':
path => "${catalina_base}/conf/tomcat-users.xml", # File to modify
after => '<tomcat-users>', # Add content immediately after this line
line => '<role rolename="manager"/><user username="dspace" password="vagrant" roles="manager"/>', # Lines to add to file
notify => Service['tomcat'], # If changes are made, notify Tomcat to restart
}