Sha256: 4d15de6eca06c489c2105f67008985fd81e005777f2e5a44ff5c645460528c49

Contents?: true

Size: 929 Bytes

Versions: 45

Compression:

Stored size: 929 Bytes

Contents

class Redde::SystemCommand
  attr_accessor :action

  ALLOWED_ACTIONS = %w(cache unicorn sidekiq reboot).freeze

  def self.execute(action)
    new(action).process
  end

  def initialize(action)
    @action = action
    Logger.new('log/commands.log').info "Received #{action} command"
    fail "Unsopported command #{action}. Allowed commands: #{ALLOWED_ACTIONS.join(', ')}" unless ALLOWED_ACTIONS.include?(action.to_s)
  end

  def process
    send(action)
  end

  private

  def cache
    `sudo service memcached restart`
  end

  def unicorn
    `sudo service #{project_name} restart`
  end

  def sidekiq
    system("sudo kill `cat #{Rails.root}/tmp/pids/sidekiq.pid` &&
      cd #{Rails.root} &&
      RAILS_ENV=#{Rails.env} bundle exec sidekiq -C config/sidekiq.yml -L log/sidekiq.log -d")
  end

  def reboot
    `sudo reboot`
  end

  def project_name
    Rails.root.to_s.gsub('/current', '').split('/').last
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
redde-0.4.4 app/models/redde/system_command.rb
redde-0.4.3 app/models/redde/system_command.rb
redde-0.4.2 app/models/redde/system_command.rb
redde-0.4.1 app/models/redde/system_command.rb
redde-0.4.0 app/models/redde/system_command.rb
redde-0.3.39 app/models/redde/system_command.rb
redde-0.3.38 app/models/redde/system_command.rb
redde-0.3.37 app/models/redde/system_command.rb
redde-0.3.36 app/models/redde/system_command.rb
redde-0.3.35 app/models/redde/system_command.rb
redde-0.3.34 app/models/redde/system_command.rb
redde-0.3.33 app/models/redde/system_command.rb
redde-0.3.32 app/models/redde/system_command.rb
redde-0.3.31 app/models/redde/system_command.rb
redde-0.3.30 app/models/redde/system_command.rb
redde-0.3.29 app/models/redde/system_command.rb
redde-0.3.28 app/models/redde/system_command.rb
redde-0.3.27 app/models/redde/system_command.rb
redde-0.3.26 app/models/redde/system_command.rb
redde-0.3.25 app/models/redde/system_command.rb