Sha256: 581ca878032f010863a75719b75d50214c3d80bc86976a697cee9021a825d60b

Contents?: true

Size: 1.5 KB

Versions: 6

Compression:

Stored size: 1.5 KB

Contents

module Capsaicin
  module Service
    module Command

      # Check for the existance of a generic Windows NT service.
      def command?(start, stop)
        files.executable? start and files.executable? stop
      end

      # Defines a recipe to control a generic Windows NT service.
      #
      def command(id,start,stop,*args)
        options = Hash===args.last ? args.pop : {}

        svc_name = id.to_s
        svc_desc = next_description(:reset) || (svc_name.capitalize unless options.delete(:hide))
        extras = options.delete(:extras) || {}
        via = options.delete(:via)

        namespace id do

          desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:start]}" if svc_desc
          task :start, options do
            send(via || fetch(:run_method, :local_run), start)
          end

          desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:stop]}" if svc_desc
          task :stop, options do
            send(via || fetch(:run_method, :local_run), stop)
          end

          unless extras.key? :restart
	          desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[:restart]}" if svc_desc
	          task :restart, options do
	            stop
	            start
	          end
	        end
         
          extras.each do |k,cmd|
	          desc "#{svc_desc}: #{SVC_ACTION_CAPTIONS[k]}" if svc_desc
	          task k, options do
	            send(via || fetch(:run_method, :local_run), cmd)
	          end
          end
        
          instance_eval { yield } if block_given?
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
joekhoobyar-capsaicin-0.1.6 lib/capsaicin/service/command.rb
joekhoobyar-capsaicin-0.1.7 lib/capsaicin/service/command.rb
capsaicin-0.1.9 lib/capsaicin/service/command.rb
capsaicin-0.1.8 lib/capsaicin/service/command.rb
capsaicin-0.1.7 lib/capsaicin/service/command.rb
capsaicin-0.1.6 lib/capsaicin/service/command.rb