4

AWS Elastic Beanstalk へのデプロイ中に、次の 2 つのことを行いたいと考えています。

  1. cron エントリを含むファイルを取得し、このファイルを /etc/cron.d/ に配置します
  2. 単一のディレクトリに含まれるシェル スクリプトのファイル アクセス許可を変更して、cron で実行できるようにします。

私の .ebextensions フォルダーには、次のものがあります。

container_commands:
  00fix_script_permissions:
    command: "chmod u+x /var/app/current/scripts/*"
  01setup_cron:
    command: "cat .ebextensions/propel_mis_crons.txt > /etc/cron.d/propel_mis_crons && chmod 644 /etc/cron.d/propel_mis_crons"
    leader_only: true

また、.ebextensions フォルダーの propel_mis_crons.txt には次の内容があります。

# m h  dom mon dow   command
MAILTO="dev@23sparks.com"
* * * * * root /var/app/current/scripts/current_time.sh

デプロイ ログを確認したところ、次のことがわかります。

2013-08-09 14:27:13,633 [DEBUG] Running command 00fix_permissions_dirs
2013-08-09 14:27:13,633 [DEBUG] Generating defaults for command 00fix_permissions_dirs
<<< 
2013-08-09 14:27:13,736 [DEBUG] No test for command 00fix_permissions_dirs
2013-08-09 14:27:13,752 [INFO] Command 00fix_permissions_dirs succeeded
2013-08-09 14:27:13,753 [DEBUG] Command 00fix_permissions_dirs output: 
2013-08-09 14:27:13,753 [DEBUG] Running command 01setup_cron
2013-08-09 14:27:13,753 [DEBUG] Generating defaults for command 01setup_cron
<<<
2013-08-09 14:27:13,829 [DEBUG] Running test for command 01setup_cron
2013-08-09 14:27:13,846 [DEBUG] Test command output: 
2013-08-09 14:27:13,847 [DEBUG] Test for command 01setup_cron passed
2013-08-09 14:27:13,871 [INFO] Command 01setup_cron succeeded
2013-08-09 14:27:13,872 [DEBUG] Command 01setup_cron output:

ただし、展開時に、スクリプト ディレクトリ内のすべてのファイルに対するアクセス許可が正しく設定されておらず、cron が実行されません。権限の問題が原因で実行されていないcronが実行されていないのか、それともこれを妨げている何かがあるのか​​ わかりません。これは、PHP5.4 64 ビット Amazon Linux インスタンスで実行されています。

これに関するいくつかの支援をいただければ幸いです。今後、cron によってトリガーされる新しいシェル スクリプトが追加される可能性は十分にあります。

4

2 に答える 2

3
container_commands:
00_fix_script_permissions:
command: "chmod u+x /opt/python/ondeck/app/scripts/*"

私は Linux と AWS 初心者ですが、上記のようにコマンドを変更すると、私のユース ケースでは成功することがわかりました。

/opt/python/current/app/scripts/createadmin にユーザーの実行権限が付与されました

于 2013-08-26T15:49:40.367 に答える
3

@Edは、ondeckファイルではなくファイルをchmodすることを提案するところが正しいようcurrentです。

さらに、これは Elastic Beanstalk .config ファイルを使用して cron ジョブをセットアップする方法です。確かに最善の方法ではないかもしれませんが、私のアプリケーションではうまくいきます。

`"files":{
    "/home/ec2-user/cronjobs.txt":{
        "mode":"000777",
        "owner":"ec2-user",
        "group":"ec2-user",
        "source":"https://s3.amazonaws.com/xxxxxxxxxx/cronjobs.txt"
    }
}
"container_commands":{
    "01-setupcron":{
     "command": "crontab /home/ec2-user/cronjobs.txt -u ec2-user",
     "leader_only": true
    },`

まず、cronjobs テキスト ファイルを取り込み、ec2-user フォルダーに保存します。次に、container_commands で、そのファイルを crontab に適用します。

繰り返しますが、私は専門家ではありません。

于 2014-01-07T19:34:13.497 に答える