Skip to content

Commit

Permalink
Add a bunch of configuration via environment variables
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonleighton committed Apr 9, 2016
1 parent e80b16a commit 2cd0c65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,30 @@ a command runs:
Spring.quiet = true
```

### Environment variables

The following environment variables are used by Spring:

* `DISABLE_SPRING` - If set, Spring will be bypassed and your
application will boot in a foreground process
* `SPRING_LOG` - The path to a file which Spring will write log messages
to.
* `SPRING_TMP_PATH` - The directory where Spring should write its temporary
files (a pidfile and a socket). By default we use the
`XDG_RUNTIME_DIR` environment variable, or else `Dir.tmpdir`, and then
create a directory in that named `spring-$UID`. We don't use your
Rails application's `tmp/` directory because that may be on a
filesystem which doesn't support UNIX sockets.
* `SPRING_APPLICATION_ID` - Used to identify distinct Rails
applications. By default it is an MD5 hash of the current
`RUBY_VERSION`, and the path to your Rails project root.
* `SPRING_SOCKET` - The path which should be used for the UNIX socket
which Spring uses to communicate with the long-running Spring server
process. By default this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
* `SPRING_PIDFILE` - The path which should be used to store the pid of
the long-running Spring server process. By default this is
`SPRING_TMP_PATH/SPRING_PIDFILE`.

## Troubleshooting

If you want to get more information about what spring is doing, you can
Expand Down
11 changes: 7 additions & 4 deletions lib/spring/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,28 @@ def version
end

def tmp_path
path = Pathname.new(File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring-#{Process.uid}"))
path = Pathname.new(
ENV["SPRING_TMP_PATH"] ||
File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring-#{Process.uid}")
)
FileUtils.mkdir_p(path) unless path.exist?
path
end

def application_id
Digest::MD5.hexdigest(RUBY_VERSION + project_root.to_s)
ENV["SPRING_APPLICATION_ID"] || Digest::MD5.hexdigest(RUBY_VERSION + project_root.to_s)
end

def socket_path
tmp_path.join(application_id)
Pathname.new(ENV["SPRING_SOCKET"] || tmp_path.join(application_id))
end

def socket_name
socket_path.to_s
end

def pidfile_path
tmp_path.join("#{application_id}.pid")
Pathname.new(ENV["SPRING_PIDFILE"] || tmp_path.join("#{application_id}.pid"))
end

def pid
Expand Down

0 comments on commit 2cd0c65

Please sign in to comment.