Sha256: ebed9c7b25e85d150838ebcf50b94783affdffff18df8823a500ee477b4b6a1d

Contents?: true

Size: 1.21 KB

Versions: 25

Compression:

Stored size: 1.21 KB

Contents

#!/usr/bin/env ruby

require 'fileutils'

class Sidekiqctl

  attr_reader :stage, :pidfile, :timeout

  def initialize(stage, pidfile, timeout)
    @stage = stage
    @pidfile = pidfile
    @timeout = timeout

    done 'No pidfile given' if !pidfile
    done "Pidfile #{pidfile} does not exist" if !File.exist?(pidfile)
    done 'Invalid pidfile content' if pid == 0

    fetch_process

    begin
      send(stage)
    rescue NoMethodError
      done 'Invalid control command'
    end
  end

  def fetch_process
    Process.getpgid(pid)
  rescue Errno::ESRCH
    done "Process doesn't exist"
  end

  def done(msg)
    puts msg
    exit(0)
  end

  def pid
    File.read(pidfile).to_i
  end

  def quiet
    `kill -USR1 #{pid}`
  end

  def stop
    `kill -TERM #{pid}`
    timeout.times do
      begin
        Process.getpgid(pid)
      rescue Errno::ESRCH
        FileUtils.rm_f pidfile
        done 'Sidekiq shut down gracefully.'
      end
      sleep 1
    end
    `kill -9 #{pid}`
    FileUtils.rm_f pidfile
    done 'Sidekiq shut down forcefully.'
  end

  def shutdown
    quiet
    stop
  end

end

stage = ARGV[0]
pidfile = ARGV[1]
timeout = ARGV[2].to_i
timeout = 10 if timeout == 0

Sidekiqctl.new(stage, pidfile, timeout)

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
sidekiq-2.6.2 bin/sidekiqctl
sidekiq-2.6.1 bin/sidekiqctl
sidekiq-2.6.0 bin/sidekiqctl
sidekiq-2.5.4 bin/sidekiqctl
sidekiq-2.5.3 bin/sidekiqctl
sidekiq-2.5.2 bin/sidekiqctl
sidekiq-2.5.1 bin/sidekiqctl
sidekiq-2.5.0 bin/sidekiqctl
sidekiq-2.4.0 bin/sidekiqctl
sidekiq-2.3.3 bin/sidekiqctl
sidekiq-2.3.2 bin/sidekiqctl
sidekiq-2.3.1 bin/sidekiqctl
sidekiq-2.3.0 bin/sidekiqctl
sidekiq-2.2.1 bin/sidekiqctl
sidekiq-2.2.0 bin/sidekiqctl
sidekiq-2.1.1 bin/sidekiqctl
sidekiq-2.1.0 bin/sidekiqctl
sidekiq-2.0.3 bin/sidekiqctl
sidekiq-2.0.2 bin/sidekiqctl
sidekiq-2.0.1 bin/sidekiqctl