procman 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Adam Cooke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Procfile CHANGED
@@ -1,10 +1,19 @@
1
1
  process :unicorn do
2
- start { }
3
- stop { }
2
+ start do
3
+ puts "ENV: #{environment}"
4
+ end
5
+ stop {}
6
+ restart {}
4
7
  end
5
8
 
6
9
  process :worker do
7
- stop do
8
- "Stopping"
9
- end
10
+ start {}
11
+ stop {}
12
+ restart {}
13
+ end
14
+
15
+ process :cron do
16
+ start {}
17
+ stop {}
18
+ restart {}
10
19
  end
@@ -0,0 +1,62 @@
1
+ # ProcMan
2
+
3
+ A very very simple system for managing a list of processes which
4
+ need to be started/stopped/restarted within a Ruby application.
5
+
6
+ It works by defining a `Procfile` in the root of your application
7
+ and then using the `procman` command to either start, stop or restart
8
+ your application as a whole.
9
+
10
+ The `Procfile` is a Ruby file which you can use to define how to manipulate
11
+ your processes.
12
+
13
+ ## Example Procfile
14
+
15
+ Your Procfile can contain multiple types of process and each process should define
16
+ an action which should be carried out for starting, stopping & restarting that process.
17
+
18
+ In this example, we have demonstrated two processes a unicorn web server and a worker process
19
+ powered by our Ruby backgrounding system, rbg.
20
+
21
+ ```ruby
22
+ process :unicorn do
23
+
24
+ start do
25
+ system("umask 002 && bundle exec unicorn_rails -E production -c config/unicorn.rb -D")
26
+ end
27
+
28
+ stop do
29
+ system("kill `cat tmp/pids/unicorn.production.pid`")
30
+ end
31
+
32
+ restart { stop and start }
33
+
34
+ end
35
+
36
+ process :worker do
37
+
38
+ start do
39
+ system("bundle exec rbg start -c config/processes/worker.rb -E production")
40
+ end
41
+
42
+ stop do
43
+ system("bundle exec rbg stop -c config/processes/worker.rb -E production")
44
+ end
45
+
46
+ restart do
47
+ system("bundle exec rbg reload -c config/processes/worker.rb -E production")
48
+ end
49
+
50
+ end
51
+ ```
52
+
53
+ ## Executing process commands
54
+
55
+ Once you have a Procfile, you can execute commands by sending them to the `procman`
56
+ command on your system. If you have installed procman within bundler, you can execute
57
+ the command using `bundle exec procman`.
58
+
59
+ * `procman start` - start your processes
60
+ * `procman stop` - stop your processes
61
+ * `procman restart` - restart your processes
62
+
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'proc_man'
3
3
  begin
4
- ProcMan.run(ARGV.first)
4
+ ProcMan.run(ARGV[0], ARGV[1])
5
5
  rescue ProcMan::Error => e
6
6
  puts "\e[31m" + e.message + "\e[0m"
7
7
  Process.exit(1)
@@ -3,7 +3,7 @@ require 'proc_man/procfile'
3
3
 
4
4
  module ProcMan
5
5
 
6
- VERSION = '1.0.0'
6
+ VERSION = '1.1.0'
7
7
 
8
8
  class Error < StandardError; end
9
9
 
@@ -22,12 +22,13 @@ module ProcMan
22
22
  @processes ||= Array.new
23
23
  end
24
24
 
25
- def run(method)
25
+ def run(method, environment = nil)
26
26
  load_procfile(File.expand_path('./Procfile'))
27
27
  if method.nil?
28
28
  raise Error, "Command to execute was not specified. For example, pass 'start' to start processes."
29
29
  else
30
30
  for process in self.processes
31
+ process.environment = environment
31
32
  if process.defined_method?(method)
32
33
  puts "\e[33m#{method.capitalize}ing #{process.name}\e[0m"
33
34
  process.send(method)
@@ -1,7 +1,9 @@
1
1
  module ProcMan
2
2
  class Process
3
3
 
4
- def initialize(name)
4
+ attr_writer :environment
5
+
6
+ def initialize(name, options = {})
5
7
  @name = name
6
8
  end
7
9
 
@@ -9,6 +11,10 @@ module ProcMan
9
11
  @name
10
12
  end
11
13
 
14
+ def environment
15
+ @environment || 'production'
16
+ end
17
+
12
18
  def method_missing(method, &block)
13
19
  if block_given?
14
20
  instance_variable_set("@#{method}", block)
Binary file
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-23 00:00:00.000000000 Z
12
+ date: 2012-12-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A very very simple library for starting/stopping/restarting processes
15
15
  for a Ruby application
@@ -23,8 +23,11 @@ files:
23
23
  - lib/proc_man/process.rb
24
24
  - lib/proc_man/procfile.rb
25
25
  - lib/proc_man.rb
26
+ - LICENCE
26
27
  - Procfile
27
- - proman.gemspec
28
+ - procman-1.0.0.gem
29
+ - procman.gemspec
30
+ - README.md
28
31
  homepage: http://atechmedia.com
29
32
  licenses: []
30
33
  post_install_message: