From 09e20c3827a09184c5743ce11f64c69e64a6c62b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 15 Sep 2014 14:45:37 -0400 Subject: [PATCH] assistant: Detect when repository has been deleted or moved, and automatically shut down the assistant. Closes: #761261 --- Assistant/Restart.hs | 4 ++++ Assistant/Threads/SanityChecker.hs | 11 +++++++++++ Assistant/WebApp/Control.hs | 8 ++------ debian/changelog | 7 +++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Assistant/Restart.hs b/Assistant/Restart.hs index 0415e8e972..b74094f3bd 100644 --- a/Assistant/Restart.hs +++ b/Assistant/Restart.hs @@ -53,6 +53,10 @@ postRestart url = do liftIO . sendNotification . globalRedirNotifier =<< getDaemonStatus void $ liftIO $ forkIO $ do threadDelaySeconds (Seconds 120) + terminateSelf + +terminateSelf :: IO () +terminateSelf = #ifndef mingw32_HOST_OS signalProcess sigTERM =<< getPID #else diff --git a/Assistant/Threads/SanityChecker.hs b/Assistant/Threads/SanityChecker.hs index dce2c2db75..3371f212fc 100644 --- a/Assistant/Threads/SanityChecker.hs +++ b/Assistant/Threads/SanityChecker.hs @@ -21,7 +21,9 @@ import Assistant.Drop import Assistant.Ssh import Assistant.TransferQueue import Assistant.Types.UrlRenderer +import Assistant.Restart import qualified Annex.Branch +import qualified Git import qualified Git.LsFiles import qualified Git.Command.Batch import qualified Git.Config @@ -146,6 +148,8 @@ waitForNextCheck = do - will block the watcher. -} dailyCheck :: UrlRenderer -> Assistant Bool dailyCheck urlrenderer = do + checkRepoExists + g <- liftAnnex gitRepo batchmaker <- liftIO getBatchCommandMaker @@ -203,6 +207,7 @@ dailyCheck urlrenderer = do hourlyCheck :: Assistant () hourlyCheck = do + checkRepoExists #ifndef mingw32_HOST_OS checkLogSize 0 #else @@ -316,3 +321,9 @@ cleanOld check f = go =<< catchMaybeIO getmtime getmtime = realToFrac . modificationTime <$> getSymbolicLinkStatus f go (Just mtime) | check mtime = nukeFile f go _ = noop + +checkRepoExists :: Assistant () +checkRepoExists = do + g <- liftAnnex gitRepo + liftIO $ unlessM (doesDirectoryExist $ Git.repoPath g) $ + terminateSelf diff --git a/Assistant/WebApp/Control.hs b/Assistant/WebApp/Control.hs index 7141cc7803..5e197d8aed 100644 --- a/Assistant/WebApp/Control.hs +++ b/Assistant/WebApp/Control.hs @@ -53,15 +53,11 @@ getShutdownConfirmedR = do - page time to load in the browser. -} void $ liftIO $ forkIO $ do threadDelay 2000000 -#ifndef mingw32_HOST_OS - signalProcess sigTERM =<< getPID -#else - terminatePID =<< getPID -#endif + terminateSelf redirect NotRunningR {- Use a custom page to avoid putting long polling elements on it that will - - fail and cause the web browser to show an error once the webapp is + - fail and cause thet web browser to show an error once the webapp is - truely stopped. -} getNotRunningR :: Handler Html getNotRunningR = customPage' False Nothing $ diff --git a/debian/changelog b/debian/changelog index 4986b323e5..cd6cfd2288 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +git-annex (5.20140916) UNRELEASED; urgency=medium + + * assistant: Detect when repository has been deleted or moved, and + automatically shut down the assistant. Closes: #761261 + + -- Joey Hess Mon, 15 Sep 2014 14:39:17 -0400 + git-annex (5.20140915) unstable; urgency=medium * New annex.hardlink setting. Closes: #758593