Skip to content

Long running commands are aborted after calling exec_command #11

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

Closed
pkittenis opened this issue Sep 25, 2014 · 1 comment
Closed

Long running commands are aborted after calling exec_command #11

pkittenis opened this issue Sep 25, 2014 · 1 comment
Assignees
Labels

Comments

@pkittenis
Copy link
Member

If a long running command, tail -f for exaple, is executed via exec_command the command is aborted after exec_command returns.

Fix by returning the pty to be used by get_stdout to get continuous output.

Also provide feedback in get_stdout that the command has not finished executing, how long it's been running and a way to kill it.

@pkittenis pkittenis self-assigned this Sep 25, 2014
@pkittenis pkittenis added the bug label Sep 25, 2014
@pkittenis pkittenis added this to the Release 0.7 milestone Sep 25, 2014
@pkittenis pkittenis changed the title Commands that assume a pty is present can fail Long running commands are aborted after calling exec_command Oct 6, 2014
@pkittenis
Copy link
Member Author

get_stdout now returns buffers by default (the behaviour when return_buffers=True) for long running commands.

In this case the channel is also returned in the hash so that exit code can be got after command has finished executing.

Reading stdout can be used to block and get output of command while it's still running.

Will update documentation to reflect this usage and possibly re-do get_stdout as it is only returning input/output buffers and the channel in this case.

For example:

In [4]: cmds = client.exec_command('puppet agent -t', sudo=True)
In [5]: output = [client.get_stdout(cmd) for cmd in cmds]
In [7]: stdout = output[0]['XXXX']['stdout']
In [8]: for line in stdout: print line
Info: Retrieving plugin
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
Info: Loading facts in /var/lib/puppet/lib/facter/ntp_is_configured.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/XXXXXXX.rb
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb
Info: Loading facts in /var/lib/puppet/lib/facter/concat_basedir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/jenkins.rb
Info: Caching catalog for XXXXXXXXXX
Info: Applying configuration version '1412615199'
Notice: Finished catalog run in 25.42 seconds
In [9]: 
In [10]: for line in stdout: print line
In [13]: chan.recv_exit_status()
Out[13]: 0

pkittenis pushed a commit that referenced this issue Oct 6, 2014
…ad and return buffers if not. Channel is now also returned from get_stdout to allow user to get exit status on command completion. This resolves #11
@pkittenis pkittenis removed this from the Release 0.7 milestone Oct 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant