Skip to content

Commit 2cd0c65

Browse files
committed
Add a bunch of configuration via environment variables
I'm adding this to make it easier to use Spring inside a Docker container, but it should be generally useful for people who want to run a non-standard setup.
1 parent e80b16a commit 2cd0c65

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,30 @@ a command runs:
365365
Spring.quiet = true
366366
```
367367

368+
### Environment variables
369+
370+
The following environment variables are used by Spring:
371+
372+
* `DISABLE_SPRING` - If set, Spring will be bypassed and your
373+
application will boot in a foreground process
374+
* `SPRING_LOG` - The path to a file which Spring will write log messages
375+
to.
376+
* `SPRING_TMP_PATH` - The directory where Spring should write its temporary
377+
files (a pidfile and a socket). By default we use the
378+
`XDG_RUNTIME_DIR` environment variable, or else `Dir.tmpdir`, and then
379+
create a directory in that named `spring-$UID`. We don't use your
380+
Rails application's `tmp/` directory because that may be on a
381+
filesystem which doesn't support UNIX sockets.
382+
* `SPRING_APPLICATION_ID` - Used to identify distinct Rails
383+
applications. By default it is an MD5 hash of the current
384+
`RUBY_VERSION`, and the path to your Rails project root.
385+
* `SPRING_SOCKET` - The path which should be used for the UNIX socket
386+
which Spring uses to communicate with the long-running Spring server
387+
process. By default this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
388+
* `SPRING_PIDFILE` - The path which should be used to store the pid of
389+
the long-running Spring server process. By default this is
390+
`SPRING_TMP_PATH/SPRING_PIDFILE`.
391+
368392
## Troubleshooting
369393

370394
If you want to get more information about what spring is doing, you can

lib/spring/env.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,28 @@ def version
3333
end
3434

3535
def tmp_path
36-
path = Pathname.new(File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring-#{Process.uid}"))
36+
path = Pathname.new(
37+
ENV["SPRING_TMP_PATH"] ||
38+
File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring-#{Process.uid}")
39+
)
3740
FileUtils.mkdir_p(path) unless path.exist?
3841
path
3942
end
4043

4144
def application_id
42-
Digest::MD5.hexdigest(RUBY_VERSION + project_root.to_s)
45+
ENV["SPRING_APPLICATION_ID"] || Digest::MD5.hexdigest(RUBY_VERSION + project_root.to_s)
4346
end
4447

4548
def socket_path
46-
tmp_path.join(application_id)
49+
Pathname.new(ENV["SPRING_SOCKET"] || tmp_path.join(application_id))
4750
end
4851

4952
def socket_name
5053
socket_path.to_s
5154
end
5255

5356
def pidfile_path
54-
tmp_path.join("#{application_id}.pid")
57+
Pathname.new(ENV["SPRING_PIDFILE"] || tmp_path.join("#{application_id}.pid"))
5558
end
5659

5760
def pid

0 commit comments

Comments
 (0)