Sha256: 9f2d68916dfb2e506772806c171f0e9c130c9e7c915a2db036edb84ca49c14dd

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'capistrano/configuration'


module Capistrano
  module ForemanExport
    module Backend
      class Supervisord

        def initialize(task)
          @task = task
        end

        def name
          "supervisord"
        end

        def app_name
          @task.fetch(:foreman_app)
        end

        def start_cmd
          add_or_update_app
          @task.execute(:sudo, "supervisorctl start #{app_name}:*")
        end

        def stop_cmd
          @task.execute(:sudo, "supervisorctl stop #{app_name}:*")
        end

        def restart_cmd
          add_or_update_app
          @task.execute(:sudo, "supervisorctl restart #{app_name}:*")
        end

        def add_or_update_app
          status = supervisord_reread
          if status.include?("#{app_name}:")
            if status.include?('changed')
              @task.info("Configration changed, update it.")
              @task.execute(:sudo, "supervisorctl update #{app_name}")
            elsif status.include('available')
              @task.info("Configration available, add it.")
              @task.execute(:sudo, "supervisorctl add #{app_name}")
            end
          end
        end

        def supervisord_reread
          @task.capture(:sudo, %{supervisorctl reread})
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capistrano-foreman_export-0.0.3 lib/capistrano/foreman_export/backend/supervisord.rb