-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This command to start a Spring server explicitly in the foreground, which logging to stdout. This will be useful to those who want to run spring more explicitly, but the real impetus was to enable running a spring server inside a Docker container.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Spring | ||
module Client | ||
class Server < Command | ||
def call | ||
require "spring/server" | ||
Spring::Server.boot(foreground: true) | ||
end | ||
|
||
def self.description | ||
"Explicitly start a Spring server in the foreground" | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,19 +10,24 @@ module Spring | |
|
||
module Spring | ||
class Server | ||
def self.boot | ||
new.boot | ||
def self.boot(options = {}) | ||
new(options).boot | ||
end | ||
|
||
attr_reader :env | ||
|
||
def initialize(env = Env.new) | ||
@env = env | ||
@applications = Hash.new { |h, k| h[k] = ApplicationManager.new(k) } | ||
def initialize(options = {}) | ||
@foreground = options.fetch(:foreground, false) | ||
@env = options[:env] || default_env | ||
@applications = Hash.new { |h, k| h[k] = ApplicationManager.new(k, env) } | ||
@pidfile = env.pidfile_path.open('a') | ||
@mutex = Mutex.new | ||
end | ||
|
||
def foreground? | ||
@foreground | ||
end | ||
|
||
def log(message) | ||
env.log "[server] #{message}" | ||
end | ||
|
@@ -31,8 +36,8 @@ def boot | |
Spring.verify_environment | ||
|
||
write_pidfile | ||
set_pgid | ||
ignore_signals | ||
set_pgid unless foreground? | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jonleighton
Author
Member
|
||
ignore_signals unless foreground? | ||
set_exit_hook | ||
set_process_title | ||
start_server | ||
|
@@ -42,6 +47,7 @@ def start_server | |
server = UNIXServer.open(env.socket_name) | ||
log "started on #{env.socket_name}" | ||
loop { serve server.accept } | ||
rescue Interrupt | ||
end | ||
|
||
def serve(client) | ||
|
@@ -126,5 +132,19 @@ def set_process_title | |
"spring server | #{env.app_name} | started #{distance} ago" | ||
} | ||
end | ||
|
||
private | ||
|
||
def default_env | ||
Env.new(log_file: default_log_file) | ||
end | ||
|
||
def default_log_file | ||
if foreground? && !ENV["SPRING_LOG"] | ||
$stdout | ||
else | ||
nil | ||
end | ||
end | ||
end | ||
end |
@jonleighton May I kindly ask you why do you use
set_pgid unless foreground?
here? It means thatpgid
is set for spring server running in background but expected the opposite, that it would be set to the server running in foreground.I've met this problem when running RubyMine from Toolbox so that it hasn't console and spring failed on
set_pgid
. Since spring server has ran by default with the--background
option this problem should be solved on its own ifpgid
will be set only for foreground spring server process.