Sha256: 990047d3997bb63fda8fee4dd94b282fda1e340e4007d67b7599a952cee697fc

Contents?: true

Size: 1.04 KB

Versions: 22

Compression:

Stored size: 1.04 KB

Contents

# LinuxAdmin Service Representation
#
# Copyright (C) 2013 Red Hat Inc.
# Licensed under the MIT License

class LinuxAdmin
  class Service < LinuxAdmin
    attr_accessor :id

    private

    public

    def initialize(id)
      @id = id
    end

    def running?
      run(cmd(:service),
          :params => { nil => [id, "status"] }).exit_status == 0
    end

    def enable
      run!(cmd(:chkconfig),
          :params => { nil => [id, "on"] })
      self
    end

    def disable
      run!(cmd(:chkconfig),
          :params => { nil => [id, "off"] })
      self
    end

    def start
      run!(cmd(:service),
          :params => { nil => [id, "start"] })
      self
    end

    def stop
      run!(cmd(:service),
          :params => { nil => [id, "stop"] })
      self
    end

    def restart
      status =
        run(cmd(:service),
          :params => { nil => [id, "restart"] }).exit_status

      # attempt to manually stop/start if restart fails
      if status != 0
        self.stop
        self.start
      end

      self
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
linux_admin-0.9.4 lib/linux_admin/service.rb
linux_admin-0.9.3 lib/linux_admin/service.rb
linux_admin-0.9.2 lib/linux_admin/service.rb
linux_admin-0.9.1 lib/linux_admin/service.rb
linux_admin-0.9.0 lib/linux_admin/service.rb
linux_admin-0.8.1 lib/linux_admin/service.rb
linux_admin-0.8.0 lib/linux_admin/service.rb
linux_admin-0.7.0 lib/linux_admin/service.rb
linux_admin-0.6.0 lib/linux_admin/service.rb
linux_admin-0.5.7 lib/linux_admin/service.rb
linux_admin-0.5.6 lib/linux_admin/service.rb
linux_admin-0.5.5 lib/linux_admin/service.rb
linux_admin-0.5.4 lib/linux_admin/service.rb
linux_admin-0.5.3 lib/linux_admin/service.rb
linux_admin-0.5.2 lib/linux_admin/service.rb
linux_admin-0.5.1 lib/linux_admin/service.rb
linux_admin-0.5.0 lib/linux_admin/service.rb
linux_admin-0.4.1 lib/linux_admin/service.rb
linux_admin-0.4.0 lib/linux_admin/service.rb
linux_admin-0.3.0 lib/linux_admin/service.rb