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 +4 -4
- data/.travis.yml +7 -1
- data/Changelog +6 -0
- data/README.md +1 -1
- data/lib/serverengine/daemon.rb +84 -45
- data/lib/serverengine/server.rb +7 -7
- data/lib/serverengine/version.rb +1 -1
- data/lib/serverengine.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac02dfbbdf4f05336522f09c88857a122c35821d
|
4
|
+
data.tar.gz: 6ec1e772952f738b8d17e93d15788e934ffcf665
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 831d6e39b2cfd52d25c6cf39d2aba188f29767b21d203d2f8ee22cf945c44750f9617d382b9db6eab58d902c366c3d03761b420a4aed270cb32d1db2683555c9
|
7
|
+
data.tar.gz: b619fb4e206c79bf70c91950950d62c9fe64deb18014016ca959c0bda60bf99442beda9ef07ab2a1931b832333304f4da1ad2cc445dc2574299cf928579f97a3
|
data/.travis.yml
CHANGED
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
|
|
data/lib/serverengine/daemon.rb
CHANGED
@@ -62,27 +62,36 @@ module ServerEngine
|
|
62
62
|
DUMP = :CONT
|
63
63
|
end
|
64
64
|
|
65
|
-
def self.
|
66
|
-
if
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
88
|
+
Process.groups = Process.groups | user_groups
|
89
|
+
Process::UID.change_privilege(etc_pw.uid)
|
90
|
+
end
|
84
91
|
|
85
|
-
|
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
|
109
|
-
|
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
|
-
|
112
|
-
|
113
|
-
|
146
|
+
Process.fork do
|
147
|
+
begin
|
148
|
+
rpipe.close
|
114
149
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
121
|
-
|
155
|
+
Daemon.change_privilege(@chuser, @chgroup)
|
156
|
+
File.umask(@chumask) if @chumask
|
122
157
|
|
123
|
-
|
158
|
+
s = create_server(create_logger)
|
124
159
|
|
125
|
-
|
126
|
-
|
127
|
-
|
160
|
+
STDIN.reopen(File::NULL)
|
161
|
+
STDOUT.reopen(File::NULL, "wb")
|
162
|
+
STDERR.reopen(File::NULL, "wb")
|
128
163
|
|
129
|
-
|
164
|
+
s.install_signal_handlers
|
130
165
|
|
131
|
-
|
132
|
-
|
166
|
+
wpipe.write "\n"
|
167
|
+
wpipe.close
|
133
168
|
|
134
|
-
|
135
|
-
|
169
|
+
s.main
|
170
|
+
end
|
136
171
|
|
137
|
-
|
138
|
-
|
139
|
-
|
172
|
+
exit 0
|
173
|
+
ensure
|
174
|
+
exit! @daemonize_error_exit_code
|
175
|
+
end
|
140
176
|
end
|
141
|
-
end
|
142
177
|
|
143
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
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
|
data/lib/serverengine/server.rb
CHANGED
@@ -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
|
data/lib/serverengine/version.rb
CHANGED
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.
|
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-
|
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.
|
123
|
+
rubygems_version: 2.2.0
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: ServerEngine - multiprocess server framework
|