|
| 1 | +# (C) Copyright IBM Corporation 2016. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +property :source, kind_of: String, required: true |
| 16 | +property :accept_license, kind_of: [TrueClass, FalseClass], default: false |
| 17 | +property :packages, kind_of: Array, default: %w(MQSeriesServer MQSeriesGSKit) |
| 18 | +property :default, kind_of: [TrueClass, FalseClass], default: false |
| 19 | +property :uid, kind_of: [String, Integer], default: nil |
| 20 | +property :gid, kind_of: [String, Integer], default: nil |
| 21 | + |
| 22 | +default_action :create |
| 23 | + |
| 24 | +# This action does the following: |
| 25 | +# * Downloads the MQ install package |
| 26 | +# * Extracts the install package |
| 27 | +# * Adds a Yum repository pointing at the MQ RPM files |
| 28 | +# * Accepts the license, as specified |
| 29 | +# * Installs the MQ packages, as specified |
| 30 | +# * Sets the default MQ installation, as specified |
| 31 | +action :create do |
| 32 | + fail 'You must accept the license to install IBM MQ.' unless accept_license |
| 33 | + fail 'Non-default installations are not currently supported' unless default |
| 34 | + |
| 35 | + # include_recipe 'sysctl::ohai_plugin' |
| 36 | + # |
| 37 | + # sysctl_param 'fs.file-max' do |
| 38 | + # value 524_289 |
| 39 | + # only_if node['sys']['fs']['file-max'] < value |
| 40 | + # end |
| 41 | + |
| 42 | + download_dir = "#{Chef::Config[:file_cache_path]}/ibm_mq" |
| 43 | + download_path = "#{download_dir}/#{name}.tar.gz" |
| 44 | + unpack_dir = "#{download_dir}/extract-#{name}" |
| 45 | + |
| 46 | + directory download_dir do |
| 47 | + owner 'root' |
| 48 | + group 'root' |
| 49 | + mode '0755' |
| 50 | + action :create |
| 51 | + end |
| 52 | + |
| 53 | + directory unpack_dir do |
| 54 | + owner 'root' |
| 55 | + group 'root' |
| 56 | + mode '0755' |
| 57 | + action :create |
| 58 | + end |
| 59 | + |
| 60 | + package %w(rpm yum createrepo) do |
| 61 | + action :install |
| 62 | + end |
| 63 | + |
| 64 | + remote_file download_path do |
| 65 | + source new_resource.source |
| 66 | + action :create |
| 67 | + notifies :run, 'execute[extract-mq-package]', :immediately |
| 68 | + notifies :run, 'execute[createrepo-mq]', :immediately |
| 69 | + backup false |
| 70 | + action :create |
| 71 | + end |
| 72 | + |
| 73 | + execute 'extract-mq-package' do |
| 74 | + command "tar -xvf #{download_path}" |
| 75 | + cwd unpack_dir |
| 76 | + # Only run after notified by remote_file download |
| 77 | + action :nothing |
| 78 | + end |
| 79 | + |
| 80 | + execute 'createrepo-mq' do |
| 81 | + user 'root' |
| 82 | + cwd "#{unpack_dir}/MQServer" |
| 83 | + command 'createrepo .' |
| 84 | + end |
| 85 | + |
| 86 | + group 'mqm' do |
| 87 | + gid new_resource.gid |
| 88 | + action :create |
| 89 | + end |
| 90 | + |
| 91 | + user 'mqm' do |
| 92 | + uid new_resource.uid |
| 93 | + group 'mqm' |
| 94 | + home '/var/mqm' |
| 95 | + action :create |
| 96 | + end |
| 97 | + |
| 98 | + set_limit 'mqm' do |
| 99 | + type 'soft' |
| 100 | + item 'nofile' |
| 101 | + value 10_240 |
| 102 | + end |
| 103 | + |
| 104 | + set_limit 'mqm' do |
| 105 | + type 'hard' |
| 106 | + item 'nofile' |
| 107 | + value 10_240 |
| 108 | + end |
| 109 | + |
| 110 | + execute 'Accept the mqlicense' do |
| 111 | + user 'root' |
| 112 | + cwd "#{unpack_dir}/MQServer" |
| 113 | + command './mqlicense.sh -accept -text_only' |
| 114 | + end |
| 115 | + |
| 116 | + # Work around bug in 'yum' cookbook |
| 117 | + # See https://github.com/chef-cookbooks/yum/issues/144 |
| 118 | + directory '/etc/yum.repos.d' do |
| 119 | + owner 'root' |
| 120 | + group 'root' |
| 121 | + mode '0755' |
| 122 | + action :create |
| 123 | + end |
| 124 | + |
| 125 | + # Add a local yum repository |
| 126 | + yum_repository "ibm-mq-chef-#{name}" do |
| 127 | + description 'Packages for IBM MQ, used by Chef cookbook' |
| 128 | + baseurl "file://#{unpack_dir}/MQServer" |
| 129 | + gpgcheck false |
| 130 | + action :create |
| 131 | + end |
| 132 | + |
| 133 | + # Install MQ |
| 134 | + yum_package packages do |
| 135 | + action :install |
| 136 | + end |
| 137 | + |
| 138 | + # TODO: Unset as default installation, if no longer default |
| 139 | + execute 'setmqinst' do |
| 140 | + command '/opt/mqm/bin/setmqinst -n Installation1 -i' |
| 141 | + only_if { default } |
| 142 | + end |
| 143 | +end |
| 144 | + |
| 145 | +action :remove do |
| 146 | + # Uninstall MQ |
| 147 | + yum_package packages do |
| 148 | + action :remove |
| 149 | + end |
| 150 | + |
| 151 | + # Remove our Yum repository |
| 152 | + yum_repository "ibm-mq-chef-#{name}" do |
| 153 | + action :remove |
| 154 | + end |
| 155 | +end |
0 commit comments