Elastic Beanstalk" webapp"容器命令期间不存在或错误原因?

时间:2016-02-21 03:23:28

标签: amazon-web-services deployment elastic-beanstalk amazon-elastic-beanstalk

如果新创建了我的自动缩放实例,则会出现此错误。

Exited with error code 1

这是.ebextensions/crons.config中的脚本:

container_commands:
  01_cronjobs:
    command: dos2unix scripts/wp-cron.sh && su -s /bin/bash -c "scripts/wp-cron.sh" webapp
    leader_only: true

这是scripts/wp-cron.sh背后的脚本。

#!/bin/bash

# BACKUP EXISTING CRONTAB
crontab -l > /tmp/cronjob

# REMOVE EXISTING CUSTOM JOBS TO AVOID DUPLICATES
cat /tmp/cronjob | grep -v "/wp-cron.php" > /tmp/cronjob

# NEW CRONJOB RULES
echo "*/5 * * * * /usr/bin/php -f /var/app/current/wp-cron.php > /dev/null 2>&1" >> /tmp/cronjob

crontab /tmp/cronjob
rm /tmp/cronjob
echo 'Script successfully executed, crontab updated.'

webapp用户是否可能不存在?但我认为container_commands仅在应用程序准备好后执行?

这是日志文件的结尾。

inflating: /var/app/ondeck/wp-cron.php
  + chown -R webapp:webapp /var/app/ondeck
  + chmod 775 /var/app/ondeck
[2016-02-21T03:03:21.008Z] INFO  [2630]  - [Application deployment/StartupStage0/AppDeployPreHook/02_setup_envvars.sh] : Starting activity...
[2016-02-21T03:03:21.504Z] INFO  [2630]  - [Application deployment/StartupStage0/AppDeployPreHook/02_setup_envvars.sh] : Completed activity.
[2016-02-21T03:03:22.198Z] INFO  [2630]  - [Application deployment/StartupStage0/AppDeployPreHook/05_configure_php.sh] : Starting activity...
[2016-02-21T03:03:23.692Z] INFO  [2630]  - [Application deployment/StartupStage0/AppDeployPreHook/05_configure_php.sh] : Completed activity. Result:
  Using configuration value for DocumentRoot:
[2016-02-21T03:03:23.693Z] INFO  [2630]  - [Application deployment/StartupStage0/AppDeployPreHook/10_composer_install.sh] : Starting activity...
[2016-02-21T03:03:23.794Z] INFO  [2630]  - [Application deployment/StartupStage0/AppDeployPreHook/10_composer_install.sh] : Completed activity. Result:
  + . /opt/elasticbeanstalk/support/envvars
  ++ export RDS_PORT=3306
  ++ RDS_PORT=3306
  ++ export RDS_PASSWORD=something
  ++ RDS_PASSWORD=something
  ++ export RDS_USERNAME=test
  ++ RDS_USERNAME=test
  ++ export RDS_HOSTNAME=something.something.eu-central-1.rds.amazonaws.com
  ++ RDS_HOSTNAME=something.something.eu-central-1.rds.amazonaws.com
  ++ export RDS_DB_NAME=ebdb
  ++ RDS_DB_NAME=ebdb
  ++ export PHP_MEMORY_LIMIT=256M
  ++ PHP_MEMORY_LIMIT=256M
  ++ export PHP_MAX_EXECUTION_TIME=60
  ++ PHP_MAX_EXECUTION_TIME=60
  ++ export PHP_DISPLAY_ERRORS=Off
  ++ PHP_DISPLAY_ERRORS=Off
  ++ export PHP_COMPOSER_OPTIONS=
  ++ PHP_COMPOSER_OPTIONS=
  ++ export PHP_ALLOW_URL_FOPEN=On
  ++ PHP_ALLOW_URL_FOPEN=On
  ++ export PHP_ZLIB_OUTPUT_COMPRESSION=Off
  ++ PHP_ZLIB_OUTPUT_COMPRESSION=Off
  ++ export PHP_DOCUMENT_ROOT=
  ++ PHP_DOCUMENT_ROOT=
  ++ export PHP_DATE_TIMEZONE=UTC
  ++ PHP_DATE_TIMEZONE=UTC
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
  + EB_APP_STAGING_DIR=/var/app/ondeck
  + cd /var/app/ondeck
  + '[' -f composer.json ']'
  + echo 'No composer.json file detected'
  No composer.json file detected
[2016-02-21T03:03:23.794Z] INFO  [2630]  - [Application deployment/StartupStage0/AppDeployPreHook/12_update_permissions.sh] : Starting activity...
[2016-02-21T03:03:24.236Z] INFO  [2630]  - [Application deployment/StartupStage0/AppDeployPreHook/12_update_permissions.sh] : Completed activity. Result:
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_user
  + EB_APP_USER=webapp
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_base_dir
  + EB_APP_BASE_DIR=/var/app
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
  + EB_APP_STAGING_DIR=/var/app/ondeck
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_logs_dir
  + EB_APP_LOGS_DIR=/var/app/support/logs
  + cd /var/app/ondeck
  + chown -R webapp:webapp /var/app
  + chown -R webapp:webapp /var/log/httpd
  + '[' -f app/SymfonyRequirements.php ']'
[2016-02-21T03:03:24.236Z] INFO  [2630]  - [Application deployment/StartupStage0/AppDeployPreHook] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/pre.
[2016-02-21T03:03:24.236Z] INFO  [2630]  - [Application deployment/StartupStage0/EbExtensionPostBuild] : Starting activity...
[2016-02-21T03:03:31.346Z] INFO  [2630]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Starting activity...
[2016-02-21T03:03:31.347Z] INFO  [2630]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_EXAMPLE_com] : Starting activity...
[2016-02-21T03:03:31.729Z] INFO  [2630]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_EXAMPLE_com/Test for Command 01_cronjobs] : Starting activity...
[2016-02-21T03:03:31.732Z] INFO  [2630]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_EXAMPLE_com/Test for Command 01_cronjobs] : Completed activity. Result:

  Exited with error code 1
[2016-02-21T03:03:31.732Z] INFO  [2630]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_EXAMPLE_com] : Completed activity.

提前感谢您的任何想法!

// edit:调试的一个例子

[2016-02-23T01:08:26.149Z] INFO  [2631]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Starting activity...
[2016-02-23T01:08:26.150Z] INFO  [2631]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_EXAMPLE_com] : Starting activity...
[2016-02-23T01:08:26.479Z] INFO  [2631]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_EXAMPLE_com/Command 01_clear_cronjobs] : Starting activity...
[2016-02-23T01:08:26.482Z] INFO  [2631]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_EXAMPLE_com/Command 01_clear_cronjobs] : Completed activity.
[2016-02-23T01:08:26.812Z] INFO  [2631]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_EXAMPLE_com/Test for Command 02_add_cronjobs] : Starting activity...
[2016-02-23T01:08:26.815Z] INFO  [2631]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_EXAMPLE_com/Test for Command 02_add_cronjobs] : Completed activity. Result:

Exited with error code 1
[2016-02-23T01:08:26.815Z] INFO  [2631]  - [Application deployment/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_EXAMPLE_com] : Completed activity.

那就是脚本。

    container_commands:
      01_clear_cronjobs:
        command: "rm /etc/cron.d/app_jobs > /dev/null 2>&1 || exit 0"
      02_add_cronjobs:
        command: "whoamid && cat .ebextensions/cronjobs.txt && cat .ebextensions/cronjobs.txt > /etc/cron.d/app_jobs && chmod 644 /etc/cron.d/app_jobs"
        leader_only: true

有些时候它有效,有些时候(重新创建没有)。 我认为它是"测试"哪个失败了?或者是only_leader选项有问题吗?

我想知道为什么" whoami"不写日志中的东西。在工作场景中他们做到了......

1 个答案:

答案 0 :(得分:0)

正如您在日志开头看到的那样,您会看到第chown -R webapp:webapp /var/app/ondeck行。

这意味着webapp用户确实存在。为什么你认为这是容器命令失败的原因?您需要向容器命令添加更多日志记录,以便进行调试。