git - 在 post-receive git hook 中使用 sudo 重启服务器

标签 git webserver hook git-post-receive

每次更改 .pm 文件时,我都必须重新启动网络服务器,因此我尝试在接收后 Hook 中设置重新启动。

#!/bin/sh
GIT_WORK_TREE=/web git checkout -f
rap stop
sleep 5
rap start

当我手动重启时,我必须进入 root 并输入 rap stop/start。现在我得到

remote: hooks/post-receive: line 3: rap: command not found 
remote: hooks/post-receive: line 5: rap: command not found

当我 push 时。我认为许可阻碍了我,我需要一些帮助来解决这个问题。

最佳答案

如果您需要以 root 身份使用这些命令,您可以像“How to execute commands as root in git post-receive hook”中那样:

  • create a separate script containing only the commands to run as root.
    #!/bin/bash
    sudo /full/path/to/rap stop
    sudo /full/path/to/rap start
  • in the post-receive script do:
    #!/bin/bash
    export GIT_WORK_TREE=/var/www/current/myapp/
    set -x
    echo "Checking out new files on production and restarting app"
    echo $USER
    git checkout -f
    sudo /home/admin/restart-myapp
  • And finally in the visudo:
    %sudo   ALL=(ALL:ALL) ALL
    admin   ALL=(ALL) NOPASSWD: /home/admin/restart-myapp

关于git - 在 post-receive git hook 中使用 sudo 重启服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24965160/

相关文章:

php - 找到此代码使用的 WordPress 插件源代码

git - 当我 git clone : fatal: does not appear to be a git repository

Java Web Server 突然停止响应,没有任何异常

c++ - 窗口最大化

java - Tomcat7 替代方案

javascript - 显示正在运行的已部署服务

c++ - 没有内联汇编的 x64 函数绕行

Git 将我的工作从某个提交移动到一个单独的分支,而不需要当前父级的更改

Git clone fatal error ,用户凭据正确

java - 如何将 git-clone-command 翻译为 clone-uri