Sha256: 433b0795eb9cafa97138edfe2a9381cb5280015ea68ae94179a4165df1141127

Contents?: true

Size: 2 KB

Versions: 15

Compression:

Stored size: 2 KB

Contents

module BinInstall
  module Brew
    module Service
      def self.run(service)
        if started?(service)
          puts "Service #{service} already started. Skipping.".blue
        else
          system("brew services run #{service}")
        end
      end

      def self.run!(service)
        if started?(service)
          puts "Service #{service} already started. Skipping.".blue
        else
          BinInstall.system!("brew services run #{service}")
        end
      end

      def self.start(service)
        if started?(service)
          puts "Service #{service} already started. Skipping.".blue
        else
          system("brew services start #{service}")
        end
      end

      def self.start!(service)
        if started?(service)
          puts "Service #{service} already started. Skipping.".blue
        else
          BinInstall.system!("brew services start #{service}")
        end
      end

      def self.stop(service)
        if stopped?(service)
          puts "Service #{service} already stopped. Skipping.".blue
        else
          system("brew services stop #{service}")
        end
      end

      def self.stop!(service)
        if stopped?(service)
          puts "Service #{service} already stopped. Skipping.".blue
        else
          BinInstall.system!("brew services stop #{service}")
        end
      end

      def self.restart(service)
        system("brew services restart #{service}")
      end

      def self.restart!(service)
        BinInstall.system!("brew services restart #{service}")
      end

      def self.started?(service)
        services[service.to_sym] == :started
      end

      def self.stopped?(service)
        services[service.to_sym] == :stopped
      end

      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
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
bin_install-0.0.23 lib/bin_install/brew/service.rb
bin_install-0.0.22 lib/bin_install/brew/service.rb
bin_install-0.0.21 lib/bin_install/brew/service.rb
bin_install-0.0.20 lib/bin_install/brew/service.rb
bin_install-0.0.19 lib/bin_install/brew/service.rb
bin_install-0.0.18 lib/bin_install/brew/service.rb
bin_install-0.0.17 lib/bin_install/brew/service.rb
bin_install-0.0.16 lib/bin_install/brew/service.rb
bin_install-0.0.15 lib/bin_install/brew/service.rb
bin_install-0.0.14 lib/bin_install/brew/service.rb
bin_install-0.0.13 lib/bin_install/brew/service.rb
bin_install-0.0.12 lib/bin_install/brew/service.rb
bin_install-0.0.11 lib/bin_install/brew/service.rb
bin_install-0.0.10 lib/bin_install/brew/service.rb
bin_install-0.0.9 lib/bin_install/brew/service.rb