1

Я установил жемчужину: всякий раз, когда-эластичный мешок, но я не могу установить его правильно, что не так?Cron Job with Whenever Gem, не работает в амазонке эластичный beanstalk

Ошибки:

[2015-02-03T22:34:04.789Z] INFO [19261] - [CMD- 

AppDeploy/AppDeployStage0/AppDeployPreHook] : Completed activity. Result: 
    Successfully execute directory: /opt/elasticbeanstalk/hooks/appdeploy/pre. 
[2015-02-03T22:34:04.789Z] INFO [19261] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] : Starting activity... 
[2015-02-03T22:34:06.365Z] INFO [19261] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] : Activity execution failed, because: command failed with error code 1: Error occurred during build: Command cron_01_set_leader failed (Executor::NonZeroExitStatus) 
    at /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/executor-1.0/lib/executor/exec.rb:81:in `sh' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/executor-1.0/lib/executor/exec.rb:24:in `sh' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/cfn-wrapper.rb:51:in `call_cfn_script' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/cfn-wrapper.rb:28:in `run_config_sets' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/infrahooks/infra-embeddedpostbuild.rb:20:in `execute!' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/executable.rb:56:in `instance_eval' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/executable.rb:56:in `execute!' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:213:in `block (3 levels) in exec_stage' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `call' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `exec' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:126:in `timeout_exec' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:110:in `block in create' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `instance_eval' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `create' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:209:in `block (2 levels) in exec_stage' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:207:in `each' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:207:in `each_with_index' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:207:in `block in exec_stage' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `call' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `exec' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:126:in `timeout_exec' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:110:in `block in create' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `instance_eval' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `create' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:204:in `exec_stage' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:158:in `execute!' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:68:in `run' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command-processor.rb:64:in `block (2 levels) in execute!' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `call' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `exec' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:126:in `timeout_exec' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:110:in `block in create' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `instance_eval' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `create' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command-processor.rb:62:in `block in execute!' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command-processor.rb:106:in `execute_command' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command-processor.rb:60:in `execute!' 
    from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/bin/command-processor:46:in `<top (required)>' 
    from /opt/elasticbeanstalk/lib/ruby/bin/command-processor:23:in `load' 
    from /opt/elasticbeanstalk/lib/ruby/bin/command-processor:23:in `<main>' 

cron.config

files: 
# Reload the on deployment 
    /opt/elasticbeanstalk/hooks/appdeploy/post/10_reload_cron.sh: 
    mode: "00700" 
    owner: root 
    group: root 
    content: | 
     #!/usr/bin/env bash 
     . /opt/elasticbeanstalk/containerfiles/envvars 
     cd $EB_CONFIG_APP_CURRENT 
     su -c "/usr/local/bin/bundle exec setup_cron" $EB_CONFIG_APP_USER 
    # Add Bundle to the PATH 
    "/etc/profile.d/bundle.sh": 
    mode: "000755" 
    owner: root 
    group: root 
    content: | 
     #!/usr/bin/env bash 
     export PATH=$PATH:/usr/local/bin 
    encoding: plain 
container_commands: 
    cron_01_set_leader: 
    test: test ! -f /opt/elasticbeanstalk/containerfiles/.cron-setup-complete 
    leader_only: true 
    cwd: /var/app/ondeck 
    command: su -c "/usr/local/bin/bundle exec create_cron_leader --no-update" $EB_CONFIG_APP_USER 
    cron_02_write_cron_setup_complete_file: 
    cwd: /opt/elasticbeanstalk/containerfiles 
    command: touch .cron-setup-complete 

политика:

{ 
    "Version": "2012-10-17", 
    "Statement": [ 
    { 
     "Action": "ec2:*", 
     "Effect": "Allow", 
     "Resource": "*" 
    }, 
    { 
     "Effect": "Allow", 
     "Action": "elasticloadbalancing:*", 
     "Resource": "*" 
    }, 
    { 
     "Effect": "Allow", 
     "Action": "cloudwatch:*", 
     "Resource": "*" 
    }, 
    { 
     "Effect": "Allow", 
     "Action": "autoscaling:*", 
     "Resource": "*" 
    } 
    ] 
} 

Некоторые подсказки для этой проблемы? Что означает константа $ EB_CONFIG_APP_USER, когда я ее определяю?

ответ

4

Какую версию Усиливающего бобового AMI вы используете? Начиная с 2014.09, старые переменные среды (например, $ EB_CONFIG_APP_USER) не работают. См. ПРЕДУПРЕЖДЕНИЕ в верхней части всякий раз, когда-elasticbeanstalk readme и это драгоценный камень Issue 18.

Они могут обновлять всякий раз, когда используется эластичный жемчуг, для обработки нового подхода к изменению среды, но тем временем вы, вероятно, застряли в использовании по умолчанию whenever gem и записываете свой собственный код для вызова whenever --update. Мой every-cron.config выглядит так. Обратите внимание, что он не обрабатывает опцию «только лидера».

# Use the whenever gem to update webapp's crontab from config/schedule.rb after successful deployment 
# See notes in Gemfile re. "whenever" vs. "whenever-elasticbeanstalk" 

# Adapted from http://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts/ 
# with environment corrections from 
# http://www.dannemanne.com/posts/post-deployment_script_on_elastic_beanstalk_restart_cron-whenever 

commands: 
    70.1-create-post-dir: 
    # "mkdir -p" ignores error if directory already exists 
    command: "mkdir -p /opt/elasticbeanstalk/hooks/appdeploy/post" 

files: 
    "/opt/elasticbeanstalk/hooks/appdeploy/post/70-update_cron_from_whenever.sh": 
    mode: "000755" 
    owner: root 
    group: root 
    content: | 
     #!/usr/bin/env bash 

     # Load environment data 
     EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir) 
     EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir) 
     EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user) 
     EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir) 
     # Export EB_APP_LOG_DIR so we can access it when running "whenever" below, 
     # which accesses config/schedule.rb, which uses EB_APP_LOG_DIR. 
     export EB_APP_LOG_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_log_dir) 

     # Make sure the cron-whenever.log exists and is owned by $EB_APP_USER 
     touch $EB_APP_LOG_DIR/cron-whenever.log 
     chown $EB_APP_USER:$EB_APP_USER $EB_APP_LOG_DIR/cron-whenever.log 

     # cron requires a home directory. Make sure it exists and is owned by $EB_APP_USER. 
     mkdir -p /home/$EB_APP_USER 
     chown $EB_APP_USER:$EB_APP_USER /home/$EB_APP_USER 

     # Set up correct environment and ruby version so that bundle can load all gems 
     . $EB_SUPPORT_DIR/envvars 
     . $EB_SCRIPT_DIR/use-app-ruby.sh 

     # Run the whenever --update command to update the cron job for $EB_APP_USER. 
     cd $EB_APP_DEPLOY_DIR 
     whenever --update -u $EB_APP_USER 

     # After setup, you can run "crontab -l -u webapp" to check the configuration.