serverengine 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: debb8b7610180c5b0980d3ff75235e924503ebb4
4
- data.tar.gz: bd1f53485fd632906589b85c94f13d554fa3d652
3
+ metadata.gz: ac02dfbbdf4f05336522f09c88857a122c35821d
4
+ data.tar.gz: 6ec1e772952f738b8d17e93d15788e934ffcf665
5
5
  SHA512:
6
- metadata.gz: 0e5097035cea3dfaf166bd5a1eea304feb5c364368616ee58c8140613adc6a0155c1ecd0d4f6c09991425fc9f5fa5b446c81d239ed72ed11cd30af5f2e6f69c4
7
- data.tar.gz: d6de17641b8cc2d3c64ca1cc21cc6e9968065071077d4adbb68658e3c397f66a637828ce350d72d5b65e74d339014b93ba8972eb5dae42894cf055602ee44c58
6
+ metadata.gz: 831d6e39b2cfd52d25c6cf39d2aba188f29767b21d203d2f8ee22cf945c44750f9617d382b9db6eab58d902c366c3d03761b420a4aed270cb32d1db2683555c9
7
+ data.tar.gz: b619fb4e206c79bf70c91950950d62c9fe64deb18014016ca959c0bda60bf99442beda9ef07ab2a1931b832333304f4da1ad2cc445dc2574299cf928579f97a3
data/.travis.yml CHANGED
@@ -1,7 +1,9 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.2
4
+ - 2.2.4
5
+ - 2.3.0
6
+ - ruby-head
5
7
 
6
8
  branches:
7
9
  only:
@@ -11,3 +13,7 @@ script: bundle exec rake spec
11
13
 
12
14
  before_install:
13
15
  - gem update bundler
16
+
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: ruby-head
data/Changelog CHANGED
@@ -1,3 +1,9 @@
1
+ 2016-04-14 version 1.6.2:
2
+
3
+ * Fix to use Etc instead of id command in change_privilege for windows
4
+ * Fix signal handler on Server class to be configurable
5
+ * Fix to use spawn when damonize on windows
6
+
1
7
  2016-03-04 version 1.6.1:
2
8
 
3
9
  * Fix CloseHandle definition in winsock
data/README.md CHANGED
@@ -345,7 +345,7 @@ se.run
345
345
  ```ruby
346
346
  module MyServer
347
347
  def before_run
348
- @socket_manager_path = ServerEngine::SocketManager.generate_path
348
+ @socket_manager_path = ServerEngine::SocketManager::Server.generate_path
349
349
  @socket_manager_server = ServerEngine::SocketManager::Server.open(@socket_manager_path)
350
350
  end
351
351
 
@@ -62,27 +62,36 @@ module ServerEngine
62
62
  DUMP = :CONT
63
63
  end
64
64
 
65
- def self.change_privilege(user, group)
66
- if group
67
- chgid = group.to_i
68
- if chgid.to_s != group
69
- chgid = Process::GID.from_name(group)
70
- end
71
- Process::GID.change_privilege(chgid)
65
+ def self.get_etc_passwd(user)
66
+ if user.to_i.to_s == user
67
+ Etc.getpwuid(user.to_i)
68
+ else
69
+ Etc.getpwnam(user)
72
70
  end
71
+ end
73
72
 
73
+ def self.get_etc_group(group)
74
+ if group.to_i.to_s == group
75
+ Etc.getgrgid(group.to_i)
76
+ else
77
+ Etc.getgrnam(group)
78
+ end
79
+ end
80
+
81
+ def self.change_privilege(user, group)
74
82
  if user
75
- chuid = user.to_i
76
- if chuid.to_s != user
77
- chuid = Process::UID.from_name(user)
78
- end
83
+ etc_pw = Daemon.get_etc_passwd(user)
84
+ user_groups = [etc_pw.gid]
85
+ Etc.setgrent
86
+ Etc.group { |gr| user_groups << gr.gid if gr.mem.include?(etc_pw.name) } # emulate 'id -G'
79
87
 
80
- user_groups = `id -G #{Shellwords.escape user}`.split.map(&:to_i)
81
- if $?.success?
82
- Process.groups = Process.groups | user_groups
83
- end
88
+ Process.groups = Process.groups | user_groups
89
+ Process::UID.change_privilege(etc_pw.uid)
90
+ end
84
91
 
85
- Process::UID.change_privilege(chuid)
92
+ if group
93
+ etc_group = Daemon.get_etc_group(group)
94
+ Process::GID.change_privilege(etc_group.gid)
86
95
  end
87
96
 
88
97
  nil
@@ -97,6 +106,27 @@ module ServerEngine
97
106
  end
98
107
  end
99
108
 
109
+ def self.run_server(server_module, worker_module, load_config_proc={}, &block)
110
+ Daemon.new(server_module, worker_module, load_config_proc, &block).server_main
111
+ end
112
+
113
+ def server_main
114
+ $0 = @daemon_process_name if @daemon_process_name
115
+
116
+ Daemon.change_privilege(@chuser, @chgroup)
117
+ File.umask(@chumask) if @chumask
118
+
119
+ s = create_server(create_logger)
120
+
121
+ STDIN.reopen(File::NULL)
122
+ STDOUT.reopen(File::NULL, "wb")
123
+ STDERR.reopen(File::NULL, "wb")
124
+
125
+ s.install_signal_handlers
126
+
127
+ s.main
128
+ end
129
+
100
130
  def main
101
131
  unless @daemonize
102
132
  s = create_server(create_logger)
@@ -105,53 +135,62 @@ module ServerEngine
105
135
  return 0
106
136
  end
107
137
 
108
- rpipe, wpipe = IO.pipe
109
- wpipe.sync = true
138
+ rpipe = nil
139
+ if ServerEngine.windows?
140
+ windows_daemon_cmdline = config[:windows_daemon_cmdline]
141
+ pid = Process.spawn(*Array(windows_daemon_cmdline))
142
+ else
143
+ rpipe, wpipe = IO.pipe
144
+ wpipe.sync = true
110
145
 
111
- Process.fork do
112
- begin
113
- rpipe.close
146
+ Process.fork do
147
+ begin
148
+ rpipe.close
114
149
 
115
- Process.setsid
116
- Process.fork do
117
- $0 = @daemon_process_name if @daemon_process_name
118
- wpipe.write "#{Process.pid}\n"
150
+ Process.setsid
151
+ Process.fork do
152
+ $0 = @daemon_process_name if @daemon_process_name
153
+ wpipe.write "#{Process.pid}\n"
119
154
 
120
- Daemon.change_privilege(@chuser, @chgroup)
121
- File.umask(@chumask) if @chumask
155
+ Daemon.change_privilege(@chuser, @chgroup)
156
+ File.umask(@chumask) if @chumask
122
157
 
123
- s = create_server(create_logger)
158
+ s = create_server(create_logger)
124
159
 
125
- STDIN.reopen(File::NULL)
126
- STDOUT.reopen(File::NULL, "wb")
127
- STDERR.reopen(File::NULL, "wb")
160
+ STDIN.reopen(File::NULL)
161
+ STDOUT.reopen(File::NULL, "wb")
162
+ STDERR.reopen(File::NULL, "wb")
128
163
 
129
- s.install_signal_handlers
164
+ s.install_signal_handlers
130
165
 
131
- wpipe.write "\n"
132
- wpipe.close
166
+ wpipe.write "\n"
167
+ wpipe.close
133
168
 
134
- s.main
135
- end
169
+ s.main
170
+ end
136
171
 
137
- exit 0
138
- ensure
139
- exit! @daemonize_error_exit_code
172
+ exit 0
173
+ ensure
174
+ exit! @daemonize_error_exit_code
175
+ end
140
176
  end
141
- end
142
177
 
143
- wpipe.close
178
+ wpipe.close
179
+
180
+ pid = rpipe.gets.to_i
181
+ end
144
182
 
145
- pid = rpipe.gets.to_i
146
183
  if @pid_path
147
184
  File.open(@pid_path, "w") {|f|
148
185
  f.write "#{pid}\n"
149
186
  }
150
187
  end
151
188
 
152
- data = rpipe.read
153
- if data != "\n"
154
- return @daemonize_error_exit_code
189
+ unless ServerEngine.windows?
190
+ data = rpipe.read
191
+ if data != "\n"
192
+ return @daemonize_error_exit_code
193
+ end
155
194
  end
156
195
 
157
196
  return 0
@@ -65,16 +65,16 @@ module ServerEngine
65
65
  def install_signal_handlers
66
66
  s = self
67
67
  SignalThread.new do |st|
68
- st.trap(Daemon::Signals::GRACEFUL_STOP) { s.stop(true) }
69
- st.trap(Daemon::Signals::DETACH) { s.stop(true) }
68
+ st.trap(@config[:signal_graceful_stop] || Daemon::Signals::GRACEFUL_STOP) { s.stop(true) }
69
+ st.trap(@config[:signal_detach] || Daemon::Signals::DETACH) { s.stop(true) }
70
70
  # Here disables signals excepting GRACEFUL_STOP == :SIGTERM because
71
71
  # only SIGTERM is available on all version of Windows.
72
72
  unless ServerEngine.windows?
73
- st.trap(Daemon::Signals::IMMEDIATE_STOP) { s.stop(false) }
74
- st.trap(Daemon::Signals::GRACEFUL_RESTART) { s.restart(true) }
75
- st.trap(Daemon::Signals::IMMEDIATE_RESTART) { s.restart(false) }
76
- st.trap(Daemon::Signals::RELOAD) { s.reload }
77
- st.trap(Daemon::Signals::DUMP) { Sigdump.dump }
73
+ st.trap(@config[:signal_immediate_stop] || Daemon::Signals::IMMEDIATE_STOP) { s.stop(false) }
74
+ st.trap(@config[:signal_graceful_restart] || Daemon::Signals::GRACEFUL_RESTART) { s.restart(true) }
75
+ st.trap(@config[:signal_immediate_restart] || Daemon::Signals::IMMEDIATE_RESTART) { s.restart(false) }
76
+ st.trap(@config[:signal_reload] || Daemon::Signals::RELOAD) { s.reload }
77
+ st.trap(@config[:signal_dump] || Daemon::Signals::DUMP) { Sigdump.dump }
78
78
  end
79
79
  end
80
80
  end
@@ -1,3 +1,3 @@
1
1
  module ServerEngine
2
- VERSION = "1.6.1"
2
+ VERSION = "1.6.2"
3
3
  end
data/lib/serverengine.rb CHANGED
@@ -51,4 +51,14 @@ module ServerEngine
51
51
  def self.create(server_module, worker_module, load_config_proc={}, &block)
52
52
  Daemon.new(server_module, worker_module, load_config_proc, &block)
53
53
  end
54
+
55
+ def self.ruby_bin_path
56
+ if ServerEngine.windows?
57
+ ruby_path = "\0" * 256
58
+ GetModuleFileName.call(0, ruby_path, 256)
59
+ return ruby_path.rstrip.gsub(/\\/, '/')
60
+ else
61
+ return File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["RUBY_INSTALL_NAME"]) + RbConfig::CONFIG["EXEEXT"]
62
+ end
63
+ end
54
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverengine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sigdump
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.4.5
123
+ rubygems_version: 2.2.0
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: ServerEngine - multiprocess server framework