clustershell icon indicating copy to clipboard operation
clustershell copied to clipboard

[solved] Send command to group of nodes including self

Open DClabaut opened this issue 10 years ago • 5 comments

Good morning, I am developing a python script that uses ClusterShell, and am having trouble sending a command to several machines if the group includes the emitting machine:

task = task_self() task.shell(command, nodes=NodeSet("@nodes-example")) task.resume()

doesn't work if "@nodes-example" contains "127.0.0.1".

Is there a workaround, or must I get another machine only for sending the commands ?

Thank you very much, Damien Clabaut

DClabaut avatar Aug 05 '14 11:08 DClabaut

Hello, Indeed, if your node group contains (an alias to) localhost, clustershell will try to connect to localhost using ssh (ssh by default). One easy solution is to modify your ssh config to allow ssh localhost. If you really want to avoid any ssh connection to localhost, you could explicitely do the following:

task = task_self()
task.shell(command, key="localhost")
task.shell(command, nodes="@nodes-without-localhost")
task.resume()

... but usually in that case, your script will only work from a specific machine (not so portable).

Another thing, clustershell doesn't resolve hostnames (to IP), it only expand groups to node names and pass these names directly to ssh (so it makes no difference between localhost or another remote machine).

Let me know if that helps, Stéphane

thiell avatar Aug 05 '14 12:08 thiell

I have been looking more deeply at the problem and it seems I was wrong about it: I can actually connect to 127.0.0.1, but as the scripts I start with ClusterShell are daemons, my main script just waits for it to stop... which is virtually never gonna happen.

Is there a way to use clustershell as background ? Like, my script just sends the command, then keeps executing no matter what happens to the command ?

Thanks,

DClabaut avatar Aug 05 '14 14:08 DClabaut

Found a dirty workaround: os.system("clush -g nodes-example command &") It does the trick, even though it is a shame to use python, then shell, then python again ^^

DClabaut avatar Aug 06 '14 08:08 DClabaut

That's very dirty :-) Did you try things like: task.shell("%s &" % command, nodes="@nodes") or task.shell("nohup %s &" % command, nodes="@nodes") ?

thiell avatar Aug 06 '14 08:08 thiell

Yes, and It didn't work...

DClabaut avatar Aug 06 '14 08:08 DClabaut