deployer icon indicating copy to clipboard operation
deployer copied to clipboard

Aborting a task by CTRL+C leaves the process running on the server

Open windbridges opened this issue 2 years ago • 7 comments

  • Deployer version: 7.0.0-rc.8
  • Deployment OS: Ubuntu 18.04.6 LTS

I'm not sure if this is the desired behavior, since I discovered it by applying deployer to a rather non-standard task.

In addition to directly deploying and provisioning, I created several handy tasks for debugging, among them displaying the application log in real time. The task runs something like tail -f file.log. It's very handy to run dep log my-host and see the log in real time. But when I press CTRL+C, even though the task stops in the console, the tail process continues to run on the server.

It turns out that interrupting the long task doesn't actually stop the process on the server, but only returns a prompt in the console.

Should this behavior be fixed? Can anyone suggest a workaround to solve my problem?

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

windbridges avatar Jul 20 '22 18:07 windbridges

Yes, I think it should be fixed.

This is the default ssh behavior. But Deployer has a special timeout feature and this can be repurposed to also handle CTRL+C.

antonmedv avatar Jul 20 '22 18:07 antonmedv

Yes, I think it should be fixed.

This is the default ssh behavior. But Deployer has a special timeout feature and this can be repurposed to also handle CTRL+C.

Is there some sort of temporary workaround for this?

windbridges avatar Jul 22 '22 03:07 windbridges

Implement your own abort handler as its just php code.

antonmedv avatar Jul 22 '22 06:07 antonmedv

Implement your own abort handler as its just php code.

Okay, but what should I do inside this handler? I think I need to run kill [pid], but I don't know the process id. The only possible option is to grep process id by command name?

windbridges avatar Jul 23 '22 22:07 windbridges

This is what Deployer does internally on timeout.

antonmedv avatar Jul 24 '22 09:07 antonmedv

This is what Deployer does internally on timeout.

Ah, got it, thanks.

windbridges avatar Jul 24 '22 21:07 windbridges

I can't get this to work. I set the signal handler in the task, it is set, but it is not called when I press CTRL-C:

declare(ticks = 1);

task('app:log', function () {
    $command = parse('...');

    pcntl_signal(SIGINT, function () use ($command) {
        echo 'Got SIGINT';
        exit;
    });

    cd('{{project_path}}');
    run($command);
});

The same code works if the call to pcntl_signal is placed outside the task. But outside the task context it will be hard to understand which task is active at the moment.

In addition, I cannot call run() inside the signal handler, I get the error "Context was requested but was not available". Can you give me a link to an example where you do this to handle timeout?

windbridges avatar Aug 03 '22 18:08 windbridges