webhook
webhook copied to clipboard
Run command in background
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?
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
It looks like the only way to have webhook (or Go) spawn a background process and move on is to use exec.Start()
.
@byronhallett Possible solution is to use at
echo "myserver" | at now
@arusland that does not seem to work either. Thanks for the suggestion though.
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.
@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.
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
Hey I'm facing the same issue.. @mateuszkwiatkowski your first link is not working
@GabrieleCalarota Ha! I anticipated this and created a mirror here: :) https://gitlab.com/runhyve/task-spooler
@mateuszkwiatkowski thx for suggesting tsp, works like a charm!
@mateuszkwiatkowski Thank you for your example using ts
! It's exactly what I needed!