diff --git a/.gitignore b/.gitignore index 1a8670b..710f5fe 100644 --- a/.gitignore +++ b/.gitignore @@ -14,13 +14,8 @@ config/client_session_key.aes yesod-devel/ # vervis -config/capability_signing_key -config/hashids_salt config/settings.yml config/ssh-host-key config/ssh-host-key.pub lib/ -repos/ -delivery-states/ -actor-counter.sqlite3 -delivery-counter.sqlite3 +state/ diff --git a/INSTALL.md b/INSTALL.md index c00a786..2665392 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -98,6 +98,10 @@ Build. This will also automatically install the GHC Haskell compiler. # (7) Configuration +Create a directory to hold mutable application state: + + $ mkdir state + Generate a new SSH key with a blank password: $ 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 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 the `delivery-state-dir` setting in `config/settings.yml`. For example, if you're keeping the default name: - $ mkdir delivery-states + $ mkdir state/delivery-states # (8) Development and deployment diff --git a/config/settings-default.yaml b/config/settings-default.yaml index 13a2877..63a91b7 100644 --- a/config/settings-default.yaml +++ b/config/settings-default.yaml @@ -77,13 +77,12 @@ database: max-instance-keys: 2 max-actor-keys: 2 -delivery-state-dir: delivery-states +state-dir: state ############################################################################### # Version control repositories ############################################################################### -repo-dir: repos diff-context-lines: 5 #post-receive-hook: /home/joe/.local/bin/vervis-post-receive #post-apply-hook: /home/joe/.local/bin/vervis-post-apply @@ -148,12 +147,6 @@ resident-factories: [] # * Deliver local activities to other servers 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 # record but reached the limit setting reject-on-max-keys: true diff --git a/src/Vervis/Application.hs b/src/Vervis/Application.hs index 487a0f3..379dfc2 100644 --- a/src/Vervis/Application.hs +++ b/src/Vervis/Application.hs @@ -161,6 +161,10 @@ import Vervis.Persist.Collab import Data.Either.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 -- of the call to mkYesodData which occurs in Foundation.hs. Please see the -- comments there for more details. @@ -251,8 +255,13 @@ makeFoundation appSettings = do setup <- isInitialSetup pool schemaBackend loadMode <- determineKeyFileLoadMode setup - capSignKey <- loadKeyFile loadMode $ appCapabilitySigningKeyFile appSettings - hashidsSalt <- loadKeyFile loadMode $ appHashidsSaltFile appSettings + -- Remove these 3 lines when 2025 comes + 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 app = mkFoundation pool capSignKey hashidsCtx (error "theater") (error "env") (error "launcher") (error "actors") @@ -270,13 +279,13 @@ makeFoundation appSettings = do writePostApplyHooks -- Launch actor threads and fill the actor map - let delieryStateDir = appDeliveryStateDir appSettings + let delieryStateDir = appStateDir appSettings "deliveries" exists <- doesDirectoryExist delieryStateDir unless exists $ error $ "delivery-state-dir not found: " ++ delieryStateDir delivery <- do micros <- intervalMicros $ appDeliveryRetryBase appSettings startDeliveryTheater - "delivery-counter.sqlite3" (sitePostSignedHeaders app) micros appHttpManager logFunc delieryStateDir + "state/delivery-counter.sqlite3" (sitePostSignedHeaders app) micros appHttpManager logFunc delieryStateDir actorTVars <- do p <- newTVarIO HM.empty j <- newTVarIO HM.empty @@ -291,7 +300,7 @@ makeFoundation appSettings = do render = yesodRender app root env = Env appSettings pool hashidsCtx appActorKeys delivery render appHttpManager appActorFetchShare actorTVars 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 let hostString = T.unpack $ renderAuthority hLocal diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index fcace4f..c5d139f 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -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 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 :: (MonadSite m, SiteEnv m ~ App) => Host -> HashidsContext -> [Migration m] @@ -2236,7 +2244,9 @@ changes hLocal ctx = , unchecked $ lift $ do rs <- selectList [] [Asc Repo396Id] 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) dir <- actor396Name <$> getJust (repo396Actor r) let oldSharer = @@ -3932,6 +3942,16 @@ changes hLocal ctx = , addFieldPrimRequired "Factory" True "allowProject" -- 667 , 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 diff --git a/src/Vervis/Path.hs b/src/Vervis/Path.hs index 58b0706..a0c0e5d 100644 --- a/src/Vervis/Path.hs +++ b/src/Vervis/Path.hs @@ -1,6 +1,7 @@ {- This file is part of Vervis. - - - Written in 2016, 2019, 2022, 2023 by fr33domlover . + - Written in 2016, 2019, 2022, 2023, 2024 + - by fr33domlover . - - ♡ Copying is an act of love. Please copy, reuse and share. - @@ -37,10 +38,10 @@ import Vervis.Model import Vervis.Settings askRepoRootDir :: (MonadSite m, SiteEnv m ~ App) => m FilePath -askRepoRootDir = asksSite $ appRepoDir . appSettings +askRepoRootDir = asksSite $ ( "repos") . appStateDir . appSettings askRepoRootDir' :: Act FilePath -askRepoRootDir' = asksEnv $ appRepoDir . envSettings +askRepoRootDir' = asksEnv $ ( "repos") . appStateDir . envSettings repoDir :: FilePath -> KeyHashid Repo -> FilePath repoDir root repo = root (T.unpack $ keyHashidText repo) diff --git a/src/Vervis/Settings.hs b/src/Vervis/Settings.hs index 2aaac06..9d0eaf6 100644 --- a/src/Vervis/Settings.hs +++ b/src/Vervis/Settings.hs @@ -91,8 +91,8 @@ data AppSettings = AppSettings -- | Maximal number of keys (personal keys or usage of shared keys) to -- remember cached in our database per remote actor. , appMaxActorKeys :: Maybe Int - -- | Path of the directory in which DeliveryTheater actor state is stored - , appDeliveryStateDir :: FilePath + -- | Path of the directory in which actor state is stored + , appStateDir :: FilePath -- | The instance's host (e.g. \"dev.angeley.es\"). Used for determining -- which requests are remote and which are for this instance, and for -- 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. --, 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 , appDiffContextLines :: Int -- | Path of the Vervis post-receive hook executable @@ -171,11 +169,6 @@ data AppSettings = AppSettings -- * Accept activities from users in the outbox -- * Deliver local activities to other servers , 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 -- 'VerifKeySharedUsage' into the database, but we've reached the -- configured storage limit. @@ -225,7 +218,7 @@ instance FromJSON AppSettings where appDatabaseConf <- o .: "database" appMaxInstanceKeys <- o .:? "max-instance-keys" appMaxActorKeys <- o .:? "max-actor-keys" - appDeliveryStateDir <- o .: "delivery-state-dir" + appStateDir <- o .: "state-dir" port <- o .: "http-port" appInstanceHost <- do h <- o .: "instance-host" @@ -252,7 +245,6 @@ instance FromJSON AppSettings where --appLoadFontFromLibData <- o .:? "load-font-from-lib-data" .!= defaultDev - appRepoDir <- o .: "repo-dir" appDiffContextLines <- o .: "diff-context-lines" appPostReceiveHookFile <- o .:? "post-receive-hook" .!= detectedHookFile appPostApplyHookFile <- o .:? "post-apply-hook" .!= detectedDarcsHookFile @@ -266,8 +258,6 @@ instance FromJSON AppSettings where appResidentFactories <- o .:? "resident-factories" .!= [] appFederation <- o .:? "federation" .!= False - appCapabilitySigningKeyFile <- o .: "capability-signing-key" - appHashidsSaltFile <- o .: "hashids-salt-file" appRejectOnMaxKeys <- o .: "reject-on-max-keys" appDropDeliveryAfter <- ndt <$> o .: "drop-delivery-after" appDeliveryRetryBase <- interval <$> o .: "retry-delivery-base" diff --git a/src/Vervis/Ssh.hs b/src/Vervis/Ssh.hs index ddd8033..bbedb04 100644 --- a/src/Vervis/Ssh.hs +++ b/src/Vervis/Ssh.hs @@ -370,7 +370,7 @@ mkConfig settings ctx pool logFunc theater reposVar = do flip runReaderT pool . flip runLoggingT logFunc } , cChannel = ChannelConfig - { ccRequestHandler = handle (decodeKeyHashidPure ctx) (appRepoDir settings) + { ccRequestHandler = handle (decodeKeyHashidPure ctx) (appStateDir settings "repos") , ccRunBaseMonad = flip runReaderT (pool, theater, reposVar) . flip runLoggingT logFunc }