use global webapp redirects when shutting down
This commit is contained in:
parent
b1a89c448a
commit
6802123f7d
7 changed files with 38 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
|||
{- git-annex assistant webapp control
|
||||
-
|
||||
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
||||
- Copyright 2012, 2013 Joey Hess <joey@kitenet.net>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -10,15 +10,17 @@
|
|||
module Assistant.WebApp.Control where
|
||||
|
||||
import Assistant.WebApp.Common
|
||||
import Utility.LogFile
|
||||
import Assistant.DaemonStatus
|
||||
import Assistant.Alert
|
||||
import Assistant.TransferSlots
|
||||
import Assistant.Restart
|
||||
import Utility.LogFile
|
||||
import Utility.NotificationBroadcaster
|
||||
|
||||
import Control.Concurrent
|
||||
import System.Posix (getProcessID, signalProcess, sigTERM)
|
||||
import qualified Data.Map as M
|
||||
import qualified Data.Text as T
|
||||
|
||||
getShutdownR :: Handler Html
|
||||
getShutdownR = page "Shutdown" Nothing $
|
||||
|
@ -37,12 +39,25 @@ getShutdownConfirmedR = do
|
|||
ts <- M.keys . currentTransfers <$> getDaemonStatus
|
||||
mapM_ pauseTransfer ts
|
||||
page "Shutdown" Nothing $ do
|
||||
webapp <- getYesod
|
||||
let url = T.unpack $ yesodRender webapp (T.pack "") NotRunningR []
|
||||
{- Signal any other web browsers. -}
|
||||
liftAssistant $ do
|
||||
modifyDaemonStatus_ $ \status -> status { globalRedirUrl = Just url }
|
||||
liftIO . sendNotification . globalRedirNotifier =<< getDaemonStatus
|
||||
{- Wait 2 seconds before shutting down, to give the web
|
||||
- page time to load in the browser. -}
|
||||
void $ liftIO $ forkIO $ do
|
||||
threadDelay 2000000
|
||||
signalProcess sigTERM =<< getProcessID
|
||||
$(widgetFile "control/shutdownconfirmed")
|
||||
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
|
||||
- truely stopped. -}
|
||||
getNotRunningR :: Handler Html
|
||||
getNotRunningR = customPage' False Nothing $
|
||||
$(widgetFile "control/notrunning")
|
||||
|
||||
getRestartR :: Handler Html
|
||||
getRestartR = do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue