emmy-engine 0.2.3 → 0.2.4

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: bb59578321a7548dfbfb97f3aec79be5fa4748d4
4
- data.tar.gz: 6956f77fa81364267887394db94e96a81315178c
3
+ metadata.gz: 2ca6fbf6bf4fe55da6118207a8364f8e7c9e3e6e
4
+ data.tar.gz: 7ac4430acd303c198bb530719da1cc1731422079
5
5
  SHA512:
6
- metadata.gz: 3a561103f57d1797a6e91e7deb4cf255ed99ab771ff55797cca9353393fb8afbdceba608c9f33eedfc0452c9656a7fd6d9c32e48f4479b0d72315e6928d05f5a
7
- data.tar.gz: c56a4fddb13fe885d462d22a98ee702940b6b3e8cfe521eed86b6795da420af967119e6d2f573aee808473a0007c9c90cf2bba2aaaea01b4fe00ef15a43b014c
6
+ metadata.gz: dd9eb63595163b681075ab2b70acedd73ceddb639cb5562373a3c9707881b33d6e127849268ac1173174fdcc4f4c01b3384dbc104fe7f2f35b4a0c41cf752c21
7
+ data.tar.gz: 26223b0c416dd7bf78522aa8ae2e4c4fb9a9549b0d99b1d2c7be2626604621ed9b05b9f362aeaa14888a8e9a27dab4386b0b22d0697da259d24c9da43a97d778
data/lib/emmy/runner.rb CHANGED
@@ -60,7 +60,7 @@ module Emmy
60
60
  "Default: #{config.url.host}") { |address| config.url.host = address }
61
61
  opts.on("-b", "--backend [name]", "Backend name",
62
62
  "Default: backend") { |name| config.backend = name }
63
- opts.on("-d", "--daemonize", "Runs server in the background") { config.daemonize = true }
63
+ opts.on("-d", "--daemonize", "Runs server in the background") { @action = :daemonize_server }
64
64
  opts.on("-s", "--silence", "Logging disabled") { config.logging = false }
65
65
  # actions
66
66
  opts.on("-i", "--info", "Shows server configuration") { @action = :show_configuration }
@@ -76,7 +76,12 @@ module Emmy
76
76
  config.group = "worker"
77
77
  end
78
78
 
79
- config.pid ||= "tmp/pids/#{config.backend}.pid"
79
+ config.pid ||= "#{config.backend}.pid"
80
+ config.log ||= "#{config.backend}.log"
81
+ if config.environment == "development"
82
+ config.stdout = "#{config.backend}.stdout"
83
+ config.stderr = config.stdout
84
+ end
80
85
  end
81
86
 
82
87
  def run_action
@@ -87,6 +92,20 @@ module Emmy
87
92
  self
88
93
  end
89
94
 
95
+ def daemonize_server
96
+ Process.fork do
97
+ Process.setsid
98
+ exit if fork
99
+
100
+ scope_pid(Process.pid) do |pid|
101
+ puts pid
102
+ File.umask(0000) # rw-rw-rw-
103
+ bind_standard_streams
104
+ start_server
105
+ end
106
+ end
107
+ end
108
+
90
109
  def start_server
91
110
  load backend_file
92
111
  end
@@ -97,7 +116,9 @@ module Emmy
97
116
  else
98
117
  require 'irb'
99
118
  require 'irb/completion'
100
- IRB.start
119
+ EmmyMachine.run_block do
120
+ IRB.start
121
+ end
101
122
  end
102
123
  end
103
124
 
@@ -138,6 +159,30 @@ module Emmy
138
159
  error "Can't find backend in #{backends.inspect} places."
139
160
  end
140
161
 
162
+ def scope_pid(pid)
163
+ FileUtils.mkdir_p(File.dirname(config.pid))
164
+ File.open(config.pid, 'w') { |f| f.write(pid) }
165
+ if block_given?
166
+ yield pid
167
+ delete_pid
168
+ end
169
+ end
170
+
171
+ def delete_pid
172
+ File.delete(config.pid)
173
+ end
174
+
175
+ def bind_standard_streams
176
+ STDIN.reopen("/dev/null")
177
+ STDOUT.reopen(config.stdout, "a")
178
+
179
+ if config.stdout == config.stderr
180
+ STDERR.reopen(STDOUT)
181
+ else
182
+ STDERR.reopen(config.stderr, "a")
183
+ end
184
+ end
185
+
141
186
  #<<<
142
187
  end
143
188
  end
data/lib/emmy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Emmy
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emmy-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - inre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-10 00:00:00.000000000 Z
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: emmy-machine