2017-02-12 109 views
0

当我运行fabric.py来部署我的站点时Ubuntu。Fabric执行时拒绝权限rm -rf

我遇到了错误:

[192.168.15.143] run: rm -rf /home/user/project/weather_station/ 
[192.168.15.143] out: rm: cannot remove '/home/user/project/weather_station/logs/gunicorn.log': Permission denied 
[192.168.15.143] out: 


Fatal error: run() received nonzero return code 1 while executing! 

Requested: rm -rf /home/user/project/weather_station/ 
Executed: /bin/bash -l -c "rm -rf /home/user/project/weather_station/" 

Aborting. 
Disconnecting from 192.168.15.143... done. 

我认为这是错误是关于拒绝的权限。

我引用this

因此,我改变run('rm -rf {}'.format(PROJECT_DIR))sudo('rm -rf {}'.format(PROJECT_DIR))

但仍error.Is有什么办法?

+0

如果使用'operations.sudo()'而不是'operations.run()'会发生什么? – fernandezcuesta

+0

错误是完全相同的。我可以在fabfile中设置像'sudo -H rm -rf'这样的参数吗? – CJCheng

回答

0

是在/home/user/project/weather_station/logs/gunicorn.log文件中使用由活动进程?如果gunicorn正在运行并使用此文件作为日志文件,则“权限被拒绝”。正是应该发生的事情。如果是这种情况,那么你需要重新考虑你想要做什么,因为你不应该删除正在使用的文件。

对于日志文件,显而易见的解决方案是将gunicorn配置为使用其他位置,如/home/user/logs/weather_station,以便它位于您要删除的路径之外。

这一点不谈,如果执行此命令rm前停止gunicorn过程,那么你的命令应该成功运行。

的广泛问题,然而,就是(我觉得)你想删除日志文件,该文件在使用。您需要配置gunicorn来为其日志文件使用不同的位置,否则在尝试删除它之前需要结束gunicorn。

+0

thx您的回复,我终于通过键入'sudo chmod 777/home/user/project/weather_station/logs/gunicorn.log'解决了问题 – CJCheng

0

我终于用sudo chmod 777 /home/user/project/weather_station/logs/gunicorn.log

然后它的工作。