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

Command "hostname" is not portable #1212

Closed
pditommaso opened this issue Jul 17, 2021 · 10 comments
Closed

Command "hostname" is not portable #1212

pditommaso opened this issue Jul 17, 2021 · 10 comments

Comments

@pditommaso
Copy link

pditommaso commented Jul 17, 2021

The hostname command may not exist in all environments and cause the pipeline execution to fail

def hostname = "hostname".execute().text.trim()

Consider replacing it with

def hostname = ['sh', '-c', 'echo $HOSTNAME'].execute().text.trim()

x-ref nextflow-io/nextflow#2199

@pontus
Copy link
Contributor

pontus commented Jul 20, 2021

What cases are fixed by this, I'd rather think it's the other way around (hostname being available on all target platforms, although handling options differently, whereas $HOSTNAME is not set without a fancy shell).

Also, if one go for the environment variable, is there some "this runs on the target machine" magic that would explain the execution rather than picking it up from the environment variables directly?

@drpatelh
Copy link
Member

drpatelh commented Jul 20, 2021

An alternative is to use the hostname command but wrap it in a try/catch statement like here nf-core/rnaseq@fd5c9eb

Would that be a better solution @pontus @pditommaso ?

drpatelh added a commit to drpatelh/nf-core-tools that referenced this issue Jul 20, 2021
@pontus
Copy link
Contributor

pontus commented Jul 20, 2021

I'm mostly confused, so I'm not sure.

In my view hostname should work. uname -n might be slightly better but is mostly the same.

An optimisation (if there is no magic involved) could be to look at the environment first (in groovy) and run the command if there is no hostname, don't think it's worth the complexity though.

drpatelh added a commit that referenced this issue Jul 20, 2021
@drpatelh
Copy link
Member

Ok. This should be fixed in #1213 Can change if there is another, better solution :)

@pditommaso
Copy link
Author

@Zethson likely can provide more details about the env in which hostname was not found. In any case wrapping into a try catch is super suggested

@Zethson
Copy link
Member

Zethson commented Jul 20, 2021

@Zethson likely can provide more details about the env in which hostname was not found. In any case wrapping into a try catch is super suggested

A fresh Arch installation without inetutils being installed. I did not notice this and just expected the hostname command to always be available :)

@pditommaso
Copy link
Author

May you check if the var HOSTNAME is present ?

@Zethson
Copy link
Member

Zethson commented Jul 20, 2021

May you check if the var HOSTNAME is present ?

It's empty.

@pditommaso
Copy link
Author

Then try { .. } catch(Exception e) { .. } is the way to go

@drpatelh
Copy link
Member

Changed here #1214

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

No branches or pull requests

4 participants