about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2015-11-19T18·04+0100
committerVincent Ambo <tazjin@gmail.com>2015-11-19T18·04+0100
commite9f044e6d5a8f3112981e100a37457a75d74b572 (patch)
treef51b1522f67e04c802155249a9719d933028240a
parent0f6ff6310ed93b6221120f23ec085c1b7951de5b (diff)
Add tazblog-db executable
-rw-r--r--db/Main.hs34
-rw-r--r--tazblog.cabal11
2 files changed, 45 insertions, 0 deletions
diff --git a/db/Main.hs b/db/Main.hs
new file mode 100644
index 000000000000..9523041f109a
--- /dev/null
+++ b/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
diff --git a/tazblog.cabal b/tazblog.cabal
index 6bbe2c01f0ef..36af795b1345 100644
--- a/tazblog.cabal
+++ b/tazblog.cabal
@@ -56,3 +56,14 @@ executable tazblog
                  acid-state,
                  tazblog,
                  options
+
+executable tazblog-db
+  hs-source-dirs: db
+  main-is: Main.hs
+  default-language: Haskell2010
+  ghc-options: -threaded -rtsopts -with-rtsopts=-N
+  build-depends: base,
+                 acid-state,
+                 tazblog,
+                 options,
+                 network