git push to remote does not terminate

127 Views Asked by At

I want to push local changes to a live server, but the 'git-push' command does not terminate, after doing its' job. The program has to be stopped manually (I would like it to close itself).

I'm trying to use the git post-receive hook to update the live server and to restart two daemons. The problem is that the 'npm start' (the last command) continues to send its text output to 'git-push', even though 'npm start' was started as a background job. I've tried to redirect the stdin and sterr to /dev/null, but that didn't yield any result.

The 'npm start' starts a react web app

#!/bin/sh
killall node
GIT_WORK_TREE=/root/danskesn git checkout -f
server="node /root/danskesn/server/server.js"
webapp="npm start 1>/dev/null 2>&1 &"

nohup $server &
nohup $webapp &
2

There are 2 best solutions below

0
estherwn On

My best guess is that the files that you are trying to update are being locked by your active (react web app) process and therefore the git push does not get a chance to resolve properly.

0
torek On

Note carefully the redirections in this line:

webapp="npm start 1>/dev/null 2>&1 &"

Now look at the two backgrounded processes:

nohup $server &
nohup $webapp &

One of these—the one using $webapp—has embedded redirections for stdout and stderr. But what is $server set to?

server="node /root/danskesn/server/server.js"

Exercise: Are there any redirections here? If so, find them. (There could be some, inside node or /root/danskesn/server/server.js. I don't believe there are, though.)

If there aren't any redirections, the standard output and standard error output from this nohup $server & command is still connected to the git push command across your network. Your git push will wait for any output, and copy it to your shell session, prefixed with the word remote:. Your git push will terminate only when there is no more output available, i.e., when nohup $server & has closed its output and error streams, probably by terminating entirely.