Start moving app state to ./state dir
This is in preparation for the Dockerfile
This commit is contained in:
parent
cdc97dcb8b
commit
27f1fe2db3
8 changed files with 51 additions and 39 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -14,13 +14,8 @@ config/client_session_key.aes
|
||||||
yesod-devel/
|
yesod-devel/
|
||||||
|
|
||||||
# vervis
|
# vervis
|
||||||
config/capability_signing_key
|
|
||||||
config/hashids_salt
|
|
||||||
config/settings.yml
|
config/settings.yml
|
||||||
config/ssh-host-key
|
config/ssh-host-key
|
||||||
config/ssh-host-key.pub
|
config/ssh-host-key.pub
|
||||||
lib/
|
lib/
|
||||||
repos/
|
state/
|
||||||
delivery-states/
|
|
||||||
actor-counter.sqlite3
|
|
||||||
delivery-counter.sqlite3
|
|
||||||
|
|
|
@ -98,6 +98,10 @@ Build. This will also automatically install the GHC Haskell compiler.
|
||||||
|
|
||||||
# (7) Configuration
|
# (7) Configuration
|
||||||
|
|
||||||
|
Create a directory to hold mutable application state:
|
||||||
|
|
||||||
|
$ mkdir state
|
||||||
|
|
||||||
Generate a new SSH key with a blank password:
|
Generate a new SSH key with a blank password:
|
||||||
|
|
||||||
$ ssh-keygen -t rsa -m PEM -f config/ssh-host-key
|
$ ssh-keygen -t rsa -m PEM -f config/ssh-host-key
|
||||||
|
@ -112,13 +116,13 @@ Create a directory that will keep all the VCS repositories hosted by Vervis.
|
||||||
Its name should match the `repo-dir` setting in `config/settings.yml`. For
|
Its name should match the `repo-dir` setting in `config/settings.yml`. For
|
||||||
example, if you're keeping the default name:
|
example, if you're keeping the default name:
|
||||||
|
|
||||||
$ mkdir repos
|
$ mkdir state/repos
|
||||||
|
|
||||||
Create a directory that will keep remote delivery state. Its name should match
|
Create a directory that will keep remote delivery state. Its name should match
|
||||||
the `delivery-state-dir` setting in `config/settings.yml`. For example, if
|
the `delivery-state-dir` setting in `config/settings.yml`. For example, if
|
||||||
you're keeping the default name:
|
you're keeping the default name:
|
||||||
|
|
||||||
$ mkdir delivery-states
|
$ mkdir state/delivery-states
|
||||||
|
|
||||||
# (8) Development and deployment
|
# (8) Development and deployment
|
||||||
|
|
||||||
|
|
|
@ -77,13 +77,12 @@ database:
|
||||||
max-instance-keys: 2
|
max-instance-keys: 2
|
||||||
max-actor-keys: 2
|
max-actor-keys: 2
|
||||||
|
|
||||||
delivery-state-dir: delivery-states
|
state-dir: state
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Version control repositories
|
# Version control repositories
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
repo-dir: repos
|
|
||||||
diff-context-lines: 5
|
diff-context-lines: 5
|
||||||
#post-receive-hook: /home/joe/.local/bin/vervis-post-receive
|
#post-receive-hook: /home/joe/.local/bin/vervis-post-receive
|
||||||
#post-apply-hook: /home/joe/.local/bin/vervis-post-apply
|
#post-apply-hook: /home/joe/.local/bin/vervis-post-apply
|
||||||
|
@ -148,12 +147,6 @@ resident-factories: []
|
||||||
# * Deliver local activities to other servers
|
# * Deliver local activities to other servers
|
||||||
federation: false
|
federation: false
|
||||||
|
|
||||||
# Signing key file for signing object capabilities sent to remote users
|
|
||||||
capability-signing-key: config/capability_signing_key
|
|
||||||
|
|
||||||
# Salt file for encoding and decoding hashids
|
|
||||||
hashids-salt-file: config/hashids_salt
|
|
||||||
|
|
||||||
# Whether to reject an HTTP signature when we want to insert a new key or usage
|
# Whether to reject an HTTP signature when we want to insert a new key or usage
|
||||||
# record but reached the limit setting
|
# record but reached the limit setting
|
||||||
reject-on-max-keys: true
|
reject-on-max-keys: true
|
||||||
|
|
|
@ -161,6 +161,10 @@ import Vervis.Persist.Collab
|
||||||
import Data.Either.Local
|
import Data.Either.Local
|
||||||
import Database.Persist.Local
|
import Database.Persist.Local
|
||||||
|
|
||||||
|
moveFileIfExists from to = do
|
||||||
|
exists <- doesFileExist from
|
||||||
|
when exists $ renameFile from to
|
||||||
|
|
||||||
-- This line actually creates our YesodDispatch instance. It is the second half
|
-- This line actually creates our YesodDispatch instance. It is the second half
|
||||||
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the
|
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the
|
||||||
-- comments there for more details.
|
-- comments there for more details.
|
||||||
|
@ -251,8 +255,13 @@ makeFoundation appSettings = do
|
||||||
setup <- isInitialSetup pool schemaBackend
|
setup <- isInitialSetup pool schemaBackend
|
||||||
loadMode <- determineKeyFileLoadMode setup
|
loadMode <- determineKeyFileLoadMode setup
|
||||||
|
|
||||||
capSignKey <- loadKeyFile loadMode $ appCapabilitySigningKeyFile appSettings
|
-- Remove these 3 lines when 2025 comes
|
||||||
hashidsSalt <- loadKeyFile loadMode $ appHashidsSaltFile appSettings
|
createDirectoryIfMissing False "state"
|
||||||
|
moveFileIfExists "config/capability_signing_key" "state/capability_signing_key"
|
||||||
|
moveFileIfExists "config/hashids_salt" "state/hashids_salt"
|
||||||
|
|
||||||
|
capSignKey <- loadKeyFile loadMode $ appStateDir appSettings </> "capability_signing_key"
|
||||||
|
hashidsSalt <- loadKeyFile loadMode $ appStateDir appSettings </> "hashids_salt"
|
||||||
let hashidsCtx = hashidsContext hashidsSalt
|
let hashidsCtx = hashidsContext hashidsSalt
|
||||||
|
|
||||||
app = mkFoundation pool capSignKey hashidsCtx (error "theater") (error "env") (error "launcher") (error "actors")
|
app = mkFoundation pool capSignKey hashidsCtx (error "theater") (error "env") (error "launcher") (error "actors")
|
||||||
|
@ -270,13 +279,13 @@ makeFoundation appSettings = do
|
||||||
writePostApplyHooks
|
writePostApplyHooks
|
||||||
|
|
||||||
-- Launch actor threads and fill the actor map
|
-- Launch actor threads and fill the actor map
|
||||||
let delieryStateDir = appDeliveryStateDir appSettings
|
let delieryStateDir = appStateDir appSettings </> "deliveries"
|
||||||
exists <- doesDirectoryExist delieryStateDir
|
exists <- doesDirectoryExist delieryStateDir
|
||||||
unless exists $ error $ "delivery-state-dir not found: " ++ delieryStateDir
|
unless exists $ error $ "delivery-state-dir not found: " ++ delieryStateDir
|
||||||
delivery <- do
|
delivery <- do
|
||||||
micros <- intervalMicros $ appDeliveryRetryBase appSettings
|
micros <- intervalMicros $ appDeliveryRetryBase appSettings
|
||||||
startDeliveryTheater
|
startDeliveryTheater
|
||||||
"delivery-counter.sqlite3" (sitePostSignedHeaders app) micros appHttpManager logFunc delieryStateDir
|
"state/delivery-counter.sqlite3" (sitePostSignedHeaders app) micros appHttpManager logFunc delieryStateDir
|
||||||
actorTVars <- do
|
actorTVars <- do
|
||||||
p <- newTVarIO HM.empty
|
p <- newTVarIO HM.empty
|
||||||
j <- newTVarIO HM.empty
|
j <- newTVarIO HM.empty
|
||||||
|
@ -291,7 +300,7 @@ makeFoundation appSettings = do
|
||||||
render = yesodRender app root
|
render = yesodRender app root
|
||||||
env = Env appSettings pool hashidsCtx appActorKeys delivery render appHttpManager appActorFetchShare actorTVars
|
env = Env appSettings pool hashidsCtx appActorKeys delivery render appHttpManager appActorFetchShare actorTVars
|
||||||
actors <- flip runWorker app $ runSiteDB $ loadTheater env
|
actors <- flip runWorker app $ runSiteDB $ loadTheater env
|
||||||
(theater, actorMap) <- startTheater "actor-counter.sqlite3" logFunc actors
|
(theater, actorMap) <- startTheater "state/actor-counter.sqlite3" logFunc actors
|
||||||
launcher <- startPersonLauncher theater env
|
launcher <- startPersonLauncher theater env
|
||||||
|
|
||||||
let hostString = T.unpack $ renderAuthority hLocal
|
let hostString = T.unpack $ renderAuthority hLocal
|
||||||
|
|
|
@ -127,6 +127,14 @@ renameUnique' entity@(EntityName e) old new =
|
||||||
(fromString $ "Unique" ++ T.unpack e ++ T.unpack old)
|
(fromString $ "Unique" ++ T.unpack e ++ T.unpack old)
|
||||||
(fromString $ "Unique" ++ T.unpack e ++ T.unpack new)
|
(fromString $ "Unique" ++ T.unpack e ++ T.unpack new)
|
||||||
|
|
||||||
|
moveDirIfExists from to = do
|
||||||
|
exists <- doesDirectoryExist from
|
||||||
|
when exists $ renameDirectory from to
|
||||||
|
|
||||||
|
moveFileIfExists from to = do
|
||||||
|
exists <- doesFileExist from
|
||||||
|
when exists $ renameFile from to
|
||||||
|
|
||||||
changes
|
changes
|
||||||
:: (MonadSite m, SiteEnv m ~ App)
|
:: (MonadSite m, SiteEnv m ~ App)
|
||||||
=> Host -> HashidsContext -> [Migration m]
|
=> Host -> HashidsContext -> [Migration m]
|
||||||
|
@ -2236,7 +2244,9 @@ changes hLocal ctx =
|
||||||
, unchecked $ lift $ do
|
, unchecked $ lift $ do
|
||||||
rs <- selectList [] [Asc Repo396Id]
|
rs <- selectList [] [Asc Repo396Id]
|
||||||
oldSharerDirs <- fmap (LO.nubSort . catMaybes) $ for rs $ \ (Entity rid r) -> do
|
oldSharerDirs <- fmap (LO.nubSort . catMaybes) $ for rs $ \ (Entity rid r) -> do
|
||||||
root <- asksSite $ appRepoDir . appSettings
|
root <- do
|
||||||
|
stateDir <- asksSite $ appStateDir . appSettings
|
||||||
|
return $ stateDir </> "repos"
|
||||||
parent <- sharer396Ident <$> getJust (repo396Sharer r)
|
parent <- sharer396Ident <$> getJust (repo396Sharer r)
|
||||||
dir <- actor396Name <$> getJust (repo396Actor r)
|
dir <- actor396Name <$> getJust (repo396Actor r)
|
||||||
let oldSharer =
|
let oldSharer =
|
||||||
|
@ -3932,6 +3942,16 @@ changes hLocal ctx =
|
||||||
, addFieldPrimRequired "Factory" True "allowProject"
|
, addFieldPrimRequired "Factory" True "allowProject"
|
||||||
-- 667
|
-- 667
|
||||||
, addFieldPrimRequired "Factory" True "allowTeam"
|
, addFieldPrimRequired "Factory" True "allowTeam"
|
||||||
|
-- 668
|
||||||
|
, unchecked $ lift $ liftIO $ do
|
||||||
|
moveDirIfExists "repos" "state/repos"
|
||||||
|
moveDirIfExists "delivery-states" "state/deliveries"
|
||||||
|
moveFileIfExists "actor-counter.sqlite3" "state/actor-counter.sqlite3"
|
||||||
|
moveFileIfExists "actor-counter.sqlite3-shm" "state/actor-counter.sqlite3-shm"
|
||||||
|
moveFileIfExists "actor-counter.sqlite3-wal" "state/actor-counter.sqlite3-wal"
|
||||||
|
moveFileIfExists "delivery-counter.sqlite3" "state/delivery-counter.sqlite3"
|
||||||
|
moveFileIfExists "delivery-counter.sqlite3-shm" "state/delivery-counter.sqlite3-shm"
|
||||||
|
moveFileIfExists "delivery-counter.sqlite3-wal" "state/delivery-counter.sqlite3-wal"
|
||||||
]
|
]
|
||||||
|
|
||||||
migrateDB
|
migrateDB
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{- This file is part of Vervis.
|
{- This file is part of Vervis.
|
||||||
-
|
-
|
||||||
- Written in 2016, 2019, 2022, 2023 by fr33domlover <fr33domlover@riseup.net>.
|
- Written in 2016, 2019, 2022, 2023, 2024
|
||||||
|
- by fr33domlover <fr33domlover@riseup.net>.
|
||||||
-
|
-
|
||||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||||
-
|
-
|
||||||
|
@ -37,10 +38,10 @@ import Vervis.Model
|
||||||
import Vervis.Settings
|
import Vervis.Settings
|
||||||
|
|
||||||
askRepoRootDir :: (MonadSite m, SiteEnv m ~ App) => m FilePath
|
askRepoRootDir :: (MonadSite m, SiteEnv m ~ App) => m FilePath
|
||||||
askRepoRootDir = asksSite $ appRepoDir . appSettings
|
askRepoRootDir = asksSite $ (</> "repos") . appStateDir . appSettings
|
||||||
|
|
||||||
askRepoRootDir' :: Act FilePath
|
askRepoRootDir' :: Act FilePath
|
||||||
askRepoRootDir' = asksEnv $ appRepoDir . envSettings
|
askRepoRootDir' = asksEnv $ (</> "repos") . appStateDir . envSettings
|
||||||
|
|
||||||
repoDir :: FilePath -> KeyHashid Repo -> FilePath
|
repoDir :: FilePath -> KeyHashid Repo -> FilePath
|
||||||
repoDir root repo = root </> (T.unpack $ keyHashidText repo)
|
repoDir root repo = root </> (T.unpack $ keyHashidText repo)
|
||||||
|
|
|
@ -91,8 +91,8 @@ data AppSettings = AppSettings
|
||||||
-- | Maximal number of keys (personal keys or usage of shared keys) to
|
-- | Maximal number of keys (personal keys or usage of shared keys) to
|
||||||
-- remember cached in our database per remote actor.
|
-- remember cached in our database per remote actor.
|
||||||
, appMaxActorKeys :: Maybe Int
|
, appMaxActorKeys :: Maybe Int
|
||||||
-- | Path of the directory in which DeliveryTheater actor state is stored
|
-- | Path of the directory in which actor state is stored
|
||||||
, appDeliveryStateDir :: FilePath
|
, appStateDir :: FilePath
|
||||||
-- | The instance's host (e.g. \"dev.angeley.es\"). Used for determining
|
-- | The instance's host (e.g. \"dev.angeley.es\"). Used for determining
|
||||||
-- which requests are remote and which are for this instance, and for
|
-- which requests are remote and which are for this instance, and for
|
||||||
-- generating URLs. The database relies on this value, and you shouldn't
|
-- generating URLs. The database relies on this value, and you shouldn't
|
||||||
|
@ -134,8 +134,6 @@ data AppSettings = AppSettings
|
||||||
-- library, instead of the app's production runtime data directory.
|
-- library, instead of the app's production runtime data directory.
|
||||||
--, appLoadFontFromLibData :: Bool
|
--, appLoadFontFromLibData :: Bool
|
||||||
|
|
||||||
-- | Path to the directory under which git repos are placed
|
|
||||||
, appRepoDir :: FilePath
|
|
||||||
-- | Number of context lines to display around changes in commit diff
|
-- | Number of context lines to display around changes in commit diff
|
||||||
, appDiffContextLines :: Int
|
, appDiffContextLines :: Int
|
||||||
-- | Path of the Vervis post-receive hook executable
|
-- | Path of the Vervis post-receive hook executable
|
||||||
|
@ -171,11 +169,6 @@ data AppSettings = AppSettings
|
||||||
-- * Accept activities from users in the outbox
|
-- * Accept activities from users in the outbox
|
||||||
-- * Deliver local activities to other servers
|
-- * Deliver local activities to other servers
|
||||||
, appFederation :: Bool
|
, appFederation :: Bool
|
||||||
-- | Signing key file for signing object capabilities sent to remote
|
|
||||||
-- users
|
|
||||||
, appCapabilitySigningKeyFile :: FilePath
|
|
||||||
-- | Salt for encoding and decoding hashids
|
|
||||||
, appHashidsSaltFile :: FilePath
|
|
||||||
-- | What do to when we wish to insert a new 'VerifKey' or
|
-- | What do to when we wish to insert a new 'VerifKey' or
|
||||||
-- 'VerifKeySharedUsage' into the database, but we've reached the
|
-- 'VerifKeySharedUsage' into the database, but we've reached the
|
||||||
-- configured storage limit.
|
-- configured storage limit.
|
||||||
|
@ -225,7 +218,7 @@ instance FromJSON AppSettings where
|
||||||
appDatabaseConf <- o .: "database"
|
appDatabaseConf <- o .: "database"
|
||||||
appMaxInstanceKeys <- o .:? "max-instance-keys"
|
appMaxInstanceKeys <- o .:? "max-instance-keys"
|
||||||
appMaxActorKeys <- o .:? "max-actor-keys"
|
appMaxActorKeys <- o .:? "max-actor-keys"
|
||||||
appDeliveryStateDir <- o .: "delivery-state-dir"
|
appStateDir <- o .: "state-dir"
|
||||||
port <- o .: "http-port"
|
port <- o .: "http-port"
|
||||||
appInstanceHost <- do
|
appInstanceHost <- do
|
||||||
h <- o .: "instance-host"
|
h <- o .: "instance-host"
|
||||||
|
@ -252,7 +245,6 @@ instance FromJSON AppSettings where
|
||||||
|
|
||||||
--appLoadFontFromLibData <- o .:? "load-font-from-lib-data" .!= defaultDev
|
--appLoadFontFromLibData <- o .:? "load-font-from-lib-data" .!= defaultDev
|
||||||
|
|
||||||
appRepoDir <- o .: "repo-dir"
|
|
||||||
appDiffContextLines <- o .: "diff-context-lines"
|
appDiffContextLines <- o .: "diff-context-lines"
|
||||||
appPostReceiveHookFile <- o .:? "post-receive-hook" .!= detectedHookFile
|
appPostReceiveHookFile <- o .:? "post-receive-hook" .!= detectedHookFile
|
||||||
appPostApplyHookFile <- o .:? "post-apply-hook" .!= detectedDarcsHookFile
|
appPostApplyHookFile <- o .:? "post-apply-hook" .!= detectedDarcsHookFile
|
||||||
|
@ -266,8 +258,6 @@ instance FromJSON AppSettings where
|
||||||
appResidentFactories <- o .:? "resident-factories" .!= []
|
appResidentFactories <- o .:? "resident-factories" .!= []
|
||||||
|
|
||||||
appFederation <- o .:? "federation" .!= False
|
appFederation <- o .:? "federation" .!= False
|
||||||
appCapabilitySigningKeyFile <- o .: "capability-signing-key"
|
|
||||||
appHashidsSaltFile <- o .: "hashids-salt-file"
|
|
||||||
appRejectOnMaxKeys <- o .: "reject-on-max-keys"
|
appRejectOnMaxKeys <- o .: "reject-on-max-keys"
|
||||||
appDropDeliveryAfter <- ndt <$> o .: "drop-delivery-after"
|
appDropDeliveryAfter <- ndt <$> o .: "drop-delivery-after"
|
||||||
appDeliveryRetryBase <- interval <$> o .: "retry-delivery-base"
|
appDeliveryRetryBase <- interval <$> o .: "retry-delivery-base"
|
||||||
|
|
|
@ -370,7 +370,7 @@ mkConfig settings ctx pool logFunc theater reposVar = do
|
||||||
flip runReaderT pool . flip runLoggingT logFunc
|
flip runReaderT pool . flip runLoggingT logFunc
|
||||||
}
|
}
|
||||||
, cChannel = ChannelConfig
|
, cChannel = ChannelConfig
|
||||||
{ ccRequestHandler = handle (decodeKeyHashidPure ctx) (appRepoDir settings)
|
{ ccRequestHandler = handle (decodeKeyHashidPure ctx) (appStateDir settings </> "repos")
|
||||||
, ccRunBaseMonad =
|
, ccRunBaseMonad =
|
||||||
flip runReaderT (pool, theater, reposVar) . flip runLoggingT logFunc
|
flip runReaderT (pool, theater, reposVar) . flip runLoggingT logFunc
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue