0
votes

I have a rails app that uses rescue. The app is deployed using elastic beanstalk (64bit Amazon Linux 2015.09 v2.0.6 running Ruby 2.1 (Passenger Standalone)) and I am trying to use monit to run rescue. After some research .ebextensions seem to be the way to go. However it looks as if the file is being ignored. I don't see the file (/var/app/current/tmp/success) I put to debug things being written, monit is not installed and the monit config file is not being created.

myapp
  .ebextensions
     99run.config

Here is the contents of 99run.config

packages:
  yum:
    monit: []

files:
  "/etc/monit.d/resque_worker":
    mode: "000644"
    owner: root
    group: root
    content: |
      check process resque_worker_QUEUE
        with pidfile /var/app/current/tmp/resque_worker_QUEUE.pid
        start program = "/bin/sh -l -c 'cd /var/app/current; nohup rake environment resque:work QUEUE=* VERBOSE=1 PIDFILE=/var/app/current/tmp/resque_worker_QUEUE.pid >> /var/app/current/log/resque_worker_QUEUE.log 2>&1'" as uid webapp and gid webapp
        stop program = "/bin/sh -c 'cd /var/app/current && kill -9 $(cat /var/app/current/tmp/resque_worker_QUEUE.pid) && rm -f /var/app/current/tmp/resque_worker_QUEUE.pid; exit 0;'"
        if totalmem is greater than 300 MB for 10 cycles then restart  # eating up memory?
        group resque_workers

commands:
  test_command:
    command: echo "ebextensions ran" > /var/app/current/tmp/success


service:
  sysvinit:
    monit:
      ensureRunning: true
      enabled: true
1

1 Answers

1
votes

You'res pretty close - I'm using a very similar structure successfully. (I imagine we both started with the same blog post...) A couple of comments, though:

Your test_command isn't producing the results you want because the success file is being overwritten. Per the documentation:

You can use the commands key to execute commands on the EC2 instance. The commands are processed in alphabetical order by name, and they run before the application and web server are set up and the application version file is extracted.

What's happening is that success is being written to /var/app/current/tmp while your application is being deployed to /var/app/ondeck. Later, /var/app/current is deleted and /var/app/ondeck is renamed to /var/app/current, eliminating the success file.

Next, there's a typo in this block:

service:
  sysvinit:
    monit:

It should be services instead:

services:
  sysvinit:
    monit:

Lastly, I had to tell monit to explictly start and stop resque during each deploy by adding the following to the files section:

"/opt/elasticbeanstalk/hooks/appdeploy/post/98_start_resque.sh":
  mode: "000755"
  owner: root
  group: root
  content: |
    #!/usr/bin/env bash

    su -s /bin/bash -c "monit start resque_worker_QUEUE"

and the following commands:

commands:
  01_remove_worker_bak:
    command: "rm /etc/monit.d/resque_worker_QUEUE.bak"
    ignoreErrors: true
  02_stop_worker:
    command: "monit stop resque_worker_QUEUE"
    ignoreErrors: true