2012-07-31 16:17:31 +00:00
|
|
|
{- git-annex assistant webapp thread
|
2012-07-26 01:26:13 +00:00
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2013-06-05 01:02:09 +00:00
|
|
|
{-# LANGUAGE TemplateHaskell, MultiParamTypeClasses #-}
|
|
|
|
{-# LANGUAGE CPP #-}
|
2012-07-29 01:21:22 +00:00
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
2012-07-26 01:26:13 +00:00
|
|
|
|
|
|
|
module Assistant.Threads.WebApp where
|
|
|
|
|
|
|
|
import Assistant.Common
|
2012-07-31 05:11:32 +00:00
|
|
|
import Assistant.WebApp
|
2012-09-02 04:27:48 +00:00
|
|
|
import Assistant.WebApp.Types
|
2012-07-31 05:11:32 +00:00
|
|
|
import Assistant.WebApp.DashBoard
|
|
|
|
import Assistant.WebApp.SideBar
|
|
|
|
import Assistant.WebApp.Notifications
|
2013-03-13 01:51:03 +00:00
|
|
|
import Assistant.WebApp.RepoList
|
2012-07-31 05:11:32 +00:00
|
|
|
import Assistant.WebApp.Configurators
|
2012-08-31 19:17:12 +00:00
|
|
|
import Assistant.WebApp.Configurators.Local
|
|
|
|
import Assistant.WebApp.Configurators.Ssh
|
2012-09-08 04:26:47 +00:00
|
|
|
import Assistant.WebApp.Configurators.Pairing
|
2012-11-24 20:30:15 +00:00
|
|
|
import Assistant.WebApp.Configurators.AWS
|
2013-04-25 16:23:36 +00:00
|
|
|
import Assistant.WebApp.Configurators.IA
|
2012-11-17 19:30:11 +00:00
|
|
|
import Assistant.WebApp.Configurators.WebDAV
|
2012-10-26 18:17:09 +00:00
|
|
|
import Assistant.WebApp.Configurators.XMPP
|
2013-03-03 21:07:27 +00:00
|
|
|
import Assistant.WebApp.Configurators.Preferences
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
import Assistant.WebApp.Configurators.Unused
|
2013-03-31 20:38:05 +00:00
|
|
|
import Assistant.WebApp.Configurators.Edit
|
|
|
|
import Assistant.WebApp.Configurators.Delete
|
2013-10-10 22:02:33 +00:00
|
|
|
import Assistant.WebApp.Configurators.Fsck
|
2013-11-21 21:49:56 +00:00
|
|
|
import Assistant.WebApp.Configurators.Upgrade
|
2012-07-31 06:30:26 +00:00
|
|
|
import Assistant.WebApp.Documentation
|
2013-01-03 19:16:40 +00:00
|
|
|
import Assistant.WebApp.Control
|
2012-09-18 21:50:07 +00:00
|
|
|
import Assistant.WebApp.OtherRepos
|
2013-10-22 20:02:52 +00:00
|
|
|
import Assistant.WebApp.Repair
|
2012-10-29 23:07:10 +00:00
|
|
|
import Assistant.Types.ThreadedMonad
|
2012-07-26 01:26:13 +00:00
|
|
|
import Utility.WebApp
|
2013-05-12 23:19:28 +00:00
|
|
|
import Utility.Tmp
|
2013-01-03 22:50:30 +00:00
|
|
|
import Utility.FileMode
|
2012-07-26 06:45:01 +00:00
|
|
|
import Git
|
2012-07-26 01:26:13 +00:00
|
|
|
|
|
|
|
import Yesod
|
2013-04-08 19:04:35 +00:00
|
|
|
import Network.Socket (SockAddr, HostName)
|
2012-07-31 05:11:32 +00:00
|
|
|
import Data.Text (pack, unpack)
|
2012-07-26 08:50:09 +00:00
|
|
|
|
2012-07-31 05:11:32 +00:00
|
|
|
mkYesodDispatch "WebApp" $(parseRoutesFile "Assistant/WebApp/routes")
|
2012-07-26 01:26:13 +00:00
|
|
|
|
2012-08-01 20:10:26 +00:00
|
|
|
type Url = String
|
|
|
|
|
2012-10-29 04:15:43 +00:00
|
|
|
webAppThread
|
|
|
|
:: AssistantData
|
2012-09-08 23:57:15 +00:00
|
|
|
-> UrlRenderer
|
2012-10-29 04:15:43 +00:00
|
|
|
-> Bool
|
2013-11-17 18:58:35 +00:00
|
|
|
-> Maybe String
|
2013-04-08 19:04:35 +00:00
|
|
|
-> Maybe HostName
|
2013-06-11 03:16:18 +00:00
|
|
|
-> Maybe (IO Url)
|
2012-08-01 20:10:26 +00:00
|
|
|
-> Maybe (Url -> FilePath -> IO ())
|
2012-09-06 18:56:04 +00:00
|
|
|
-> NamedThread
|
2013-11-17 18:58:35 +00:00
|
|
|
webAppThread assistantdata urlrenderer noannex cannotrun listenhost postfirstrun onstartup = thread $ liftIO $ do
|
2013-05-02 20:47:42 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
when (isJust listenhost) $
|
|
|
|
-- See Utility.WebApp
|
|
|
|
error "Sorry, --listen is not currently supported on Android"
|
|
|
|
#endif
|
2012-07-31 16:17:31 +00:00
|
|
|
webapp <- WebApp
|
2012-10-29 04:15:43 +00:00
|
|
|
<$> pure assistantdata
|
2012-07-31 16:17:31 +00:00
|
|
|
<*> (pack <$> genRandomToken)
|
2012-10-29 04:15:43 +00:00
|
|
|
<*> getreldir
|
2013-04-17 05:37:08 +00:00
|
|
|
<*> pure staticRoutes
|
2012-08-01 20:10:26 +00:00
|
|
|
<*> pure postfirstrun
|
2013-11-17 18:58:35 +00:00
|
|
|
<*> pure cannotrun
|
2012-10-29 04:15:43 +00:00
|
|
|
<*> pure noannex
|
2013-04-08 19:04:35 +00:00
|
|
|
<*> pure listenhost
|
2012-09-08 23:57:15 +00:00
|
|
|
setUrlRenderer urlrenderer $ yesodRender webapp (pack "")
|
2012-07-27 03:55:51 +00:00
|
|
|
app <- toWaiAppPlain webapp
|
2012-07-26 01:26:13 +00:00
|
|
|
app' <- ifM debugEnabled
|
|
|
|
( return $ httpDebugLogger app
|
|
|
|
, return app
|
|
|
|
)
|
2013-04-08 19:04:35 +00:00
|
|
|
runWebApp listenhost app' $ \addr -> if noannex
|
2013-12-07 15:45:01 +00:00
|
|
|
then withTmpFile "webapp.html" $ \tmpfile h -> do
|
|
|
|
hClose h
|
2013-01-10 03:17:52 +00:00
|
|
|
go addr webapp tmpfile Nothing
|
2012-10-29 04:15:43 +00:00
|
|
|
else do
|
|
|
|
let st = threadState assistantdata
|
2012-09-18 21:50:07 +00:00
|
|
|
htmlshim <- runThreadState st $ fromRepo gitAnnexHtmlShim
|
|
|
|
urlfile <- runThreadState st $ fromRepo gitAnnexUrlFile
|
2013-01-10 03:17:52 +00:00
|
|
|
go addr webapp htmlshim (Just urlfile)
|
2012-10-29 18:30:10 +00:00
|
|
|
where
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
-- The webapp thread does not wait for the startupSanityCheckThread
|
|
|
|
-- to finish, so that the user interface remains responsive while
|
|
|
|
-- that's going on.
|
|
|
|
thread = namedThreadUnchecked "WebApp"
|
2012-10-29 18:30:10 +00:00
|
|
|
getreldir
|
|
|
|
| noannex = return Nothing
|
|
|
|
| otherwise = Just <$>
|
|
|
|
(relHome =<< absPath
|
|
|
|
=<< runThreadState (threadState assistantdata) (fromRepo repoPath))
|
2013-01-10 03:17:52 +00:00
|
|
|
go addr webapp htmlshim urlfile = do
|
|
|
|
let url = myUrl webapp addr
|
2013-01-03 22:50:30 +00:00
|
|
|
maybe noop (`writeFileProtected` url) urlfile
|
|
|
|
writeHtmlShim "Starting webapp..." url htmlshim
|
2012-10-29 18:30:10 +00:00
|
|
|
maybe noop (\a -> a url htmlshim) onstartup
|
2012-07-26 03:13:01 +00:00
|
|
|
|
2013-01-10 03:17:52 +00:00
|
|
|
myUrl :: WebApp -> SockAddr -> Url
|
2013-03-13 02:18:36 +00:00
|
|
|
myUrl webapp addr = unpack $ yesodRender webapp urlbase DashboardR []
|
2012-10-29 18:30:10 +00:00
|
|
|
where
|
2013-01-10 03:17:52 +00:00
|
|
|
urlbase = pack $ "http://" ++ show addr
|