---
title: "Comment by Benjamin Silva Herrera on \"2 Amazon AWS Elastic Beanstalk extensions you need to work with Sidekiq\" | Hashnode"
description: "What happens if the process dies? you are not using a process manager like upstart, systemd or supervisord. We have al these scripts to manage sidekiq properly."
url: "https://hashnode.com/posts/2-amazon-aws-elastic-beanstalk-extensions-you-need-to-work-with-sidekiq/5fbeda3008c16c34b89c4889/comment/5fbef23ed73a0534d9b517fa"
---

[Discussion](https://hashnode.com/posts/2-amazon-aws-elastic-beanstalk-extensions-you-need-to-work-with-sidekiq/5fbeda3008c16c34b89c4889)

Comment [2 Amazon AWS Elastic Beanstalk extensions you need to work with Sidekiq](https://hashnode.com/posts/2-amazon-aws-elastic-beanstalk-extensions-you-need-to-work-with-sidekiq/5fbeda3008c16c34b89c4889)

[Benjamin Silva Herrera](https://hashnode.com/@silva96)

[Nov 26, 2020](https://hashnode.com/posts/2-amazon-aws-elastic-beanstalk-extensions-you-need-to-work-with-sidekiq/5fbeda3008c16c34b89c4889/comment/5fbef23ed73a0534d9b517fa)

What happens if the process dies? you are not using a process manager like upstart, systemd or supervisord.

We have al these scripts to manage sidekiq properly.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1606349190491/fFpkRvbf6.png)

```
commands:
  02_create_sidekiq_log_file:
    command: touch /var/log/sidekiq_worker.log
```

```
files:
  "/opt/elasticbeanstalk/support/conf/sidekiq_worker.conf":
    mode: "000755"
    owner: root
    group: root
    content: |
      description "Elastic Beanstalk Sidekiq Background Worker"

      # Greatly reduce Ruby memory fragmentation and heap usage
      # mikeperham.com/2018/04/25/taming-rails-memory-blo…
      env MALLOC_ARENA_MAX=2

      respawn
      respawn limit 3 30

      # TERM is sent by sidekiqctl when stopping sidekiq. Without declaring these as
      # normal exit codes, it just respawns.
      normal exit 0 TERM

      # Upstart waits 5 seconds by default to kill a process. Increase timeout to
      # give sidekiq process enough time to exit.
      kill timeout 30

      script
      exec /bin/bash <<"EOT"
        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_SUPPORT_DIR/envvars
        . $EB_SCRIPT_DIR/use-app-ruby.sh

        EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)

        cd $EB_APP_DEPLOY_DIR
        echo "Bundle exec sidekiq worker"
        exec bundle exec sidekiq -e ${RACK_ENV} \
          -C ${EB_APP_DEPLOY_DIR}/config/sidekiq.yml >/var/log/sidekiq_worker.log 2>&1
      EOT
      end script
```

```
files:
  "/etc/init/sidekiq_worker.conf":
    mode: "120400"
    content: "/opt/elasticbeanstalk/support/conf/sidekiq_worker.conf"
  "/etc/init/workers.conf":
    mode: "000755"
    owner: root
    group: root
    content: |
      description "Manages the Set of Sidekiq Processes"

      # Use "sudo stop workers" to stop all Sidekiq instances.
      # Use "sudo start workers" to start all instances.
      # Use "sudo restart workers" to restart all instances.

      # This starts upon bootup and stops on shutdown
      start on runlevel [2345]
      stop on runlevel [06]

      pre-start script
        sudo start sidekiq_worker
      end script

      post-stop script
        sudo stop sidekiq_worker
      end script

commands:
  reload_initctl_for_sidekiq:
    command: "sudo initctl reload-configuration"
```

```
files:
  "/tmp/sidekiq_mute.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash
      skwpid=$(initctl status sidekiq_worker | grep /running | awk '{print $NF}')
      if [ -f skwpid ]
      then
        echo "TSTP/quieting sidekiq worker"
        sudo kill -TSTP skwpid
      fi
```

```
files:
  "/tmp/sidekiq_restart.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash
      skwpid=$(initctl status sidekiq_worker | grep /running | awk '{print $NF}')
      if [ -f skwpid ]
      then
        echo "TERM/terminating sidekiq worker"
        sudo kill -TERM skwpid
      fi

      echo "STOPPING all sidekiq workers"
      sudo stop workers

      echo "STARTING all sidekiq workers"
      sudo start workers
```

```
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq.sh":
    mode: "120755"
    owner: root
    group: root
    content: "/tmp/sidekiq_restart.sh"

  "/opt/elasticbeanstalk/hooks/configdeploy/post/50_restart_sidekiq.sh":
    mode: "120755"
    owner: root
    group: root
    content: "/tmp/sidekiq_restart.sh"

  "/opt/elasticbeanstalk/hooks/restartappserver/post/50_restart_sidekiq.sh":
    mode: "120755"
    owner: root
    group: root
    content: "/tmp/sidekiq_restart.sh"

  "/opt/elasticbeanstalk/hooks/appdeploy/pre/03_mute_sidekiq.sh":
    mode: "120755"
    owner: root
    group: root
    content: "/tmp/sidekiq_mute.sh"

  "/opt/elasticbeanstalk/hooks/configdeploy/pre/03_mute_sidekiq.sh":
    mode: "120755"
    owner: root
    group: root
    content: "/tmp/sidekiq_mute.sh"

  "/opt/elasticbeanstalk/hooks/restartappserver/pre/03_mute_sidekiq.sh":
    mode: "120755"
    owner: root
    group: root
    content: "/tmp/sidekiq_mute.sh"
```

[Piotr Jurewicz](https://hashnode.com/@pjurewicz)

[Nov 26, 2020](https://hashnode.com/posts/2-amazon-aws-elastic-beanstalk-extensions-you-need-to-work-with-sidekiq/5fbeda3008c16c34b89c4889/comment/5fbef23ed73a0534d9b517fa#reply-5fbfa86006727f3ebc094b13)

Hi Benjamin. Since I've been using monit to control memory consumption, I have no longer problems with system killing Sidekiq processes. However, thanks a lot for sharing your scripts. They can be very useful.

[Benjamin Silva Herrera](https://hashnode.com/@silva96)

[Nov 26, 2020](https://hashnode.com/posts/2-amazon-aws-elastic-beanstalk-extensions-you-need-to-work-with-sidekiq/5fbeda3008c16c34b89c4889/comment/5fbef23ed73a0534d9b517fa#reply-5fbfc565b27eed41baa5c7e1)

[Piotr Jurewicz](https://hashnode.com/@pjurewicz) Yes that's a good way to tackle down "most" of possible sources that can cause a process to die. But of course there might be other. For instance, if you have your rails app in the same instance, it can grow in ram too, so even having sidekiq with low memory usage, the system can enter a "resource starvation" state and the Kernel would kill proceses to safeguard the system state. The way the Kernel chooses this proceses is based in many factors, so there's still chance your sidekiq dies.
