module BinInstall::Brew::Service

Public Class Methods

restart(service) click to toggle source
# File lib/bin_install/brew/service.rb, line 52
def self.restart(service)
  system("brew services restart #{service}")
end
restart!(service) click to toggle source
# File lib/bin_install/brew/service.rb, line 56
def self.restart!(service)
  BinInstall.system!("brew services restart #{service}")
end
run(service) click to toggle source
# File lib/bin_install/brew/service.rb, line 4
def self.run(service)
  if started?(service)
    puts "Service #{service} already started. Skipping #{service} install.".blue
  else
    system("brew services run #{service}")
  end
end
run!(service) click to toggle source
# File lib/bin_install/brew/service.rb, line 12
def self.run!(service)
  if started?(service)
    puts "Service #{service} already started. Skipping #{service} install.".blue
  else
    BinInstall.system!("brew services run #{service}")
  end
end
services() click to toggle source
# File lib/bin_install/brew/service.rb, line 68
def self.services
  output = `brew services list`
  lines = output.split("\n")
  lines.shift # Remove header from table.

  lines.map do |row|
    columns = row.split(' ')
    [columns[0].to_sym, columns[1].to_sym]
  end.to_h
end
start(service) click to toggle source
# File lib/bin_install/brew/service.rb, line 20
def self.start(service)
  if started?(service)
    puts "Service #{service} already started. Skipping #{service} install.".blue
  else
    system("brew services start #{service}")
  end
end
start!(service) click to toggle source
# File lib/bin_install/brew/service.rb, line 28
def self.start!(service)
  if started?(service)
    puts "Service #{service} already started. Skipping #{service} install.".blue
  else
    BinInstall.system!("brew services start #{service}")
  end
end
started?(service) click to toggle source
# File lib/bin_install/brew/service.rb, line 60
def self.started?(service)
  services[service.to_sym] == :started
end
stop(service) click to toggle source
# File lib/bin_install/brew/service.rb, line 36
def self.stop(service)
  if stopped?(service)
    puts "Service #{service} already stopped. Skipping #{service} install.".blue
  else
    system("brew services stop #{service}")
  end
end
stop!(service) click to toggle source
# File lib/bin_install/brew/service.rb, line 44
def self.stop!(service)
  if stopped?(service)
    puts "Service #{service} already stopped. Skipping #{service} install.".blue
  else
    BinInstall.system!("brew services stop #{service}")
  end
end
stopped?(service) click to toggle source
# File lib/bin_install/brew/service.rb, line 64
def self.stopped?(service)
  services[service.to_sym] == :stopped
end