Module: Capsaicin::Service::Command
- Included in:
- Capsaicin::Service
- Defined in:
- lib/capsaicin/service/command.rb
Instance Method Summary collapse
-
#command(id, start, stop, *args) ⇒ Object
Defines a recipe to control a command-based service.
-
#command?(start, stop) ⇒ Boolean
Check for the existance of a command-based service.
Instance Method Details
#command(id, start, stop, *args) ⇒ Object
Defines a recipe to control a command-based service.
12 13 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 45 46 47 48 49 |
# File 'lib/capsaicin/service/command.rb', line 12 def command(id,start,stop,*args) = Hash===args.last ? args.pop : {} svc_name = id.to_s svc_desc = next_description(:reset) || (svc_name.capitalize unless .delete(:hide)) extras = .delete(:extras) || {} via = .delete(:via) namespace id do desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:start]}" if svc_desc task :start, do send(via || fetch(:run_method, :run), start) end desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:stop]}" if svc_desc task :stop, do send(via || fetch(:run_method, :run), stop) end unless extras.key? :restart desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:restart]}" if svc_desc task :restart, do stop start end end extras.each do |k,cmd| desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[k]}" if svc_desc task k, do send(via || fetch(:run_method, :run), cmd) end end instance_eval { yield } if block_given? end end |
#command?(start, stop) ⇒ Boolean
Check for the existance of a command-based service.
6 7 8 |
# File 'lib/capsaicin/service/command.rb', line 6 def command?(start, stop) files.executable? start and files.executable? stop end |