2

If I kick off a long running command like a database dump using exec, how would I go about canceling that command on the remote host if, for example, the user start mashing Control-C to kill the script.

In my testing it seems like even if you Control-C and kill the application the remote command keeps running.

Josh Rickard
  • 1,593
  • 2
  • 16
  • 29

1 Answers1

0

Capture SIGINT and SystemExit and clean up:

rescue SystemExit, Interrupt
  # clean up
  # net-ssh execute a kill on the pid
  # raise error
end
Mike K.
  • 3,751
  • 28
  • 41
  • 1
    Wouldn't that just kill the Ruby process and not a process it started on a remote host? I guess you could replace Process.kill with whatever remote command would kill the process. Also you'd want to raise the error after rescuing it, right? – Keith Bennett Apr 24 '16 at 18:44
  • Thanks, @keithrbennett, code example edited based on your suggestions. – Mike K. Apr 25 '16 at 13:50