Post History
I'm trying to run a pipeline to update a PDF after every push to the 'main' branch. I want it to be atomic, so it doesn't touch the existing PDF until it has finished, so I need to use sponge(1) (...
#2: Post edited
Run pipeline in background from git hook
- Run pipeline in the background from git hook
#1: Initial revision
Run pipeline in background from git hook
I'm trying to run a pipeline to update a PDF after every push to the 'main' branch. I want it to be atomic, so it doesn't touch the existing PDF until it has finished, so I need to use sponge(1) (from moreutils). I've tried the following script: ```sh #!/bin/sh test "$1" = "refs/heads/main" || exit 0; cd ~/tmp/man-pages/; unset $(git rev-parse --local-env-vars); git fetch srv >/dev/null; git reset srv/main --hard >/dev/null; do_work() { scripts/LinuxManBook/build.sh 2>/dev/null \ | sponge ~/tmp/LMB-HEAD.pdf >/dev/null 2>&1; } do_work & ``` If I run the script in a terminal, it works as expected: ```sh $ time ./hooks/post-update refs/heads/main real 0m0.015s user 0m0.007s sys 0m0.008s ``` And after 15 seconds, the PDF is there. However, if I do a git push, I must wait for it to finish. It seems to be ignoring the `&`. ```sh $ time git push -f tmp Enumerating objects: 8, done. Counting objects: 100% (8/8), done. Delta compression using up to 24 threads Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 1.40 KiB | 1.40 MiB/s, done. Total 5 (delta 3), reused 0 (delta 0), pack-reused 0 remote: From /home/alx/tmp/man remote: + 3ac7ec68b...8b824c494 main -> srv/main (forced update) To /home/alx/tmp/man.git/ + 3ac7ec68b...8b824c494 main -> main (forced update) real 0m16.051s user 0m0.025s sys 0m0.014s ``` Is there anything I'm missing? If I transform the script to do a simpler redirection, without using a pipe, then it works as expected. It seems it's the pipe that is making me wait. ```sh ... scripts/LinuxManBook/build.sh >~/tmp/LMB-HEAD.pdf & #This works ```