class Shred::Commands::Services

Attributes

supported_services[R]

Public Instance Methods

configure() click to toggle source
# File lib/shred/commands/services.rb, line 109
def configure
  @supported_services = command_config.each_with_object([]) do |(type, specs), m|
    case type.to_sym
    when :launchctl
      specs.each_with_object(m) do |(svc, keys), mm|
        plist = keys['plist'] or
          raise "Missing 'plist' config for '#{svc}' platform service"
        mm << LaunchctlService.new(
          sym: svc.to_sym,
          plist: plist
        )
      end
    when :shell
      specs.each_with_object(m) do |(svc, keys), mm|
        start = keys['start'] or
          raise "Missing 'start' config for '#{svc}' platform service"
        stop = keys['stop'] or
          raise "Missing 'stop' config for '#{svc}' platform service"
        mm << ShellCommandService.new(
          sym: svc.to_sym,
          start_command_lines: start,
          stop_command_lines: stop
        )
      end
    else raise "Unknown platform service type #{type}"
    end
  end
end
invoke_for_services(meth, *services) click to toggle source
# File lib/shred/commands/services.rb, line 138
def invoke_for_services(meth, *services)
  services = supported_services.map { |d| d.sym.to_s} if services.empty?
  services.each do |service|
    service = supported_services.detect { |d| d.sym.to_s == service }
    if service
      service.send(meth, self)
    else
      say_err("No such service #{service}")
    end
  end
end
restart(*services) click to toggle source
# File lib/shred/commands/services.rb, line 104
def restart(*services)
  invoke_for_services(:restart, *services)
end
start(*services) click to toggle source
# File lib/shred/commands/services.rb, line 80
def start(*services)
  invoke_for_services(:start, *services)
end
stop(*services) click to toggle source
# File lib/shred/commands/services.rb, line 92
def stop(*services)
  invoke_for_services(:stop, *services)
end