1

Basically I want to:

git --work-tree=/home/aero/server --git-dir=/home/aero/server/.git pull;
ps aux | grep node | grep server-aero-static | awk '{print $2}' | xargs kill -9;
cd /home/aero/server;
npm start;

I don't think this would work in post-receive, why? And how can I get it to work?

Aero Wang
  • 8,382
  • 14
  • 63
  • 99

1 Answers1

0

The Git part should work, provided the remote "origin" is correctly set in /home/aero/server, in order for that repo to work properly (as in "Git post-receive not working correctly").

The npm start part might be a problem if that command blocks.
In that case (meaning execution in a Git hook), you might consider using pm2 to start your application, as explained in "A Friendly Guide To Automate Deployment For Node.js Apps With Git Hooks" by aunnnn.

pm2 start npm --name 'my-app' — start \
&& echo "post-receive: app started successfully with pm2".
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yeah I am using pm2 right now (or forever on some other servers) but I like to know if I can do it naked. – Aero Wang Mar 28 '19 at 06:48
  • @AeroWang From the article I link, you cannot: not in a hook, where `npm start` would hang/freeze the hook (and the whole Git command) – VonC Mar 28 '19 at 09:51