Skip to content

Commit dff0c69

Browse files
Add is_service_installed? helper to enable and run gdrcopy service only when the service is present
Signed-off-by: Francesco Giordano <[email protected]>
1 parent 0c52c5b commit dff0c69

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright:: 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License").
6+
# You may not use this file except in compliance with the License.
7+
# A copy of the License is located at
8+
#
9+
# http://aws.amazon.com/apache2.0/
10+
#
11+
# or in the "LICENSE.txt" file accompanying this file.
12+
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
13+
# See the License for the specific language governing permissions and limitations under the License.
14+
15+
#
16+
# Check if a service is installed in the instance and in the specific platform
17+
#
18+
def is_service_installed?(service, platform_families = node['platform_family'])
19+
if platform_family?(platform_families)
20+
service_check = Mixlib::ShellOut.new("systemctl daemon-reload && systemctl list-unit-files --all | grep #{service}")
21+
service_check.run_command
22+
# convert return code in boolean
23+
service_check.exitstatus.to_i.zero?
24+
else
25+
# in case of different platform return false
26+
false
27+
end
28+
end

cookbooks/aws-parallelcluster-config/recipes/nvidia.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
end
2424
end
2525

26-
if graphic_instance?
26+
if graphic_instance? && is_service_installed?(node['cluster']['nvidia']['gdrcopy']['service'])
2727
# NVIDIA GDRCopy
2828
execute "enable #{node['cluster']['nvidia']['gdrcopy']['service']} service" do
2929
# Using command in place of service resource because of: https://github.com/chef/chef/issues/12053

0 commit comments

Comments
 (0)