How to automatically restart delayed_job when deploying a rails project on Amazon Elastic Beanstalk?

后端 未结 4 1030
走了就别回头了
走了就别回头了 2020-12-05 05:42

I\'m hosting a rails project on Amazon Elastic Beanstalk and I try to configure a container command to automatically restart my delayed_job worker on the server after each d

4条回答
  •  一生所求
    2020-12-05 06:16

    On 64bit Amazon Linux 2014.09 v1.1.0 running Ruby 2.1 (Passenger Standalone), got it working thanks to this post.

    Note that this script is run as root, but your workers should be run as the webapp user.

    # Adds a post-deploy hook such that after a new version is deployed
    # successfully, restarts the delayed_job workers.
    #
    # http://stackoverflow.com/questions/14401204/how-to-automatically-restart-delayed-job-when-deploying-a-rails-project-on-amazo
    # http://www.dannemanne.com/posts/post-deployment_script_on_elastic_beanstalk_restart_delayed_job
    files:
      "/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_delayed_job.sh":
        mode: "000755"
        owner: root
        group: root
        encoding: plain
        content: |
          #!/usr/bin/env bash
    
          EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
          EB_APP_CURRENT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
          EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)
          EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
          EB_APP_PIDS_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_pid_dir)
    
          . $EB_SUPPORT_DIR/envvars
          . $EB_SCRIPT_DIR/use-app-ruby.sh
    
          cd $EB_APP_CURRENT_DIR
    
          # Switch to the webapp user.  Worker shouldn't be run as root.
          su -s /bin/bash -c "bundle exec bin/delayed_job --pid-dir=$EB_APP_PIDS_DIR restart" $EB_APP_USER
    

提交回复
热议问题