2016-01-22 38 views
5

我有麻煩設置Elastic Beanstalk上Web文件夾的權限。我在一個實例中使用自定義的docker鏡像運行多個容器:apache-php,mysql,memcached等。對於容器「apache-php」,我將一個文件夾與我的yii2應用程序映射到/ var/www/html /。如何爲Elastic Beanstalk上的特定容器設置文件夾權限

當我手動進行捆綁並通過Elastic Beanstalk控制檯進行上載/部署時,我確定擁有文件夾的正確權限,一切正常。

現在,當我使用「eb deploy」部署應用程序時,它將刪除所有權限,並收到服務器錯誤,並且「目錄不能通過Web進程寫入:/ var/www/html/backend/web /資產「。

我可以通過ssh連接,並手動設置必要的權限,但確定這不方便,因爲每次重新部署應用程序都需要完成。

所以,我的問題是什麼是自動設置Elastic Beanstalk特定容器中特定文件夾的權限的最佳方式是什麼?也許,我可以使用.ebextensions,但我沒有找到如何爲特定容器運行「container_commands」。

回答

9

AWS EB部署在/var/app/ondeck

  1. 啓動您的應用程序在部署彈性魔豆,你的應用程序是先解壓到/var/app/ondeck/
    • 最有可能的,你的本地文件夾部署沒有你想要的權限在他們。
  2. 如果您需要在部署過程中對應用程序或shell進行調整,.ebextensions/*.config是正確的選擇。

集裝箱命令應運行到該路徑

但請記住,這些命令將運行每次部署,是否需要或不,除非你使用一些方法來測試預配置。

container_commands: 
    08user_config: 
    test: test ! -f /opt/elasticbeanstalk/.preconfig-complete 
    command: | 
     echo "jail-me" > /home/ec2-user/.userfile 
    09writable_dirs: 
    command: | 
     chmod -R 770 /var/app/ondeck/backend/web/assets 
     chmod -R 770 /var/app/ondeck/[path] 
    99complete: 
    command: | 
     touch /opt/elasticbeanstalk/.preconfig-complete 

files: 
    "/etc/profile.d/myalias.sh": 
    mode: "000644" 
    owner: root 
    group: root 
    content: | 
     alias webroot='cd /var/www/html/backend/web; ls -al --color;' 
     echo " ========== " 
     echo " The whole point of Elastic Beanstalk is that you shouldn't need to SSH into the server. " 
     echo " ========== " 
+1

嗨@Tony,能否請你檢查我怎麼能得到錯誤,而我試圖 '命令: 03_attachment_directory_permission: 命令: 搭配chmod 777的/ var /應用/ ondeck/manellen /票/附件/' 並且它在日誌文件 – Manellen

+0

@Manellen中返回錯誤'因爲:(ElasticBeanstalk :: ExternalInvocationError)',你不應該使用註釋來提問。這個問題[已經被要求和回答](https://stackoverflow.com/questions/40357270/running-a-script-from-ebextensions-folder-in-aws-elastic-beanstalk),通常是由嘗試訪問尚不存在的路徑上的文件。 I.E .:當應用部署時,'/ home'尚不存在。在這個答案'/ etc/profile.d/myalias.sh'中創建的文件不存在。一切正在'/ var/app/ondeck'中準備。 –

-1

是的,你應該使用ebextensions。

在您的應用程序源根目錄中創建一個名爲.ebextensions的文件夾。創建一個.config擴展名爲01-folder-permissions.config的文件。文件按其名稱的字典順序處理。

文件的內容可以是:

container_commands: 
    change_permissions: 
     command: chmod 777 /var/www/some-folder 

替換相應的文件夾和權限。閱讀關於容器命令here

+0

當容器命令運行時'/ var/www'還不存在。 –

+6

chmod 777不好。從不777.無處。這是黑客的大獎。 –

相關問題