我最近刚刚在服务器上为作为 Upstart 服务运行的 Web 应用程序设置了一个远程 git repo。我想使用 post-receive 挂钩来触发更新应用程序代码所需的操作,然后停止然后重新启动 upstart 服务。这是我的 repo.git/hooks/post-receive 文件:
#!/bin/bash
export GIT_WORK_TREE=/var/www/current/myapp/
echo "Checking out new files and restarting app"
echo $USER
git checkout -f
sudo /sbin/stop myapp-service
sudo /sbin/start myapp-service
Run Code Online (Sandbox Code Playgroud)
根据我在这里读到的信息:askUbuntu.com,让 upstart 命令以 root 身份执行的方法是编辑我的 visudo 文件。这是相关的片段:
%sudo ALL=(ALL:ALL) ALL
admin ALL=(ALL:ALL) NOPASSWD: /sbin/start myapp-service /sbin/stop myapp-service
Run Code Online (Sandbox Code Playgroud)
但是当我 git push 到遥控器时,我得到如下输出:
$ git commit -am "test" && git push prod master
[master 59ffccd] test
1 file changed, 1 insertion(+), 1 deletion(-)
Counting objects: …Run Code Online (Sandbox Code Playgroud)