我最近刚刚在服务器上为作为Upstart服务运行的Web应用程序设置了一个远程git repo。我想使用接收后挂钩触发更新应用程序代码并停止然后重新启动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
根据我在此处阅读的信息:askUbuntu.com,获取以root用户身份执行的upstart命令的方法是编辑visudo文件。以下是相关代码段:
%sudo ALL=(ALL:ALL) ALL
admin ALL=(ALL:ALL) NOPASSWD: /sbin/start myapp-service /sbin/stop myapp-service
但是当我git push到远程时,我得到如下输出:
$ git commit -am "test" && git push prod master
[master 59ffccd] test
1 file changed, 1 insertion(+), 1 deletion(-)
Counting objects: 11, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 544 bytes, done.
Total 6 (delta 4), reused 0 (delta 0)
remote: Checking out new files on production and restarting app
remote: admin
remote:
remote: sudo: no tty present and no askpass program specified
remote: Sorry, try again.
我检查了正确的用户正在执行接收后脚本(如上所示,请执行admin)。
有人可以帮我停下来,然后在git post-receive hook脚本中启动Upstart作业吗?如果Python,PHP或node.js javascript脚本比bash更容易执行upstart命令,则它们也可以接受(我是bash新手)
我查看了我的身份验证日志,这就是我所拥有的:
Apr 24 19:35:21 myhost01 sudo: pam_unix(sudo:auth): auth could not identify password for [admin]
Apr 24 19:35:21 myhost01 sudo: pam_unix(sudo:auth): conversation failed
Apr 24 19:35:21 myhost01 sudo: pam_unix(sudo:auth): auth could not identify password for [admin]
Apr 24 19:35:21 myhost01 sudo: pam_unix(sudo:auth): conversation failed
Apr 24 19:35:21 myhost01 sudo: pam_unix(sudo:auth): auth could not identify password for [admin]
Apr 24 19:35:21 myhost01 sudo: admin : 3 incorrect password attempts ; TTY=unknown ; PWD=/home/admin/myapp.git ; USER=root ; COMMAND=/s$
Apr 24 19:35:21 myhost01 sudo: unable to execute /usr/sbin/sendmail: No such file or directory
Apr 24 19:35:21 myhost01 sudo: pam_unix(sudo:auth): conversation failed