about summary refs log tree commit diff
path: root/services/tazblog/db/Main.hs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-06-28T21·55+0100
committerVincent Ambo <tazjin@google.com>2019-06-28T21·55+0100
commit2373c925e18963c6f2698ba4c45d74196f3aaaf3 (patch)
tree38a0c804881c71b24391129d9ca4092de1a7b583 /services/tazblog/db/Main.hs
parentaeeb11f1b76729115c4db98f419cbcda1a0f7660 (diff)
refactor: Move tazblog into monorepo structure
It's happening!
Diffstat (limited to 'services/tazblog/db/Main.hs')
-rw-r--r--services/tazblog/db/Main.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/services/tazblog/db/Main.hs b/services/tazblog/db/Main.hs
new file mode 100644
index 000000000000..9523041f109a
--- /dev/null
+++ b/services/tazblog/db/Main.hs
@@ -0,0 +1,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