git-auto-deploy使用与问题

在ubuntu系统服务中目前全采用了git-auto-deploy部署代码,这两天ubuntu包升级后发现有部署问题,公司的和我自己的vpn出现的问题差不多,记录如下:

【安装】
https://github.com/olipo186/Git-Auto-Deploy
【认证】

sudo -Hu git-auto-deploy git clone git@gitlab.com:xxx/main.git dir
PS:以 sshkey方式认证需要此动作加入kownhost

升级后代码部署失败,查看日志

#tail -n 30 /var/log/git-auto-deploy.log
2017-01-25 11:59:08,623 [INFO ]  Initializing repository /data/www/boms/
2017-01-25 11:59:10,169 [INFO ]  Branch master set up to track remote branch master from origin.
2017-01-25 11:59:10,169 [INFO ]  Your branch is up-to-date with 'origin/master'.
2017-01-25 11:59:10,169 [ERROR]  Reset branch 'master'
2017-01-25 11:59:10,186 [INFO ]  Repository /data/www/boms/ successfully initialized
2017-01-25 11:59:10,186 [INFO ]  Starting Git Auto Deploy in daemon mode
2017-01-25 11:59:10,194 [ERROR]  Traceback (most recent call last):
2017-01-25 11:59:10,195 [ERROR]  File "/usr/bin/git-auto-deploy", line 9, in 
2017-01-25 11:59:10,195 [ERROR]
2017-01-25 11:59:10,195 [ERROR]  load_entry_point('git-auto-deploy==0.5', 'console_scripts', 'git-auto-deploy')()
2017-01-25 11:59:10,195 [ERROR]  File "/usr/lib/python2.7/dist-packages/gitautodeploy/gitautodeploy.py", line 472, in main
2017-01-25 11:59:10,195 [ERROR]
2017-01-25 11:59:10,195 [ERROR]  app.setup(config)
2017-01-25 11:59:10,195 [ERROR]  File "/usr/lib/python2.7/dist-packages/gitautodeploy/gitautodeploy.py", line 312, in setup
2017-01-25 11:59:10,195 [ERROR]
2017-01-25 11:59:10,195 [ERROR]  self.create_pid_file()
2017-01-25 11:59:10,196 [ERROR]  File "/usr/lib/python2.7/dist-packages/gitautodeploy/gitautodeploy.py", line 166, in create_pid_file
2017-01-25 11:59:10,196 [ERROR]
2017-01-25 11:59:10,196 [ERROR]  with open(self._config['pidfilepath'], 'w') as f:
2017-01-25 11:59:10,196 [ERROR]  IOError
2017-01-25 11:59:10,196 [ERROR]  :
2017-01-25 11:59:10,196 [ERROR]  [Errno 13] Permission denied: u'/var/run/git-auto-deploy/git-auto-deploy.pid'
2017-01-25 11:59:10,196 [ERROR]

重启服务发现还是不行,给出了error信息

#systemctl restart git-auto-deploy.service

#tail -n 30 /var/log/git-auto-deploy.log
2017-08-18 11:46:06,796 [INFO ]  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2017-08-18 11:46:06,796 [INFO ]  Permissions 0750 for '/etc/git-auto-deploy/.ssh/id_rsa' are too open.
2017-08-18 11:46:06,797 [INFO ]  It is required that your private key files are NOT accessible by others.
2017-08-18 11:46:06,797 [INFO ]  This private key will be ignored.
2017-08-18 11:46:06,797 [INFO ]  Load key "/etc/git-auto-deploy/.ssh/id_rsa": bad permissions
2017-08-18 11:46:06,797 [INFO ]  Permission denied (publickey).
2017-08-18 11:46:06,797 [INFO ]  fatal: Could not read from remote repository.
2017-08-18 11:46:06,797 [INFO ]
2017-08-18 11:46:06,797 [INFO ]  Please make sure you have the correct access rights
2017-08-18 11:46:06,797 [INFO ]  and the repository exists.
2017-08-18 11:46:06,797 [ERROR]  Command 'git fetch origin' failed with exit code 128
2017-08-18 11:46:06,797 [ERROR]  Unable to init repository /data/www/boms/
2017-08-18 11:46:06,797 [INFO ]  Starting Git Auto Deploy in daemon mode
2017-08-18 11:46:06,806 [ERROR]  Traceback (most recent call last):
2017-08-18 11:46:06,806 [ERROR]  File "/usr/bin/git-auto-deploy", line 9, in 
2017-08-18 11:46:06,806 [ERROR]
2017-08-18 11:46:06,806 [ERROR]  load_entry_point('git-auto-deploy==0.16', 'console_scripts', 'git-auto-deploy')()
2017-08-18 11:46:06,806 [ERROR]  File "/usr/lib/python2.7/dist-packages/gitautodeploy/gitautodeploy.py", line 678, in main
2017-08-18 11:46:06,806 [ERROR]
2017-08-18 11:46:06,806 [ERROR]  app.setup(config)
2017-08-18 11:46:06,807 [ERROR]  File "/usr/lib/python2.7/dist-packages/gitautodeploy/gitautodeploy.py", line 273, in setup
2017-08-18 11:46:06,807 [ERROR]
2017-08-18 11:46:06,807 [ERROR]  self.create_pid_file()
2017-08-18 11:46:06,807 [ERROR]  File "/usr/lib/python2.7/dist-packages/gitautodeploy/gitautodeploy.py", line 120, in create_pid_file
2017-08-18 11:46:06,807 [ERROR]
2017-08-18 11:46:06,807 [ERROR]  with open(self._config['pid-file'], 'w') as f:
2017-08-18 11:46:06,807 [ERROR]  IOError
2017-08-18 11:46:06,807 [ERROR]  :
2017-08-18 11:46:06,807 [ERROR]  [Errno 13] Permission denied: u'/var/run/git-auto-deploy/git-auto-deploy.pid'
2017-08-18 11:46:06,807 [ERROR]

显然是相关文件权限不对造成的,重新调整如下

#chmod -R 700 /etc/git-auto-deploy/.ssh/
#chown -R git-auto-deploy:git-auto-deploy /var/run/git-auto-deploy
#systemctl restart git-auto-deploy.service

再看git-auto-deploy的log已经ok了!

最终的解决办法是修改git-auto-deploy的启动服务,把用户组调整为和nginx同组

vi /etc/init.d/git-auto-deploy
DAEMON_UID="git-auto-deploy"
DAEMON_GID="www-data"

发表评论

电子邮件地址不会被公开。 必填项已用*标注