Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Run pipeline in the background from git hook

+2
−0

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:

#!/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:

$ 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 &.

$ 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.

...

scripts/LinuxManBook/build.sh >~/tmp/LMB-HEAD.pdf &  #This works
History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+0
−0

Use nohup(1), and redirect stdout and stderr to /dev/null

The following works as expected, not having to wait until the PDF is generated.

#!/bin/sh

test "$1" = "refs/heads/main" || exit 0;

cd /srv/src/alx/linux/man-pages/man-pages/;

unset $(git rev-parse --local-env-vars);
git fetch srv			>/dev/null;
git reset srv/main --hard	>/dev/null;

nohup sh <<__EOF__ >/dev/null 2>&1 &
	scripts/LinuxManBook/build.sh 2>/dev/null \
	| sponge /srv/www/share/dist/man-pages/git/HEAD/man-pages-HEAD.pdf;
__EOF__
History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »