Hi,

I have a small VPS running my Rails app which is a personal website. I use SearchKick and that in turn uses ElasticSearch.

I find that ElasticSearch appears to fall over. I notice it mainly after a deploy. I had a similar issue with Delayed Job and was told I could set up a Capistrano task to restart that after each deploy. Code for that is below. That works fine but I don’t think I can do the same for ElasticSearch (I have tried and it didn’t work).

Anyone have any ideas as to how I can ensure ES is running properly after a deploy?

The code to restart Delayed Job is:

namespace :delayed_job do

    def args
      fetch(:delayed_job_args, "")
    end

    def delayed_job_roles
      fetch(:delayed_job_server_role, :app)
    end

    desc 'Stop the delayed_job process'
    task :stop do
      on roles(delayed_job_roles) do
        within release_path do
          with rails_env: fetch(:rails_env) do
            execute :bundle, :exec, :'bin/delayed_job', :stop
          end
        end
      end
    end

    desc 'Start the delayed_job process'
    task :start do
      on roles(delayed_job_roles) do
        within release_path do
          with rails_env: fetch(:rails_env) do
            execute :bundle, :exec, :'bin/delayed_job', args, :start
          end
        end
      end
    end

    desc 'Restart the delayed_job process'
    task :restart do
      on roles(delayed_job_roles) do
        within release_path do
          with rails_env: fetch(:rails_env) do
            execute :bundle, :exec, :'bin/delayed_job', args, :restart
          end
        end
      end
    end

  end

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi there @rctneil,

Do you see any errors in the log? Also is there any additional information your syslog?

You can take a look at this tutorial here on How To Use Journalctl to View and Manipulate Systemd Logs.

Feel free to share the output of the logs here as well.

Regards,
Bobby

by Justin Ellingwood
Some of the most compelling advantages of systemd are those involved with process and system logging. Using other systems, logs are usually dispersed throughout the system, handled by different daemons and tools, and can be fairly difficult to interpret when they span...
  • @bobbyiliev I don’t have logs as it’s been a little while since I restarted ES manually. I can try to post one as soon as it happens next time I deploy.

    • Any idea why it may be happening?
    • Any suggestions on how I could get it to auto-restart ES after a deploy?

    Neil

    • Hi there @rctneil,

      I’m not quite sure why it might be crashing, it is best to cross check the logs for more information which would point you to the right direction.

      Regarding the restart in case that the service crashes, what you could do is set the restart policy to always, so that systemctl would try to start the service in case it fails.

      To do so, run the following command:

      • sudo systemctl edit elasticsearch.service

      This creates a file at systemctl edit elasticsearch.service.

      Then add the following content:

      [Service]
      Restart=always
      

      After that refresh the unit files with:

      • sudo systemctl daemon-reload

      Then finally check if this was taken into account:

      • sudo systemctl cat elasticsearch.service

      Let me know how it goes.
      Regards,
      Bobby

Submit an Answer