{"thread":{"id":"26969","subject":"Background processes in post-receive hook","startedAt":"2011-04-02T23:03:43Z","lastAt":"2011-04-03T05:06:19Z","messageCount":5,"participants":["James Pickens","Junio C Hamano","Sitaram Chamarty","Joe Ratterman","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"164967","messageId":"AANLkTinrEt6DkwhknpDZ0iV9PR+7bBd3DAaPRJOgNFTG@mail.gmail.com","threadId":"26969","inReplyTo":null,"subject":"Background processes in post-receive hook","fromName":"James Pickens","fromEmail":"jepicken@gmail.com","sentAt":"2011-04-02T23:03:43Z","receivedAt":"2011-04-02T23:03:43Z","isPatch":false,"sender":{"key":"jepicken@gmail.com","avatar":null},"body":"Hi,\n\nI have a post-receive hook (bash script) that launches several background\nprocesses and exits immediately.  I do that so I don't have to wait for the\nbackground processes to finish every time I push to the repository, but Git\nseems to wait for them to finish anyways, even though the post-receive hook\nitself already exited.  Is there any way to stop Git from waiting and let the\npush finish immediately?  Sorry if I'm missing something obvious...\n\nThanks,\nJames\n"},{"id":"164970","messageId":"7v8vvsgoj8.fsf@alter.siamese.dyndns.org","threadId":"26969","inReplyTo":"AANLkTinrEt6DkwhknpDZ0iV9PR+7bBd3DAaPRJOgNFTG@mail.gmail.com","subject":"Re: Background processes in post-receive hook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-03T00:35:23Z","receivedAt":"2011-04-03T00:35:23Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"James Pickens <jepicken@gmail.com> writes:\n\n> I have a post-receive hook (bash script) that launches several background\n> processes and exits immediately.  I do that so I don't have to wait for the\n> background processes to finish every time I push to the repository, but Git\n> seems to wait for them to finish anyways, even though the post-receive hook\n> itself already exited.  Is there any way to stop Git from waiting and let the\n> push finish immediately?\n\nAn easy way to do that is to run whatever lengthy process you do not want\nto wait for using\n\n\techo \"that command\" | at now\n\nin the hook ;-).\n"},{"id":"164973","messageId":"BANLkTin4-fMhi_5H1oZ+gPB99stj5GRjVA@mail.gmail.com","threadId":"26969","inReplyTo":"AANLkTinrEt6DkwhknpDZ0iV9PR+7bBd3DAaPRJOgNFTG@mail.gmail.com","subject":"Re: Background processes in post-receive hook","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2011-04-03T03:22:50Z","receivedAt":"2011-04-03T03:22:50Z","isPatch":false,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"On Sun, Apr 3, 2011 at 4:33 AM, James Pickens <jepicken@gmail.com> wrote:\n> Hi,\n>\n> I have a post-receive hook (bash script) that launches several background\n> processes and exits immediately.  I do that so I don't have to wait for the\n> background processes to finish every time I push to the repository, but Git\n> seems to wait for them to finish anyways, even though the post-receive hook\n> itself already exited.  Is there any way to stop Git from waiting and let the\n> push finish immediately?  Sorry if I'm missing something obvious...\n\ninterestingly, the double fork trick doesn't work either...\n\n  ( ( long-running-command & ) )\n\nWhat Junio said may be the only alternative...\n"},{"id":"164977","messageId":"AANLkTim3Eu+rHc3_7_PWsALK3QwuzyX2Anbn8o6aCbAE@mail.gmail.com","threadId":"26969","inReplyTo":"BANLkTin4-fMhi_5H1oZ+gPB99stj5GRjVA@mail.gmail.com","subject":"Re: Background processes in post-receive hook","fromName":"Joe Ratterman","fromEmail":"jratt0@gmail.com","sentAt":"2011-04-03T04:59:59Z","receivedAt":"2011-04-03T04:59:59Z","isPatch":false,"sender":{"key":"jratt0@gmail.com","avatar":"https://avatars.githubusercontent.com/u/66082737?v=4"},"body":"On Sat, Apr 2, 2011 at 10:22 PM, Sitaram Chamarty <sitaramc@gmail.com> wrote:\n> interestingly, the double fork trick doesn't work either...\n>\n>  ( ( long-running-command & ) )\n\nI think that is because the hook is still reading from the command's\nstdout.  If you close stdout/stderr, I would expect it to work.  For\nexample, the \"sort\" command below cannot exit until all sub-programs\nhave finished feeding it data.  You can see that despite the levels of\nforking involved, the stdout of perl and the stdin of sort are the\nsame.\n\n$ ( ( perl -e 'sleep 60; print \"THERE\\n\";' & ) ) | sort > /tmp/out &\n[1] 4033\n$ ps h\n...\n 4033 pts/10   S      0:00 sort\n 4035 pts/10   S      0:00 perl -e sleep 60; print \"THERE\\n\";\n...\n$ ll /proc/{4035,4033}/fd\n/proc/4033/fd:\ntotal 0\nlr-x------ 1 jratt bgq 64 Apr  2 23:49 0 -> pipe:[55227211]\nl-wx------ 1 jratt bgq 64 Apr  2 23:49 1 -> /tmp/out\nlrwx------ 1 jratt bgq 64 Apr  2 23:49 2 -> /dev/pts/10\n\n/proc/4035/fd:\ntotal 0\nlr-x------ 1 jratt bgq 64 Apr  2 23:49 0 -> /dev/null\nl-wx------ 1 jratt bgq 64 Apr  2 23:49 1 -> pipe:[55227211]\nlrwx------ 1 jratt bgq 64 Apr  2 23:49 2 -> /dev/pts/10\n$ cat /tmp/out\n$ fg\n( ( perl -e 'sleep 60; print \"THERE\\n\";' & ) ) | sort > /tmp/out\n$ cat /tmp/out\nTHERE\n\n\n\nHowever, this version exits before the shell returns to the prompt\n(and the output is lost).\n\n$ ( ( perl -e 'close STDOUT; close STDERR;sleep 60; print \"THERE\\n\";'\n& ) ) | sort > /tmp/out &\n[1] 4097\n[1]+  Done                    ( ( perl -e 'close STDOUT; close\nSTDERR;sleep 60; print \"THERE\\n\";' & ) ) | sort > /tmp/out\n$\n\n\n\nJoe\n"},{"id":"164978","messageId":"20110403050619.GA32750@elie","threadId":"26969","inReplyTo":"BANLkTin4-fMhi_5H1oZ+gPB99stj5GRjVA@mail.gmail.com","subject":"Re: Background processes in post-receive hook","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-04-03T05:06:19Z","receivedAt":"2011-04-03T05:06:19Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Sitaram Chamarty wrote:\n\n> interestingly, the double fork trick doesn't work either...\n>\n>   ( ( long-running-command & ) )\n\nHopefully closing the output pipe does the trick.\n\n\texec long-running-command >&- 2>&- &\n\nThanks for an interesting example.\nJonathan\n"}]}