Sha256: 1f9374bc2813737207c8da75f6c9cd717850961011c6f8f873eb9999537f9ca5

Contents?: true

Size: 1.56 KB

Versions: 9

Compression:

Stored size: 1.56 KB

Contents

module Capistrano
  module Cluster
    class Service
      attr :name, :cmd
      def initialize(name, &block)
        @name = name
        instance_eval(&block)
      end

      def start(*args)
        @start = args.first if args.length > 0
        @start || fail("no start command defined for #{@name}")
      end

      def working_dir(*args)
        @working_dir = args.first if args.length > 0
        @working_dir || "/tmp"
      end

      def pid_file(*args)
        @pid_file = args.first if args.length > 0
        @pid_file || "/var/run/#{@name}.pid"
      end

      def reload(*args)
        @reload = args.first if args.length > 0
        @reload || "stop;start"
      end

      def stop(*args)
        @stop = args.first if args.length > 0
        @stop || "kill -TERM $(< #{pid_file})"
      end

      def user(*args)
        @user = args.first if args.length > 0
        @user
      end

      def log_file(*args)
        @log_file = args.first if args.length > 0
        @log_file || "/var/log/service.#{@name}.log"
      end

      def script
        file("service", name: name, start_cmd: start, pid_file: pid_file, working_dir: working_dir, reload_cmd: reload, stop_cmd: stop, user: user)
      end

      module DSL

        def service(name, &block)
          service = Capistrano::Cluster::Service.new(name, &block)
          upload_as :root, service.script, "/etc/init.d/#{name}"
          sudo :chmod, "0777", "/etc/init.d/#{name}"
          sudo "update-rc.d", name, :defaults
        end

      end

    end

  end

end



include Capistrano::Cluster::Service::DSL


Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
capistrano-cluster-0.0.18 lib/capistrano/cluster/service.rb
capistrano-cluster-0.0.17 lib/capistrano/cluster/service.rb
capistrano-cluster-0.0.16 lib/capistrano/cluster/service.rb
capistrano-cluster-0.0.15 lib/capistrano/cluster/service.rb
capistrano-cluster-0.0.14 lib/capistrano/cluster/service.rb
capistrano-cluster-0.0.13 lib/capistrano/cluster/service.rb
capistrano-cluster-0.0.12 lib/capistrano/cluster/service.rb
capistrano-cluster-0.0.11 lib/capistrano/cluster/service.rb
capistrano-cluster-0.0.10 lib/capistrano/cluster/service.rb