add support for fully automatic upgrades
The Upgrader avoids checking for upgrades on startup when it was just upgraded. This avoids an upgrade loop if something goes wrong. One example of something going wrong would be if the upgrade info file and the distribution file get out of sync (or the distribution file is cached in a proxy), so it thinks it has upgraded to a new version, but has really not.
This commit is contained in:
parent
f04786f984
commit
6165284e39
4 changed files with 22 additions and 14 deletions
|
@ -153,7 +153,7 @@ startDaemon assistant foreground startdelay cannotrun listenhost startbrowser =
|
|||
#endif
|
||||
, assist $ netWatcherThread
|
||||
, assist $ upgraderThread urlrenderer
|
||||
, assist $ upgradWatcherThread urlrenderer
|
||||
, assist $ upgradeWatcherThread urlrenderer
|
||||
, assist $ netWatcherFallbackThread
|
||||
, assist $ transferScannerThread urlrenderer
|
||||
, assist $ cronnerThread urlrenderer
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
{-# LANGUAGE CPP #-}
|
||||
|
||||
module Assistant.Threads.UpgradeWatcher (
|
||||
upgradWatcherThread
|
||||
upgradeWatcherThread
|
||||
) where
|
||||
|
||||
import Assistant.Common
|
||||
|
@ -30,9 +30,9 @@ import qualified Data.Text as T
|
|||
data WatcherState = InStartupScan | Started | Upgrading
|
||||
deriving (Eq)
|
||||
|
||||
upgradWatcherThread :: UrlRenderer -> NamedThread
|
||||
upgradWatcherThread urlrenderer = namedThread "UpgradeWatcher" $ do
|
||||
whenM (liftIO $ checkSuccessfulUpgrade) $
|
||||
upgradeWatcherThread :: UrlRenderer -> NamedThread
|
||||
upgradeWatcherThread urlrenderer = namedThread "UpgradeWatcher" $ do
|
||||
whenM (liftIO checkSuccessfulUpgrade) $
|
||||
showSuccessfulUpgrade urlrenderer
|
||||
go =<< liftIO upgradeFlagFile
|
||||
where
|
||||
|
|
|
@ -12,6 +12,8 @@ module Assistant.Threads.Upgrader (
|
|||
) where
|
||||
|
||||
import Assistant.Common
|
||||
import Assistant.Upgrade
|
||||
|
||||
import Assistant.Types.UrlRenderer
|
||||
import Assistant.DaemonStatus
|
||||
import Assistant.Alert
|
||||
|
@ -31,11 +33,14 @@ import Data.Time.Clock
|
|||
import qualified Data.Text as T
|
||||
|
||||
upgraderThread :: UrlRenderer -> NamedThread
|
||||
upgraderThread urlrenderer = namedThread "Upgrader" $ do
|
||||
checkUpgrade urlrenderer
|
||||
upgraderThread urlrenderer = namedThread "Upgrader" $
|
||||
when (isJust Build.SysConfig.upgradelocation) $ do
|
||||
{- Check for upgrade on startup, unless it was just
|
||||
- upgraded. -}
|
||||
unlessM (liftIO checkSuccessfulUpgrade) $
|
||||
checkUpgrade urlrenderer
|
||||
h <- liftIO . newNotificationHandle False . networkConnectedNotifier =<< getDaemonStatus
|
||||
go h Nothing
|
||||
go h =<< liftIO getCurrentTime
|
||||
where
|
||||
{- Wait for a network connection event. Then see if it's been
|
||||
- half a day since the last upgrade check. If so, proceed with
|
||||
|
@ -47,10 +52,10 @@ upgraderThread urlrenderer = namedThread "Upgrader" $ do
|
|||
then go h lastchecked
|
||||
else do
|
||||
now <- liftIO getCurrentTime
|
||||
if maybe True (\t -> diffUTCTime now t > halfday) lastchecked
|
||||
if diffUTCTime now lastchecked > halfday
|
||||
then do
|
||||
checkUpgrade urlrenderer
|
||||
go h =<< Just <$> liftIO getCurrentTime
|
||||
go h =<< liftIO getCurrentTime
|
||||
else go h lastchecked
|
||||
halfday = 12 * 60 * 60
|
||||
|
||||
|
@ -71,13 +76,16 @@ checkUpgrade urlrenderer = do
|
|||
else debug [ "No new version found." ]
|
||||
|
||||
canUpgrade :: AlertPriority -> UrlRenderer -> GitAnnexDistribution -> Assistant ()
|
||||
canUpgrade urgency urlrenderer d = do
|
||||
canUpgrade urgency urlrenderer d = ifM autoUpgradeEnabled
|
||||
( startDistributionDownload d
|
||||
, do
|
||||
#ifdef WITH_WEBAPP
|
||||
button <- mkAlertButton True (T.pack "Upgrade") urlrenderer (ConfigStartUpgradeR d)
|
||||
void $ addAlert (canUpgradeAlert urgency button)
|
||||
button <- mkAlertButton True (T.pack "Upgrade") urlrenderer (ConfigStartUpgradeR d)
|
||||
void $ addAlert (canUpgradeAlert urgency button)
|
||||
#else
|
||||
noop
|
||||
noop
|
||||
#endif
|
||||
)
|
||||
|
||||
getDistributionInfo :: Assistant (Maybe GitAnnexDistribution)
|
||||
getDistributionInfo = do
|
||||
|
|
BIN
doc/assistant/upgradecomplete.png
Normal file
BIN
doc/assistant/upgradecomplete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
Loading…
Reference in a new issue