每次更改 .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/