service_manager 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/service_manager/service.rb +11 -6
  2. metadata +52 -70
@@ -4,7 +4,7 @@ class ServiceManager::Service
4
4
  CHDIR_SEMAPHORE = Mutex.new
5
5
  ANSI_COLOR_RESET = 0
6
6
 
7
- attr_accessor :name, :host, :port, :cwd, :reload_uri, :start_cmd, :process, :loaded_cue, :timeout, :color, :pid_file
7
+ attr_accessor :name, :host, :port, :cwd, :reload_uri, :start_cmd, :process, :loaded_cue, :timeout, :color, :pid_file, :manage_pid_file
8
8
 
9
9
  class ServiceDidntStart < Exception; end
10
10
 
@@ -53,8 +53,8 @@ class ServiceManager::Service
53
53
  return false
54
54
  end
55
55
 
56
- puts "Starting #{colorized_service_name} in #{cwd} with '#{start_cmd}'"
57
56
  CHDIR_SEMAPHORE.synchronize do
57
+ puts "Starting #{colorized_service_name} in #{cwd} with '#{start_cmd}'\n"
58
58
  Dir.chdir(cwd) do
59
59
  without_bundler_env do
60
60
  # system("bash -c set")
@@ -65,6 +65,7 @@ class ServiceManager::Service
65
65
  at_exit { stop }
66
66
  wait
67
67
  puts "Server #{colorized_service_name} is up."
68
+ File.open(pid_file, "wb") { |f| f << process.pid } if manage_pid_file
68
69
  end
69
70
 
70
71
  # stop the service. If we didn't start it, do nothing.
@@ -79,6 +80,7 @@ class ServiceManager::Service
79
80
  end
80
81
  puts "Server #{colorized_service_name} (#{process.pid}) is shut down"
81
82
  self.process = nil
83
+ FileUtils.rm(pid_file) if manage_pid_file && File.exist?(pid_file)
82
84
  true
83
85
  end
84
86
 
@@ -93,10 +95,12 @@ class ServiceManager::Service
93
95
 
94
96
  # detects if the service is running on the configured host and port (will return true if we weren't the ones who started it)
95
97
  def running?
96
- if pid_file
98
+ case
99
+ when pid_file
97
100
  running_via_pid_file?
98
- else
99
- TCPSocket.listening_service?(:port => port, :host => host)
101
+ when port
102
+ TCPSocket.listening_service?(:port => port, :host => host || "127.0.0.1")
103
+ else raise "Service Manager needs to be able to tell if the service is already running or not. You'll need to specify a pid file or a TCP port to check."
100
104
  end
101
105
  end
102
106
 
@@ -109,7 +113,8 @@ protected
109
113
  end
110
114
 
111
115
  def colorize(output)
112
- "\e[0;#{color}m#{output}\e[0;#{ANSI_COLOR_RESET}m"
116
+ no_color = output.gsub(/\e\[(\d*\;|)\d*m\d*/, "")
117
+ "\e[0;#{color}m#{no_color}\e[0;#{ANSI_COLOR_RESET}m"
113
118
  end
114
119
 
115
120
  def colorized_service_name
metadata CHANGED
@@ -1,106 +1,88 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: service_manager
3
- version: !ruby/object:Gem::Version
4
- hash: 3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 6
9
- - 2
10
- version: 0.6.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Tim Harper
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-28 00:00:00 -06:00
19
- default_executable: start_services
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: background_process
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2168700740 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 11
30
- segments:
31
- - 1
32
- - 2
33
- version: "1.2"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: tcpsocket-wait
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2168700740
25
+ - !ruby/object:Gem::Dependency
26
+ name: tcpsocket-wait
27
+ requirement: &2168700340 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
48
33
  type: :runtime
49
- version_requirements: *id002
50
- description: |
51
- It launches and interacts with a set of services from a single terminal window.
52
-
34
+ prerelease: false
35
+ version_requirements: *2168700340
36
+ description: ! 'It launches and interacts with a set of services from a single terminal
37
+ window.
38
+
39
+
53
40
  * Colorizes output for each process to help distinguish them.
54
- * Useful for integration-test applications where you need to start up several processes and test them all.
55
- * Built because servolux wasn't working very well for me.
56
- * Can detect exactly when a service is successfully launched by watching the output of the process.
57
41
 
58
- email:
42
+ * Useful for integration-test applications where you need to start up several processes
43
+ and test them all.
44
+
45
+ * Built because servolux wasn''t working very well for me.
46
+
47
+ * Can detect exactly when a service is successfully launched by watching the output
48
+ of the process.
49
+
50
+ '
51
+ email:
59
52
  - tim@leadtune.com
60
- executables:
53
+ executables:
61
54
  - start_services
62
55
  extensions: []
63
-
64
- extra_rdoc_files:
56
+ extra_rdoc_files:
65
57
  - MIT-LICENSE
66
- files:
58
+ files:
67
59
  - MIT-LICENSE
68
60
  - lib/service_manager/service.rb
69
61
  - lib/service_manager.rb
70
62
  - bin/start_services
71
- has_rdoc: true
72
63
  homepage: http://github.com/leadtune/service_manager
73
64
  licenses: []
74
-
75
65
  post_install_message:
76
66
  rdoc_options: []
77
-
78
- require_paths:
67
+ require_paths:
79
68
  - lib
80
- required_ruby_version: !ruby/object:Gem::Requirement
69
+ required_ruby_version: !ruby/object:Gem::Requirement
81
70
  none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
89
- required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
76
  none: false
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- hash: 3
95
- segments:
96
- - 0
97
- version: "0"
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
98
81
  requirements: []
99
-
100
82
  rubyforge_project:
101
- rubygems_version: 1.5.0
83
+ rubygems_version: 1.8.7
102
84
  signing_key:
103
85
  specification_version: 3
104
86
  summary: service_manager
105
87
  test_files: []
106
-
88
+ has_rdoc: