Skip to content

Commit

Permalink
login nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Hanwen <[email protected]>
  • Loading branch information
hanwen-cluster committed Sep 4, 2024
1 parent ca27a9c commit eec7e47
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@
load_cluster_config(node['cluster']['login_cluster_config_path'])

# Create the configuration file for loginmgtd
template "#{node['cluster']['shared_dir_login_nodes']}/loginmgtd_config.json" do
template "#{node['cluster']['etc_dir']}/loginmgtd_config.json" do
source 'loginmgtd/loginmgtd_config.json.erb'
owner node['cluster']['cluster_admin_user']
group node['cluster']['cluster_admin_user']
mode '0644'
variables(
gracetime_period: lazy { node['cluster']['config'].dig(:LoginNodes, :Pools, 0, :GracetimePeriod) }
gracetime_period: lazy { node['cluster']['config'].dig(:LoginNodes, :Pools, :node['cluster']['pool_name'], :GracetimePeriod) }
)
end

# Create the termination hook for loginmgtd
template "#{node['cluster']['shared_dir_login_nodes']}/loginmgtd_on_termination.sh" do
template "#{node['cluster']['etc_dir']}/loginmgtd_on_termination.sh" do
source 'loginmgtd/loginmgtd_on_termination.sh.erb'
owner node['cluster']['cluster_admin_user']
group node['cluster']['cluster_admin_user']
mode '0744'
end

# Create the script to run loginmgtd
template "#{node['cluster']['shared_dir_login_nodes']}/loginmgtd.sh" do
template "#{node['cluster']['etc_dir']}/loginmgtd.sh" do
source 'loginmgtd/loginmgtd.sh.erb'
owner node['cluster']['cluster_admin_user']
group node['cluster']['cluster_admin_user']
Expand Down
1 change: 1 addition & 0 deletions cookbooks/aws-parallelcluster-platform/recipes/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
end

sudo_access "Update Sudo Access" if node['cluster']['scheduler'] == 'slurm'
include_recipe 'aws-parallelcluster-platform::config_login' if node['cluster']['node_type'] == 'LoginNode'
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

it 'creates the loginmgtd configuration with the correct attributes' do
is_expected.to create_template('/opt/parallelcluster/shared_login_nodes/loginmgtd_config.json').with(
is_expected.to create_template('/etc/parallelcluster/loginmgtd_config.json').with(
source: 'loginmgtd/loginmgtd_config.json.erb',
owner: 'pcluster-admin',
group: 'pcluster-admin',
Expand All @@ -17,7 +17,7 @@
end

it 'creates the loginmgtd script with the correct attributes' do
is_expected.to create_template('/opt/parallelcluster/shared_login_nodes/loginmgtd.sh').with(
is_expected.to create_template('/etc/parallelcluster/loginmgtd.sh').with(
source: 'loginmgtd/loginmgtd.sh.erb',
owner: 'pcluster-admin',
group: 'pcluster-admin',
Expand All @@ -26,7 +26,7 @@
end

it 'creates the loginmgtd termination hook script with the correct attributes' do
is_expected.to create_template('/opt/parallelcluster/shared_login_nodes/loginmgtd_on_termination.sh').with(
is_expected.to create_template('/etc/parallelcluster/loginmgtd_on_termination.sh').with(
source: 'loginmgtd/loginmgtd_on_termination.sh.erb',
owner: 'pcluster-admin',
group: 'pcluster-admin',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Cmnd_Alias LOGINMGTD_HOOKS_COMMANDS = <%= node['cluster']['shared_dir_login_nodes'] %>/loginmgtd_on_termination.sh
Cmnd_Alias LOGINMGTD_HOOKS_COMMANDS = <%= node['cluster']['etc_dir'] %>/loginmgtd_on_termination.sh

<%= node['cluster']['cluster_admin_user'] %> ALL = (root) NOPASSWD: LOGINMGTD_HOOKS_COMMANDS
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -ex
# This script must be executed as <%= node['cluster']['cluster_admin_user'] %> because
# because only this user has sudoers privileges to execute the termination hook.

CONFIG_PATH="<%= node['cluster']['shared_dir_login_nodes'] %>/loginmgtd_config.json"
CONFIG_PATH="<%= node['cluster']['etc_dir'] %>/loginmgtd_config.json"
CONFIG_JSON=$(cat $CONFIG_PATH)
TERMINATION_SCRIPT_PATH=$(echo $CONFIG_JSON | jq -r .termination_script_path)
TERMINATION_MESSAGE=$(echo $CONFIG_JSON | jq -r .termination_message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"termination_script_path": "<%= node['cluster']['shared_dir_login_nodes'] %>/loginmgtd_on_termination.sh",
"termination_script_path": "<%= node['cluster']['etc_dir'] %>/loginmgtd_on_termination.sh",
"termination_message": "The system will be terminated within <%= @gracetime_period %> minutes.",
"gracetime_period": "<%= @gracetime_period %>"
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ stdout_logfile_maxbytes = 0
<%# LoginNode -%>
<% when 'LoginNode' -%>
[program:loginmgtd]
command = <%= node['cluster']['shared_dir_login_nodes'] %>/loginmgtd.sh
command = <%= node['cluster']['etc_dir'] %>/loginmgtd.sh
user = <%= node['cluster']['cluster_admin_user'] %>
environment = HOME="/home/<%= node['cluster']['cluster_admin_user'] %>",USER="<%= node['cluster']['cluster_admin_user'] %>"
autorestart = unexpected
Expand Down
11 changes: 10 additions & 1 deletion cookbooks/aws-parallelcluster-shared/libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ def load_cluster_config(config_path)
require 'yaml'
Chef::Log.info("Reading Config from #{config_path}")
config = YAML.safe_load(File.read(config_path))
Chef::Log.debug("Config read #{config}")
Chef::Log.info("Config read #{config}")
unless config.dig("LoginNodes", "Pools").nil?
Chef::Log.info("Enter Config transform #{config}")
pools = {}
for pool in config["LoginNodes"]["Pools"]
pools[pool["Name"]]=pool
end
config["LoginNodes"]["Pools"] = pools
Chef::Log.info("Config transform #{config}")
end
node.override['cluster']['config'].merge! config
end
only_if { node['cluster']['config'].nil? }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
mode '0700'
variables(
target_group_name: lazy do
node['cluster']['config'].dig(:LoginNodes, :Pools).keys do |pool_name|
get_target_group_name(
node['cluster']['cluster_name'] || node['cluster']['stack_name'],
node['cluster']['config'].dig(:LoginNodes, :Pools, 0, :Name)
pool_name
)
end
end,
region: node['cluster']['region']
)
Expand Down

0 comments on commit eec7e47

Please sign in to comment.