service_runner 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in service_runner.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Mateo Murphy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # ServiceRunner
2
+
3
+ Easily run services for rails apps
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'service_runner'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install service_runner
18
+
19
+ ## Usage
20
+
21
+ with Monit
22
+
23
+ check process service_name
24
+ with pidfile /path/to/app/tmp/pids/service_name.pid
25
+ start program = "su - user -c 'cd /path/to/app/ && thor services:start service_name'"
26
+ stop program = "su - user -c 'cd /path/to/app/ && thor services:stop service_name'"
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems" # ruby1.9 doesn't "require" it though
3
+ require "thor"
4
+
5
+ $: << File.expand_path("../../lib/", __FILE__)
6
+ require ('service_runner')
7
+
8
+ ServiceRunner::Runner.start
@@ -0,0 +1,47 @@
1
+ module ServiceRunner
2
+ class Runner < Thor
3
+ include Thor::Actions
4
+
5
+ map '-e' => :env
6
+ map '-p' => :pid
7
+ map '-l' => :log
8
+ map '-t' => :test
9
+
10
+ class_option :pid, :type => :string
11
+ class_option :test, :type => :boolean, :default => false
12
+
13
+ # Start
14
+ desc "start SERVICE", "Start a given service"
15
+ method_option :env, :type => :string
16
+ method_option :log, :type => :string
17
+
18
+ def start(service_name)
19
+ puts "Starting #{service_name}"
20
+ command Service.get(service_name).start(@options)
21
+ end
22
+
23
+ # Stop
24
+ desc "stop SERVICE", "Stop a given service"
25
+
26
+ def stop(service_name)
27
+ puts "Stopping #{service_name}"
28
+ command Service.get(service_name).stop(@options)
29
+ end
30
+
31
+ # Helpers
32
+ no_tasks do
33
+ def command(result)
34
+ if test?
35
+ puts result
36
+ else
37
+ run result
38
+ end
39
+ end
40
+
41
+ def test?
42
+ @options[:test]
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,53 @@
1
+ module ServiceRunner
2
+ class Service
3
+ attr_accessor :name, :start_command, :stop_command
4
+
5
+ def default_options
6
+ {
7
+ 'bundle' => 'bundle exec',
8
+ 'env' => 'production',
9
+ 'log' => "#{root}/log/#{name}.log",
10
+ 'pid' => "#{root}/tmp/pids/#{name}.pid"
11
+ }
12
+ end
13
+
14
+ def initialize(name)
15
+ @name = name
16
+ end
17
+
18
+ def interpolate(command, options)
19
+ interpolations = default_options.merge(options)
20
+
21
+ interpolations.inject(command) do |command_string, (key, value)|
22
+ command_string.gsub(/:\{?#{key}\}?/) { value }
23
+ end
24
+ end
25
+
26
+ def start(options = {})
27
+ interpolate(start_command, options)
28
+ end
29
+
30
+ def stop(options = {})
31
+ interpolate(stop_command, options)
32
+ end
33
+
34
+ def root
35
+ Dir.getwd
36
+ end
37
+
38
+ class << self
39
+ def define(name)
40
+ service = new(name)
41
+ yield service
42
+
43
+ @services ||= {}
44
+ @services[name] = service
45
+ end
46
+
47
+ def get(name)
48
+ @services[name]
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module ServiceRunner
2
+ VERSION = "0.2.1"
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'thor'
2
+ require 'service_runner/version'
3
+ require 'service_runner/runner'
4
+ require 'service_runner/service'
5
+
6
+ module ServiceRunner
7
+ Service.define('delayed_job') do |s|
8
+ s.start_command = "RAILS_ENV=:env script/delayed_job start >> :log 2>&1"
9
+ s.stop_command = "RAILS_ENV=:env script/delayed_job stop >> :log 2>&1"
10
+ end
11
+
12
+ Service.define('sidekiq') do |s|
13
+ s.start_command = "nohup :bundle sidekiq -e ':env' -P ':pid' >> :log 2>&1 &"
14
+ s.stop_command = ":bundle sidekiqctl stop ':pid' 30 >> :log 2>&1"
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'service_runner/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Mateo Murphy"]
7
+ gem.email = ["mateo.murphy@gmail.com"]
8
+ gem.description = %q{Service runner for rails}
9
+ gem.summary = %q{Easily manage services for your rails app}
10
+ gem.homepage = "https://github.com/mateomurphy/service_runner"
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "service_runner"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = ServiceRunner::VERSION
18
+ gem.add_dependency 'thor'
19
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: service_runner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mateo Murphy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Service runner for rails
31
+ email:
32
+ - mateo.murphy@gmail.com
33
+ executables:
34
+ - service_runner
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - bin/service_runner
44
+ - lib/service_runner.rb
45
+ - lib/service_runner/runner.rb
46
+ - lib/service_runner/service.rb
47
+ - lib/service_runner/version.rb
48
+ - service_runner.gemspec
49
+ homepage: https://github.com/mateomurphy/service_runner
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Easily manage services for your rails app
73
+ test_files: []