|
2 | 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3 | 3 | # SPDX-License-Identifier: MIT-0
|
4 | 4 |
|
5 |
| -# This script creates the json file with user and group information. |
6 |
| -# It also creates a crontab entry to update the json file every hour. |
| 5 | +# This script deconfigures this instance from creating the json file with user and group information. |
7 | 6 |
|
8 | 7 | full_script=$(realpath $0)
|
9 | 8 | script_dir=$(dirname $full_script)
|
10 | 9 | base_script=$(basename $full_script)
|
| 10 | +ANSIBLE_PATH=$(dirname $script_dir)/ansible |
| 11 | +PLAYBOOKS_PATH=$ANSIBLE_PATH/playbooks |
11 | 12 |
|
12 |
| -date |
13 |
| -echo "Started create_users_groups_json_deconfigure.sh: $full_script" |
| 13 | +echo "$(date): Started create_users_groups_json_deconfigure.sh: $full_script" |
14 | 14 |
|
15 |
| -config_dir={{ ExternalLoginNodeSlurmConfigDir }} |
16 |
| -config_bin_dir=$config_dir/bin |
| 15 | +ErrorSnsTopicArn={{ ErrorSnsTopicArn }} |
17 | 16 |
|
18 |
| -temp_config_dir=/tmp/{{ClusterName}}_config |
19 |
| -temp_config_bin_dir=$temp_config_dir/bin |
20 |
| -if [[ $script_dir != $temp_config_bin_dir ]]; then |
21 |
| - rm -rf $temp_config_dir |
22 |
| - cp -r $config_dir $temp_config_dir |
23 |
| - exec $temp_config_dir/bin/$base_script |
24 |
| -fi |
| 17 | +# Notify user of errors |
| 18 | +function on_exit { |
| 19 | + rc=$? |
| 20 | + set +e |
| 21 | + if [[ $rc -ne 0 ]] && [[ ":$ErrorSnsTopicArn" != ":" ]]; then |
| 22 | + message_file=$(mktemp) |
| 23 | + echo "See log files for more info: |
| 24 | + grep ${script_name} /var/log/messages | less" > $message_file |
| 25 | + aws sns publish --topic-arn $ErrorSnsTopicArn --subject "${ClusterName} ${script_name} failed" --message file://$message_file |
| 26 | + rm $message_file |
| 27 | + fi |
| 28 | +} |
| 29 | +trap on_exit EXIT |
25 | 30 |
|
26 | 31 | # Install ansible
|
27 | 32 | if ! yum list installed ansible &> /dev/null; then
|
28 | 33 | yum install -y ansible || amazon-linux-extras install -y ansible2
|
29 | 34 | fi
|
30 | 35 |
|
31 |
| -ANSIBLE_PATH=$temp_config_dir/ansible |
32 |
| -PLAYBOOKS_PATH=$ANSIBLE_PATH/playbooks |
33 |
| - |
34 | 36 | pushd $PLAYBOOKS_PATH
|
35 | 37 | ansible-playbook $PLAYBOOKS_PATH/ParallelClusterCreateUsersGroupsJsonDeconfigure.yml \
|
36 | 38 | -i inventories/local.yml \
|
37 | 39 | -e @$ANSIBLE_PATH/ansible_external_login_node_vars.yml
|
38 | 40 | popd
|
39 | 41 |
|
40 |
| -rm -rf $temp_config_dir |
| 42 | +rm -rf $(dirname $script_dir) |
41 | 43 |
|
42 |
| -date |
43 |
| -echo "Finished create_users_groups_json_deconfigure.sh: $full_script" |
| 44 | +echo "$(date): Finished create_users_groups_json_deconfigure.sh: $full_script" |
44 | 45 |
|
45 | 46 | exit 0
|
0 commit comments