Skip to content

Commit 39f6b6f

Browse files
committed
Add support for SPRING_SERVER_COMMAND env variable
This extension point enables starting the spring server in a different way, e.g. inside a docker container. Redirecting output because starting the server should be a background thing, so if there is output we don't want to see it.
1 parent 489f669 commit 39f6b6f

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ The following environment variables are used by Spring:
389389
the long-running Spring server process. By default this is related to
390390
the socket path; if the socket path is `/foo/bar/spring.sock` the
391391
pidfile will be `/foo/bar/spring.pid`.
392+
* `SPRING_SERVER_COMMAND` - The command to run to start up the spring
393+
server when it is not already running. Defaults to `spring _[version]_
394+
server --background`.
392395

393396
## Troubleshooting
394397

lib/spring/client/run.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,7 @@ def run
6969

7070
def boot_server
7171
env.socket_path.unlink if env.socket_path.exist?
72-
73-
pid = Process.spawn(
74-
gem_env,
75-
"ruby",
76-
"-e", "gem 'spring', '#{Spring::VERSION}'; require 'spring/server'; Spring::Server.boot"
77-
)
72+
pid = Process.spawn(gem_env, env.server_command, out: File::NULL)
7873

7974
until env.socket_path.exist?
8075
_, status = Process.waitpid2(pid, Process::WNOHANG)

lib/spring/client/server.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
module Spring
22
module Client
33
class Server < Command
4+
def self.description
5+
"Explicitly start a Spring server in the foreground"
6+
end
7+
48
def call
59
require "spring/server"
6-
Spring::Server.boot(foreground: true)
10+
Spring::Server.boot(foreground: foreground?)
711
end
812

9-
def self.description
10-
"Explicitly start a Spring server in the foreground"
13+
def foreground?
14+
!args.include?("--background")
1115
end
1216
end
1317
end

lib/spring/env.rb

+4
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,9 @@ def kill(sig)
108108
rescue Errno::ESRCH
109109
# already dead
110110
end
111+
112+
def server_command
113+
ENV["SPRING_SERVER_COMMAND"] || "spring _#{Spring::VERSION}_ server --background"
114+
end
111115
end
112116
end

0 commit comments

Comments
 (0)