Skip to content

Commit 3466889

Browse files
committed
Restore cfn_ prefix in cfnconfig variables
+ Add check for expected variables in fetch_and_run script Signed-off-by: Enrico Usai <[email protected]>
1 parent c39e5b2 commit 3466889

File tree

3 files changed

+46
-40
lines changed

3 files changed

+46
-40
lines changed

files/default/setup-ephemeral-drives.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ LVM_PATH="/dev/${LVM_VG_NAME}/${LVM_NAME}"
1717
LVM_ACTIVE_STATE="a"
1818
FS_TYPE="ext4"
1919
MOUNT_OPTIONS="noatime,nodiratime"
20-
# ephemeral_dir is set by cfnconfig
21-
INPUT_MOUNTPOINT="${ephemeral_dir}"
20+
# cfn_ephemeral_dir is set in the environment by cfnconfig sourcing
21+
INPUT_MOUNTPOINT="${cfn_ephemeral_dir}"
2222

2323
function log {
2424
SCRIPT=$(basename "$0")

templates/default/cfnconfig.erb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
stack_name=<%= node['cluster']['stack_name'] %>
2-
preinstall=<%= node['cluster']['preinstall'] %>
3-
preinstall_args=(<%= node['cluster']['preinstall_args'] %>)
4-
postinstall=<%= node['cluster']['postinstall'] %>
5-
postinstall_args=(<%= node['cluster']['postinstall_args'] %>)
6-
region=<%= node['cluster']['region'] %>
7-
scheduler=<%= node['cluster']['scheduler'] %>
8-
scheduler_slots=<%= node['cluster']['scheduler_slots'] %>
9-
instance_slots=<%= node['cluster']['instance_slots'] %>
10-
ephemeral_dir=<%= node['cluster']['ephemeral_dir'] %>
11-
ebs_shared_dirs=<%= node['cluster']['ebs_shared_dirs'] %>
12-
proxy=<%= node['cluster']['proxy'] %>
13-
node_type=<%= node['cluster']['node_type'] %>
14-
cluster_user=<%= node['cluster']['cluster_user'] %>
1+
cfn_stack_name=<%= node['cluster']['stack_name'] %>
2+
cfn_preinstall=<%= node['cluster']['preinstall'] %>
3+
cfn_preinstall_args=(<%= node['cluster']['preinstall_args'] %>)
4+
cfn_postinstall=<%= node['cluster']['postinstall'] %>
5+
cfn_postinstall_args=(<%= node['cluster']['postinstall_args'] %>)
6+
cfn_region=<%= node['cluster']['region'] %>
7+
cfn_scheduler=<%= node['cluster']['scheduler'] %>
8+
cfn_scheduler_slots=<%= node['cluster']['scheduler_slots'] %>
9+
cfn_instance_slots=<%= node['cluster']['instance_slots'] %>
10+
cfn_ephemeral_dir=<%= node['cluster']['ephemeral_dir'] %>
11+
cfn_ebs_shared_dirs=<%= node['cluster']['ebs_shared_dirs'] %>
12+
cfn_proxy=<%= node['cluster']['proxy'] %>
13+
cfn_node_type=<%= node['cluster']['node_type'] %>
14+
cfn_cluster_user=<%= node['cluster']['cluster_user'] %>
1515
<% if node['cluster']['node_type'] == 'ComputeFleet' -%>
16-
head_node=<%= node['cluster']['head_node'] %>
17-
head_node_private_ip=<%= node['cluster']['head_node_private_ip'] %>
18-
scheduler_queue_name=<%= node['cluster']['scheduler_queue_name'] %>
16+
cfn_head_node=<%= node['cluster']['head_node'] %>
17+
cfn_head_node_private_ip=<%= node['cluster']['head_node_private_ip'] %>
18+
cfn_scheduler_queue_name=<%= node['cluster']['scheduler_queue_name'] %>
1919
<% end -%>
2020
<% if node['cluster']['node_type'] == 'HeadNode' -%>
21-
volume=<%= node['cluster']['volume'] %>
21+
cfn_volume=<%= node['cluster']['volume'] %>
2222
<% end -%>

templates/default/fetch_and_run.erb

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
#!/bin/bash
22

3-
. /etc/parallelcluster/cfnconfig
3+
cfnconfig_file="/etc/parallelcluster/cfnconfig"
4+
. ${cfnconfig_file}
5+
6+
# Check expected variables from cfnconfig file
7+
function check_params () {
8+
if [ -z "${cfn_region}" ] || [ -z "${cfn_preinstall}" ] || [ -z "${cfn_preinstall_args}" ] || [ -z "${cfn_postinstall}" ] || [ -z "${cfn_postinstall_args}" ]; then
9+
error_exit "One or more required variables from ${cfnconfig_file} file are undefined"
10+
fi
11+
}
412

513
# Error exit function
614
function error_exit () {
715
script=`basename $0`
8-
echo "parallelcluster: $script - $1"
9-
logger -t parallelcluster "$script - $1"
16+
echo "parallelcluster: ${script} - $1"
17+
logger -t parallelcluster "${script} - $1"
1018
exit 1
1119
}
1220

@@ -17,50 +25,48 @@ function download_run (){
1725
tmpfile=$(mktemp)
1826
trap "/bin/rm -f $tmpfile" RETURN
1927
if [ "${scheme}" == "s3" ]; then
20-
<%= node['cluster']['cookbook_virtualenv_path'] %>/bin/aws --region ${region} s3 cp ${url} - > $tmpfile || return 1
28+
<%= node['cluster']['cookbook_virtualenv_path'] %>/bin/aws --region ${cfn_region} s3 cp ${url} - > $tmpfile || return 1
2129
else
2230
wget -qO- ${url} > $tmpfile || return 1
2331
fi
2432
chmod +x $tmpfile || return 1
25-
$tmpfile "$@" || error_exit "Failed to run $ACTION, $file failed with non 0 return code: $?"
33+
$tmpfile "$@" || error_exit "Failed to run ${ACTION}, ${file} failed with non 0 return code: $?"
2634
}
2735

2836
function run_preinstall () {
29-
if [ "${preinstall}" != "NONE" ]; then
30-
file="${preinstall}"
31-
if [ "${preinstall_args}" != "NONE" ]; then
32-
download_run ${preinstall} "${preinstall_args[@]}"
37+
if [ "${cfn_preinstall}" != "NONE" ]; then
38+
file="${cfn_preinstall}"
39+
if [ "${cfn_preinstall_args}" != "NONE" ]; then
40+
download_run ${cfn_preinstall} "${cfn_preinstall_args[@]}"
3341
else
34-
download_run ${preinstall}
42+
download_run ${cfn_preinstall}
3543
fi
3644
fi || error_exit "Failed to run preinstall"
3745
}
3846

3947
function run_postinstall () {
4048
RC=0
41-
if [ "${postinstall}" != "NONE" ]; then
42-
file="${postinstall}"
43-
if [ "${postinstall_args}" != "NONE" ]; then
44-
download_run ${postinstall} "${postinstall_args[@]}"
49+
if [ "${cfn_postinstall}" != "NONE" ]; then
50+
file="${cfn_postinstall}"
51+
if [ "${cfn_postinstall_args}" != "NONE" ]; then
52+
download_run ${cfn_postinstall} "${cfn_postinstall_args[@]}"
4553
else
46-
download_run ${postinstall}
54+
download_run ${cfn_postinstall}
4755
fi
4856
fi || error_exit "Failed to run postinstall"
4957
}
5058

51-
ACTION=${1#?}
59+
check_params
5260

53-
case $ACTION in
61+
ACTION=${1#?}
62+
case ${ACTION} in
5463
preinstall)
5564
run_preinstall
5665
;;
57-
5866
postinstall)
5967
run_postinstall
6068
;;
61-
6269
*)
6370
echo "Unknown action. Exit gracefully"
6471
exit 0
65-
6672
esac

0 commit comments

Comments
 (0)