1 {-| Path-related helper functions.
7 Copyright (C) 2012 Google Inc.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
38 , jobQueueArchiveSubDir
41 import System.FilePath
42 import System.Posix.Env (getEnvDefault)
44 import qualified Ganeti.Constants as C
46 -- | Simple helper to concat two paths.
47 pjoin :: IO String -> String -> IO String
52 -- | Returns the root directory, which can be either the real root or
54 getRootDir :: IO FilePath
55 getRootDir = getEnvDefault "GANETI_ROOTDIR" ""
57 -- | Prefixes a path with the current root directory.
58 addNodePrefix :: FilePath -> IO FilePath
59 addNodePrefix path = do
63 -- | Directory for data.
64 dataDir :: IO FilePath
65 dataDir = addNodePrefix $ C.autoconfLocalstatedir </> "lib" </> "ganeti"
67 -- | Helper for building on top of dataDir (internal).
68 dataDirP :: FilePath -> IO FilePath
69 dataDirP = (dataDir `pjoin`)
71 -- | Directory for runtime files.
73 runDir = addNodePrefix $ C.autoconfLocalstatedir </> "run" </> "ganeti"
75 -- | Directory for log files.
77 logDir = addNodePrefix $ C.autoconfLocalstatedir </> "log" </> "ganeti"
79 -- | Directory for Unix sockets.
80 socketDir :: IO FilePath
81 socketDir = runDir `pjoin` "socket"
83 -- | The default LUXI socket path.
84 defaultLuxiSocket :: IO FilePath
85 defaultLuxiSocket = socketDir `pjoin` "ganeti-master"
87 -- | The default LUXI socket for queries.
88 defaultQuerySocket :: IO FilePath
89 defaultQuerySocket = socketDir `pjoin` "ganeti-query"
91 -- | Path to file containing confd's HMAC key.
92 confdHmacKey :: IO FilePath
93 confdHmacKey = dataDirP "hmac.key"
95 -- | Path to cluster configuration file.
96 clusterConfFile :: IO FilePath
97 clusterConfFile = dataDirP "config.data"
99 -- | Path to the noded certificate.
100 nodedCertFile :: IO FilePath
101 nodedCertFile = dataDirP "server.pem"
103 -- | Job queue directory.
104 queueDir :: IO FilePath
105 queueDir = dataDirP "queue"
107 -- | Job queue serial file.
108 jobQueueSerialFile :: IO FilePath
109 jobQueueSerialFile = dataDirP "serial"
111 -- | Job queue archive directory.
112 jobQueueArchiveSubDir :: FilePath
113 jobQueueArchiveSubDir = "archive"