2017-02-12 108 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

然後它的工作。