srv_manager 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e428742efeb2eca1574496794c522b334d5901e3
4
- data.tar.gz: a33bda0fb3c99e858d0fe16797956c5abf8ea47a
3
+ metadata.gz: 437563702512cd5232a464dd34613f2d9666f569
4
+ data.tar.gz: 210427676d2042a5c78fab487b637795ae4889c0
5
5
  SHA512:
6
- metadata.gz: 9daf3784665d3c70c694fef1a46f31905a92b39877578af9c80783ea06e134c557c4a4255b5068c33586d4fac462e833bcd0d7238244143d6c74cff3b641be96
7
- data.tar.gz: 1162ad9712e90041964b93bb0ef14e169c1a314b49b1c987da70a2e7c45bcb656f265f8a8129912c9de0b8740fce8f4c5bebd12c3b8b20f6519c6c7445235bd4
6
+ metadata.gz: efa6121b4e8303d7b1743d20e10ce8da11b47d2cd71b8c3dd78e27072f94f2d3d6b87ebcfade6e37aca4ddfa47a8e7e0fc34c1992453de5b8d8f970a3f391ee2
7
+ data.tar.gz: f128851de90230289a08d436bc88507f63c1886c50cb31d4cf49d21bdd99451d4c91763c9530c4ac654aebba477bf07ea173b54cbd787da35707e5dd11f0f9a5
data/bin/srv CHANGED
@@ -18,6 +18,7 @@ module SrvManager
18
18
  option :processes, aliases: :p, type: :numeric
19
19
  option :auto, type: :boolean
20
20
  option :rvm, type: :boolean
21
+ option :pidfile
21
22
  option :env, type: :hash
22
23
  desc 'add <NAME> <COMMAND>', 'Add new service'
23
24
  def add(name, command)
@@ -151,7 +152,7 @@ module SrvManager
151
152
  end
152
153
  end
153
154
 
154
- desc 'load', 'Load service configuration'
155
+ desc 'load <JSON_FILE>', 'Load service configuration'
155
156
  def load(filename)
156
157
  json = JSON.parse(File.read(filename))
157
158
  Context.scoped do |ctx|
@@ -5,16 +5,18 @@ module SrvManager
5
5
  attr_reader :dir
6
6
  attr_reader :env
7
7
  attr_reader :rvm
8
+ attr_reader :pidfile
8
9
 
9
10
  def initialize(text, options={})
10
11
  @text = text
11
12
  @dir = File.expand_path options[:dir].to_s
12
13
  @env = options[:env] || {}
13
14
  @rvm = options[:rvm] || false
15
+ @pidfile = File.expand_path(options[:pidfile]) if options[:pidfile]
14
16
  end
15
17
 
16
18
  def to_hash
17
- {text: text, dir: dir, env: env, rvm: rvm}
19
+ {text: text, dir: dir, env: env, rvm: rvm, pidfile: pidfile}
18
20
  end
19
21
 
20
22
  end
@@ -11,6 +11,7 @@ module SrvManager
11
11
  def start
12
12
  return if alive?
13
13
  command.rvm ? rvm_start : default_start
14
+ @id = wait_for_pid(command.pidfile) if command.pidfile
14
15
  LOGGER.info "Started process #{@id}"
15
16
  end
16
17
 
@@ -42,7 +43,11 @@ module SrvManager
42
43
  private
43
44
 
44
45
  def detault_start
45
- @id = ::Process.spawn command.env, command.text, chdir: command.dir, out: '/dev/null', err: '/dev/null'
46
+ @id = ::Process.spawn command.env,
47
+ command.text,
48
+ chdir: command.dir,
49
+ out: '/dev/null',
50
+ err: '/dev/null'
46
51
  ::Process.detach @id
47
52
  end
48
53
 
@@ -54,15 +59,15 @@ module SrvManager
54
59
  out: '/dev/null',
55
60
  err: '/dev/null'
56
61
  ::Process.detach rvm_pid
57
- @id = wait_for_pid pid_file
62
+ @id = wait_for_pid pid_file, true
58
63
  end
59
64
 
60
- def wait_for_pid(filename)
65
+ def wait_for_pid(filename, delete=false)
61
66
  Timeout.timeout(60) do
62
67
  loop do
63
68
  if File.exists? filename
64
69
  pid = File.read(filename).to_i
65
- File.delete filename
70
+ File.delete filename if delete
66
71
  return pid
67
72
  end
68
73
  sleep 0.1
@@ -1,3 +1,3 @@
1
1
  module SrvManager
2
- VERSION = "0.0.4"
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: srv_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-04 00:00:00.000000000 Z
11
+ date: 2013-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor