3

I have about 130 sinatra web apps running on a cluster of apache-passenger servers. All of these apps have been cloned from a generic codebase, then modified to have their own authentication key. The majority of apps do not have modifications aside from the authentication key. The advantage of separate apps is that I can very quickly make changes to a specific app without risking downtime for other apps.

However these authentication keys are essentially configuration. It's both inconvenient and intuitively wrong to store configuration in the codebase. Alternative options I have explored include storing configuration in a database and caching it in memory, per-app apache environment variables and a shared json file.

Are there better options? Any gotchas I missed?

1 Answers1

0

It sounds like maybe an environment variable would work best for your purposes, which could then be accessed in your apps like this:

$ APPNAME_AUTH_KEY="saf3t33553" ruby -e "puts ENV['APPNAME_AUTH_KEY']"
saf3t33553

A JSON file in a shared location, or even a plain ruby file would also do the trick. Storing the configuration in a database sounds overkill.

This is a topic I've written quite a bit about, if you want to dig deeper:

Writing configurable applications (part 1, part 2) (see the "Using the Shell Environment for configuration" section in part 2 especially)

Gregory Brown
  • 1,380
  • 9
  • 15
  • 1
    I agree that storing the configuration in a database is overkill, but the advantage is that you can change configuration without restarting the app. – Erik Nov 09 '12 at 15:11
  • That's a good point, but the same would be true for using a configuration file. If the sinatra apps in the OP's cluster are all sharing a database, maybe file vs. database have similar pros and cons, except that editing the values in a database requires more work than editing a file. – Gregory Brown Nov 09 '12 at 15:16
  • Right, which means storing the keys in the apache configuration, as that is where you would set environment variables for sinatra apps running on apache/passenger. – Lucas Luitjes Nov 09 '12 at 15:26