Python 结构在执行rm-rf时接收到拒绝的权限

Python 结构在执行rm-rf时接收到拒绝的权限,python,ubuntu,fabric,Python,Ubuntu,Fabric,当我运行fabric.py在Ubuntu上部署我的站点时 我遇到了错误: [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 erro

当我运行fabric.py在Ubuntu上部署我的站点时

我遇到了错误:

[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.
我认为错误在于被拒绝的许可

我提到

所以我 将
run('rm-rf{}.format(PROJECT_DIR))
更改为
sudo('rm-rf{}.format(PROJECT_DIR))


但仍然存在错误。有什么方法吗?

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

对于日志文件,最明显的解决方案是将gunicorn配置为使用不同的位置,如
/home/user/logs/weather\u station
,以便它位于您尝试删除的路径之外

撇开这一点不谈,如果您在执行此
rm
命令之前停止gunicorn进程,那么您的命令应该会成功运行


然而,主要的问题是(我认为)您试图删除正在使用的日志文件。您需要配置gunicorn以使用其日志文件的其他位置,或者在尝试删除它之前需要结束gunicorn。

我最终使用了
sudo chmod 777/home/user/project/weather\u station/logs/gunicorn.log


然后它就开始工作了。

如果使用
operations.sudo()
而不是
operations.run()
,会发生什么情况?错误完全相同。我可以在fabfile中设置类似
sudo-H rm-rf
的参数吗?谢谢您的回复,我最后通过键入
sudo chmod 777/home/user/project/weather\u station/logs/gunicorn.log