summaryrefslogtreecommitdiff
path: root/buildscripts/package_test/recipes/install_mongodb.rb
blob: 56385dbc2b088309344e0db2876e866867bdc97d (plain)
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
# This Chef task installs MongoDB in a new EC2 instance spun up by Kitchen in
# preparation for running some basic server functionality tests.

artifacts_tarball = 'artifacts.tgz'
user = node['current_user']
homedir = node['etc']['passwd'][user]['dir']

ruby_block 'allow sudo over tty' do
  block do
    file = Chef::Util::FileEdit.new('/etc/sudoers')
    file.search_file_replace_line(/Defaults\s+requiretty/, '#Defaults requiretty')
    file.search_file_replace_line(/Defaults\s+requiretty/, '#Defaults !visiblepw')
    file.write_file
  end
end

# This file limits processes to 1024. It therefore interfereres with `ulimit -u` when present.
if platform_family? 'rhel'
  file '/etc/security/limits.d/90-nproc.conf' do
    action :delete
  end
end

if %w(7).include?(node['platform_version'][0]) and node['platform'] == 'redhat'

  # RHEL 7 client
  if node['platform'] == 'redhat' and node['platform_version'][0] == "7"
    rhui_client_url = "http://boxes.10gen.com/build/rh-amazon-rhui-client-3.0.45-1.el7.noarch.rpm"
  end

  execute 'remove old amazon rhui client' do
    command 'rpm -ev rh-amazon-rhui-client'
    live_stream true
  end
  execute 'install updated amazon rhui client' do
    command "rpm -ivh --nodeps #{rhui_client_url}"
    cwd homedir
    live_stream true
  end
  execute 'reinstall updated amazon rhui client for dependencies' do
    command 'yum reinstall -y rh-amazon-rhui-client*'
    live_stream true
  end
end

remote_file "#{homedir}/#{artifacts_tarball}" do
  source node['artifacts_url']
end

execute 'extract artifacts' do
  command "tar xzvf #{artifacts_tarball}"
  live_stream true
  cwd homedir
end

if platform_family? 'debian'

  # SERVER-40491 Debian 8 sources.list need to point to archive url
  if node['platform'] == 'debian' and node['platform_version'] == '8.1'
    cookbook_file '/etc/apt/sources.list' do
      source 'sources.list.debian8'
      owner 'root'
      group 'root'
      mode '0644'
      action :create
    end
  end

  execute 'apt update' do
    command 'apt update'
    live_stream true
  end

  ENV['DEBIAN_FRONTEND'] = 'noninteractive'
  package 'openssl'

  if node['platform_version'] == '16.04'
    execute 'update ca-certificates' do
      command 'apt-get install -y ca-certificates'
      live_stream true
    end
  end

  # the ubuntu 16.04 image does not have some dependencies installed by default
  # and it is required for the install_compass script
  execute 'install dependencies' do
    command 'apt-get install -y python libsasl2-modules-gssapi-mit'
    live_stream true
  end

  # dpkg returns 1 if dependencies are not satisfied, which they will not be
  # for enterprise builds. We install dependencies in the next block.
  execute 'install mongod' do
    command 'dpkg -i `find . -name "*server*.deb"`'
    live_stream true
    cwd homedir
    returns [0, 1]
  end

  # install the tools so we can test install_compass
  execute 'install mongo tools' do
    command 'dpkg -i `find . -name "*tools*.deb"`'
    live_stream true
    cwd homedir
    returns [0, 1]
  end

  # yum and zypper fetch dependencies automatically, but dpkg does not.
  # Installing the dependencies explicitly is fragile, so we reply on apt-get
  # to install dependencies after the fact.
  execute 'update and fix broken dependencies' do
    command 'apt update && apt -y -f install'
    live_stream true
  end

  execute 'install mongo shell' do
    command 'dpkg -i `find . -name "*shell*.deb"`'
    live_stream true
    cwd homedir
  end
end

if platform_family? 'rhel'
  bash 'wait for yum updates if they are running' do
    sleep 120
  end
  execute 'install mongod' do
    command 'yum install -y `find . -name "*server*.rpm"`'
    live_stream true
    cwd homedir
  end

  # install the tools so we can test install_compass
  execute 'install mongo tools' do
    command 'yum install -y `find . -name "*tools*.rpm"`'
    live_stream true
    cwd homedir
  end

  execute 'install mongo shell' do
    command 'yum install -y `find . -name "*shell*.rpm"`'
    live_stream true
    cwd homedir
  end
end

if platform_family? 'suse'
  bash 'wait for zypper lock to be released' do
    code <<-EOD
    retry_counter=0
    # We also need to make sure another instance of zypper isn't running while
    # we do our install, so just run zypper refresh until it doesn't fail.
    # Waiting for 2 minutes is copied from an internal project where we do this.
    until [ "$retry_counter" -ge "12" ]; do
        zypper refresh && exit 0
        retry_counter=$(($retry_counter + 1))
        [ "$retry_counter" = "12" ] && break
        sleep 10
    done
    exit 1
  EOD
  flags "-x"
  end

  execute 'install mongod' do
    command 'zypper --no-gpg-checks -n install `find . -name "*server*.rpm"`'
    live_stream true
    cwd homedir
  end

  execute 'install mongo tools' do
    command 'zypper --no-gpg-checks -n install `find . -name "*tools*.rpm"`'
    live_stream true
    cwd homedir
  end

  execute 'install mongo' do
    command 'zypper --no-gpg-checks -n install `find . -name "*shell*.rpm"`'
    live_stream true
    cwd homedir
  end
end

inspec_wait = <<HEREDOC
#!/bin/bash -x
ulimit -v unlimited
for i in {1..60}
do
  mongo --eval "db.smoke.insert({answer: 42})"
  if [ $? -eq 0 ]
  then
    exit 0
  else
    echo "sleeping"
    sleep 1
  fi
done
exit 1
HEREDOC

file '/inspec_wait.sh' do
  content inspec_wait
  mode '0755'
end