about summary refs log tree commit diff
path: root/services/tazblog/db/Main.hs
blob: 9523041f109aec3477b4d48971c99a24c0cd989a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- | Main module for the database server
module Main where

import           BlogDB              (initialBlogState)
import           Control.Applicative (pure, (<$>), (<*>))
import           Control.Exception   (bracket)
import           Data.Acid
import           Data.Acid.Local     (createCheckpointAndClose)
import           Data.Acid.Remote
import           Data.Word
import           Network             (PortID (..))
import           Options

data DBOptions = DBOptions {
  dbPort         :: Word16,
  stateDirectory :: String
}

instance Options DBOptions where
  defineOptions = pure DBOptions
    <*> simpleOption "dbport" 8070
        "Port to serve acid-state on remotely."
    <*> simpleOption "state" "/var/tazblog/state"
        "Directory in which the acid-state is located."

main :: IO ()
main = do
    putStrLn ("Launching TazBlog database server ...")
    runCommand $ \opts args ->
      bracket (openState opts) createCheckpointAndClose
              (acidServer skipAuthenticationCheck $ getPort opts)
  where
    openState o = openLocalStateFrom (stateDirectory o) initialBlogState
    getPort = PortNumber . fromIntegral . dbPort