【问题标题】:How can I cd to a folder and run npm start with git hook post-receive?如何 cd 到文件夹并使用 git hook post-receive 运行 npm start?
【发布时间】:2019-03-28 13:48:08
【问题描述】:

基本上我想:

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】:

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

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

    pm2 start npm --name 'my-app' — start \
    && echo "post-receive: app started successfully with pm2".
    

    【讨论】:

    • 是的,我现在正在使用 pm2(或永远在其他服务器上),但我想知道我是否可以裸机。
    • @AeroWang 从我链接的文章中,您不能:不在挂钩中,npm start 会挂起/冻结挂钩(以及整个 Git 命令)
    猜你喜欢
    • 2013-06-19
    • 1970-01-01
    • 2015-03-22
    • 2014-06-02
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多