Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ssh agent start script to home prepare script #360

Merged
merged 3 commits into from
Feb 24, 2023

Conversation

unkcpz
Copy link
Member

@unkcpz unkcpz commented Feb 16, 2023

fixes #357

The sshagent source command is added everytime where the notebook start. I move the append to bashrc command to the script which create the bashrc and only attach the command the first time bashrc created.

@unkcpz
Copy link
Member Author

unkcpz commented Feb 16, 2023

Tested with aiidalab-launch locally and the .bashrc file looks all good.

Copy link
Contributor

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unkcpz I've tested this locally and this approach does not seem to work. Because in this case the .bashrc file already exists, it will never get appended.

Have you tested with a brand new environment (e.g. by running aiidalab-launch reset)

@unkcpz
Copy link
Member Author

unkcpz commented Feb 17, 2023

Have you tested with a brand new environment (e.g. by running aiidalab-launch reset)

I test by creating a new profile.

Because in this case the .bashrc file already exists,

I think this is the expected behavior, no? The .bashrc is created only the first time.

@unkcpz
Copy link
Member Author

unkcpz commented Feb 17, 2023

If you look at the earliest implement which the append is in the dockerfile

RUN wget --quiet --directory-prefix=/opt/bin/ \
"https://aiida.readthedocs.io/projects/aiida-core/en/v${AIIDA_VERSION}/_downloads/4265ec5a42c3a3dba586dd460c0db95e/load-singlesshagent.sh" \
&& echo $'\n# Load singlesshagent on shell startup.\n\
if [ -f /opt/bin/load-singlesshagent.sh ]; then\n\
. /opt/bin/load-singlesshagent.sh\n\
fi\n' >> "/home/${NB_USER}/.bashrc"
. It has the problem that if the .bashrc exist in persistent volume, when the container instance is restarted (The current issue is when notebook restart), it will duplicate append the command.

@danielhollas
Copy link
Contributor

For me the bashrc is always there, even on the first startup so in the current implementation it never get appended.

Are you using bind mount or volume mount?

@unkcpz
Copy link
Member Author

unkcpz commented Feb 17, 2023

The same problem of my test as #359, I forget to update the image in the profile. I'll check it again.

@unkcpz
Copy link
Member Author

unkcpz commented Feb 17, 2023

I remember there is a discrepancy between the docker and deployment by using jupyterhub. The .bashrc is created if run using aiidalab-launch by docker. It needs a clever way to append the text.

# Set sshagent by source load-singlesshagent.sh script
# append the command text of source to .bashrc if the script /opt/bin/load-singlesshagen.sh is present
# and the command text is not already present in .bashrc
if [[ -f /opt/bin/load-singlesshagent.sh ]] && ! grep -q "# Load singlesshagent on shell startup." /home/${NB_USER}/.bashrc; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use a variable here

header="# Load singlesshagent on shell startup."

Otherwise looks okay, LMK when you want me to test this again @unkcpz

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done!

Copy link
Contributor

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀 I tested locally and it works.

@unkcpz unkcpz merged commit 88b484d into main Feb 24, 2023
@unkcpz unkcpz deleted the fix/357/sshagent-dup-set branch February 24, 2023 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

singlesshagent section in .bashrc is duplicated upon each container startup
2 participants