我如何cd到一个文件夹并使用git hook post-receive运行npm start?

问题描述 投票:1回答:1

基本上我想:

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;

我不认为这会在收到后工作,为什么?我怎样才能让它发挥作用?

node.js git npm githooks
1个回答
0
投票

如果在/home/aero/server中正确设置了远程“origin”,Git部分应该可以工作,以便该repo正常工作(如“Git post-receive not working correctly”)。

如果该命令阻塞,npm start部分可能是一个问题。 在这种情况下(意味着在Git钩子中执行),您可以考虑使用using pm2来启动您的应用程序,如A Friendly Guide To Automate Deployment For Node.js Apps With Git Hooks在“aunnnn”中所述。

pm2 start npm --name 'my-app' — start \
&& echo "post-receive: app started successfully with pm2".
© www.soinside.com 2019 - 2024. All rights reserved.