support remote-server sytax in keter.yaml file, update README

This commit is contained in:
Josh Berman 2015-06-14 10:58:15 +03:00
parent 2dd22abdf8
commit 95503ad1f4
2 changed files with 32 additions and 16 deletions

View File

@ -50,7 +50,11 @@ instance Default Settings where
"';\nCREATE DATABASE " <> fromText dbiName <>
" OWNER " <> fromText dbiUser <>
";"
_ <- readProcess "sudo" ["-u", "postgres", "psql"] $ TL.unpack sql
cmd = [ "-u", "postgres", "psql"
, "-h", (T.unpack $ dbServer dbiServer)
, "-p", (show $ dbPort dbiServer)
, "-U", "postgres"]
_ <- readProcess "sudo" cmd $ TL.unpack sql
return ()
}
@ -70,8 +74,8 @@ data DBServerInfo = DBServerInfo
deriving Show
randomDBI :: DBServerInfo -> R.StdGen -> (DBInfo, R.StdGen)
randomDBI dbsi r =
S.runState (DBInfo <$> rt <*> rt <*> rt <*> (pure dbsi)) r
randomDBI dbsi =
S.runState (DBInfo <$> rt <*> rt <*> rt <*> (pure dbsi))
where
rt = T.pack <$> replicateM 10 (S.state $ R.randomR ('a', 'z'))
@ -127,21 +131,19 @@ load Settings{..} fp = do
return Plugin
{ pluginGetEnv = \appname o ->
case HMap.lookup "postgres" o of
Just (Array x) -> do
let Object o' = V.head x
dbServer = fromMaybe def . parseMaybe parseJSON $ V.head x
x <- newEmptyMVar
writeChan chan $ GetConfig appname dbServer $ putMVar x
edbi <- takeMVar x
edbiToEnv edbi
Just (Array v) -> do
let dbServer = fromMaybe def . parseMaybe parseJSON $ V.head v
doenv chan appname dbServer
Just (Bool True) -> do
x <- newEmptyMVar
writeChan chan $ GetConfig appname def $ putMVar x
edbi <- takeMVar x
edbiToEnv edbi
doenv chan appname def
_ -> return []
}
where doenv chan appname dbs = do
x <- newEmptyMVar
writeChan chan $ GetConfig appname dbs $ putMVar x
edbi <- takeMVar x
edbiToEnv edbi
tmpfp = fp <.> "tmp"
loop chan = do

16
README.md Normal file → Executable file
View File

@ -179,8 +179,22 @@ plugins:
postgres: true
```
* Keter can be configured to connect to a remote postgres server using the following syntax:
```yaml
plugins:
postgres:
- server: remoteServerNameOrIP
port: 1234
```
Different webapps can be configured to use different servers using the above syntax.
Keter will connect to the remote servers using the `postgres` account. This setup
assumes the remote server's `pg_hba.conf` file has been configured to allow connections
from the keter-server IP using the `trust` method.
(Note: The `plugins` configuration option was added in v1.0 of the
keter configuration syntax. If you are using v0.4 then use `postgres: true`.)
keter configuration syntax. If you are using v0.4 then use `postgres: true`.
The remote-postgres server syntax was added in v1.4.2.)
* Modify your application to get its database connection settings from the following environment variables:
* `PGHOST`