Module: CapistranoExtensions::Service::LSB

Included in:
CapistranoExtensions::Service
Defined in:
lib/capistrano_extensions/service/lsb.rb

Constant Summary collapse

DEFAULT_ACTIONS =
%w(status start stop restart)

Instance Method Summary collapse

Instance Method Details

#lsb(id, *args) ⇒ Object

Defines a recipe to control a generic LSB service.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/capistrano_extensions/service/lsb.rb', line 14

def lsb(id,*args)
  options = Hash===args.last ? args.pop : {}

  svc_name = id.to_s
  svc_desc = next_description(:reset) || (svc_name.capitalize unless options.delete(:hide))
  svc_actions = DEFAULT_ACTIONS 
  svc_actions += args.pop if Array === args.last

  namespace id do
    case args.first
    when String; id = args.shift.intern
    when Symbol; id = args.shift
    end
    svc_cmd = "/etc/init.d/#{id.to_s.split(':').last}"

    desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:status]}" if svc_desc
    task :default, options do
        sudo "#{svc_cmd} status"
    end

    svc_actions.each do |svc_action|
      svc_action = svc_action.intern if String === svc_action
      desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[svc_action]}" if svc_desc
      task svc_action, options do
        sudo "#{svc_cmd} #{svc_action}"
      end
    end

    instance_eval { yield } if block_given?
  end
end

#lsb?(id) ⇒ Boolean

Check for the existance of a generic Windows NT service.

Returns:

  • (Boolean)


8
9
10
# File 'lib/capistrano_extensions/service/lsb.rb', line 8

def lsb?(id)
  files.exists? "/etc/init.d/#{id.to_s.split(':').last}"
end