webhook icon indicating copy to clipboard operation
webhook copied to clipboard

Run command in background

Open coreyworrell opened this issue 6 years ago • 11 comments

Using the options execute-command, and include-command-output-in-response: true, how can I start a command in the background and still let my script return to webhook?

Right now I have tried:

#!/usr/bin/env bash
echo "test"
longcommand && otherlongcommand &
// also tried (longcommand && otherlongcommand) &
exit 0

But this results in a TIMEOUT (through Bitbucket webhook). I would assume that the script would echo "test" and then exit allowing webhook to return its 200 response.

What can I do?

coreyworrell avatar Apr 14 '18 00:04 coreyworrell

I am trying to do a similar thing - start a server as a backgrounded process, and found that control doesn't return to the webhook until i manually kill the process from another session. I thought it might be useful that in addition to the above method, i have tried nohup and disown, both of which detatch the process as expected when running the script standalone, but do not work when run via webhook's exec. i.e. if my server binary was titled myserver I have tried

myserver &
nohup myserver &

and

myserver &; disown

byronhallett avatar May 01 '18 02:05 byronhallett

It looks like the only way to have webhook (or Go) spawn a background process and move on is to use exec.Start().

moorereason avatar May 01 '18 15:05 moorereason

@byronhallett Possible solution is to use at

 echo "myserver" | at now

arusland avatar May 01 '18 15:05 arusland

@arusland that does not seem to work either. Thanks for the suggestion though.

coreyworrell avatar May 02 '18 18:05 coreyworrell

Has anyone else managed to solve this issue?

When running webhook -hooks /directory& any time I try to use the commandline afterwards the process automatically exits.

Oneiros0 avatar Mar 26 '19 04:03 Oneiros0

@ElementCR, I think you're asking about a different problem. You need to daemonize the webhook process. This issue is about webhook spawning background process in response to a specific hook.

moorereason avatar Mar 26 '19 22:03 moorereason

Hi there,

We have solved this problem with Task Spooler: http://vicerveza.homeunix.net/~viric/soft/ts/ It does the trick. :-) Spawning command in the background: https://gitlab.com/runhyve/vm-webhooks/blob/master/vm-create.sh#L36 Poll for task status: https://gitlab.com/runhyve/vm-webhooks/blob/master/ts-get-task.sh

mateuszkwiatkowski avatar Apr 12 '19 17:04 mateuszkwiatkowski

Hey I'm facing the same issue.. @mateuszkwiatkowski your first link is not working

GabrieleCalarota avatar Feb 04 '21 15:02 GabrieleCalarota

@GabrieleCalarota Ha! I anticipated this and created a mirror here: :) https://gitlab.com/runhyve/task-spooler

mateuszkwiatkowski avatar Feb 04 '21 16:02 mateuszkwiatkowski

@mateuszkwiatkowski thx for suggesting tsp, works like a charm!

nvtkaszpir avatar Jun 06 '21 19:06 nvtkaszpir

@mateuszkwiatkowski Thank you for your example using ts! It's exactly what I needed!

nemchik avatar Dec 27 '22 16:12 nemchik