Skip to content

Commit

Permalink
f-dd
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Oct 13, 2023
1 parent 9f9a9af commit dad0f82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 5 additions & 1 deletion stack/base/before-notebook.d/10_prepare-home-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ if [[ -f /opt/bin/load-singlesshagent.sh ]] && ! grep -q "${header}" /home/${NB_
${header}
if [ -f /opt/bin/load-singlesshagent.sh ]; then
source /opt/bin/load-singlesshagent.sh
ssh-add /home/${NB_USER}/.ssh/id_rsa 2> /dev/null
fi
EOF
fi

# load the ssh-agent and add the default key generated
# the return code can be non-zero if the ssh-agent is not running
# which will cause the notebook to fail to start so we need to ignore the return code
source /opt/bin/load-singlesshagent.sh || true
10 changes: 5 additions & 5 deletions stack/base/load-singlesshagent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ load_singlesshagent() {
SSH_ENV="$HOME/.ssh/agent-environment"
# Source SSH settings, if applicable
if [ -r "${SSH_ENV}" ]; then
source "${SSH_ENV}" > /dev/null
source "${SSH_ENV}" 2>& /dev/null
[ "$VERBOSE" == "true" ] && echo "- sourcing existing environment" >&2
else
[ "$VERBOSE" == "true" ] && echo "- no existing environment to source" >&2
fi

SSH_ADD_OUTPUT=`ssh-add -l 2> /dev/null`
SSH_ADD_OUTPUT=`ssh-add -l`
# Needed, the later 'test' calls will replace this
SSHADD_RETVAL="$?"
# Error code: 0: there are keys; 1: there are no keys; 2: cannot contact agent
if [ "$SSHADD_RETVAL" == "2" ]
then
[ "$VERBOSE" == "true" ] && echo " - unable to contact agent, creating a new one" >&2
(umask 066; ssh-agent > ${SSH_ENV})
source "${SSH_ENV}" > /dev/null
source "${SSH_ENV}" 2> /dev/null
elif [ "$SSHADD_RETVAL" == "1" ]
then
[ "$VERBOSE" == "true" ] && echo " - ssh-agent found (${SSH_AGENT_PID}), no keys (I might want to add keys here)" >&2
# Maybe the user wants to do it by himself?
#ssh-add
# run ssh-add to add the default generate key `id_rsa` to the agent
ssh-add ~/.ssh/id_rsa 2> /dev/null
elif [ "$SSHADD_RETVAL" == "0" ]
then
NUMKEYS=`echo "$SSH_ADD_OUTPUT" | wc -l`
Expand Down
8 changes: 8 additions & 0 deletions tests/test-common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ def test_verdi_status(aiidalab_exec, nb_user):
output = aiidalab_exec("verdi status", user=nb_user).decode().strip()
assert "Connected to RabbitMQ" in output
assert "Daemon is running" in output


def test_ssh_agent_is_running(aiidalab_exec, nb_user):
output = aiidalab_exec("ps aux | grep ssh-agent", user=nb_user).decode().strip()
assert "ssh-agent" in output

# also check only one ssh-agent process is running
assert len(output.splitlines()) == 1

0 comments on commit dad0f82

Please sign in to comment.