2013-11-21 21:49:56 +00:00
|
|
|
{- git-annex assistant webapp upgrade UI
|
|
|
|
-
|
|
|
|
- Copyright 2013 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings #-}
|
|
|
|
|
|
|
|
module Assistant.WebApp.Configurators.Upgrade where
|
|
|
|
|
|
|
|
import Assistant.WebApp.Common
|
2013-11-23 03:12:06 +00:00
|
|
|
import qualified Annex
|
2013-11-21 21:49:56 +00:00
|
|
|
import Types.Distribution
|
2013-11-23 03:12:06 +00:00
|
|
|
import Assistant.WebApp.OtherRepos
|
|
|
|
import Assistant.Threads.Watcher
|
|
|
|
import Assistant.Alert
|
|
|
|
import Assistant.DaemonStatus
|
|
|
|
import Assistant.NamedThread
|
|
|
|
import Utility.ThreadScheduler
|
2013-11-21 21:49:56 +00:00
|
|
|
import Utility.HumanTime
|
2013-11-23 03:12:06 +00:00
|
|
|
import Git
|
2013-11-21 21:49:56 +00:00
|
|
|
|
|
|
|
import Data.Time.Clock
|
2013-11-23 03:12:06 +00:00
|
|
|
import Control.Concurrent
|
2013-11-23 03:42:16 +00:00
|
|
|
import System.Posix (getProcessID, signalProcess, sigTERM)
|
2013-11-21 21:49:56 +00:00
|
|
|
|
2013-11-23 03:12:06 +00:00
|
|
|
getConfigStartUpgradeR :: GitAnnexDistribution -> Handler Html
|
|
|
|
getConfigStartUpgradeR d = page "Upgrade git-annex" (Just Configuration) $ do
|
2013-11-21 21:49:56 +00:00
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
let upgradeage = Duration $ floor $
|
|
|
|
now `diffUTCTime` distributionReleasedate d
|
2013-11-23 03:12:06 +00:00
|
|
|
$(widgetFile "configurators/upgrade/start")
|
2013-11-21 21:49:56 +00:00
|
|
|
|
2013-11-23 03:12:06 +00:00
|
|
|
{- Finish upgrade by starting the new assistant in the same repository this
|
|
|
|
- one is running in, and redirecting to it.
|
|
|
|
-
|
|
|
|
- Before the new assistant can be started, have to remove our
|
|
|
|
- gitAnnexUrlFile and our gitAnnexPidFile. Pausing the watcher is also
|
|
|
|
- a good idea, to avoid fighting when two assistants are running in the
|
|
|
|
- same repo.
|
2013-11-23 03:42:16 +00:00
|
|
|
-
|
|
|
|
- Note that only the tag that requested this page gets redirected.
|
|
|
|
- If the user has multiple web browser tabs open to the webapp,
|
|
|
|
- the others will show the upgradingAlert, and keep running until
|
|
|
|
- this process is terminated.
|
2013-11-23 03:12:06 +00:00
|
|
|
-}
|
|
|
|
getConfigFinishUpgradeR :: Handler Html
|
|
|
|
getConfigFinishUpgradeR = do
|
|
|
|
liftAssistant $ void $ addAlert upgradingAlert
|
|
|
|
liftIO . maybe noop (`throwTo` PauseWatcher) =<< liftAssistant (namedThreadId watchThread)
|
|
|
|
liftIO . nukeFile =<< liftAnnex (fromRepo gitAnnexUrlFile)
|
|
|
|
liftIO . nukeFile =<< liftAnnex (fromRepo gitAnnexPidFile)
|
2013-11-23 03:42:16 +00:00
|
|
|
reapself `after` startnewprocess
|
2013-11-23 03:12:06 +00:00
|
|
|
where
|
|
|
|
-- Wait for the redirect to be served to the browser
|
|
|
|
-- before terminating this process.
|
2013-11-23 03:42:16 +00:00
|
|
|
reapself = liftIO $ void $ forkIO $ do
|
|
|
|
threadDelaySeconds (Seconds 120)
|
|
|
|
signalProcess sigTERM =<< getProcessID
|
|
|
|
startnewprocess = switchToAssistant
|
|
|
|
=<< liftAnnex (repoLocation <$> Annex.gitRepo)
|