summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-10-26 12:42:58 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-10-26 12:42:58 -0400
commit956694b88fff7bc151bad6196ed429e0db7b23cb (patch)
tree07237216bb2c9854d19a3664413b1311f472ad27 /Command
parentfdec6d27c4d32b9d641d17336b6be4a91c1d3fc4 (diff)
assistant: When autostarted, wait 5 seconds before running the startup scan, to avoid contending with the user's desktop login process.
Diffstat (limited to 'Command')
-rw-r--r--Command/Assistant.hs41
-rw-r--r--Command/Watch.hs9
-rw-r--r--Command/WebApp.hs4
3 files changed, 36 insertions, 18 deletions
diff --git a/Command/Assistant.hs b/Command/Assistant.hs
index f65bed736..521a88571 100644
--- a/Command/Assistant.hs
+++ b/Command/Assistant.hs
@@ -14,43 +14,55 @@ import qualified Command.Watch
import Init
import Config.Files
import qualified Build.SysConfig
+import Utility.HumanTime
import System.Environment
def :: [Command]
-def = [noRepo checkAutoStart $ dontCheck repoExists $
- withOptions [Command.Watch.foregroundOption, Command.Watch.stopOption, autoStartOption] $
+def = [noRepo checkAutoStart $ dontCheck repoExists $ withOptions options $
command "assistant" paramNothing seek SectionCommon
"automatically handle changes"]
+options :: [Option]
+options =
+ [ Command.Watch.foregroundOption
+ , Command.Watch.stopOption
+ , autoStartOption
+ , startDelayOption
+ ]
+
autoStartOption :: Option
autoStartOption = Option.flag [] "autostart" "start in known repositories"
+startDelayOption :: Option
+startDelayOption = Option.field [] "startdelay" paramNumber "delay before running startup scan"
+
seek :: [CommandSeek]
seek = [withFlag Command.Watch.stopOption $ \stopdaemon ->
withFlag Command.Watch.foregroundOption $ \foreground ->
withFlag autoStartOption $ \autostart ->
- withNothing $ start foreground stopdaemon autostart]
+ withField startDelayOption (pure . maybe Nothing parseDuration) $ \startdelay ->
+ withNothing $ start foreground stopdaemon autostart startdelay]
-start :: Bool -> Bool -> Bool -> CommandStart
-start foreground stopdaemon autostart
+start :: Bool -> Bool -> Bool -> Maybe Duration -> CommandStart
+start foreground stopdaemon autostart startdelay
| autostart = do
- liftIO autoStart
+ liftIO $ autoStart startdelay
stop
| otherwise = do
ensureInitialized
- Command.Watch.start True foreground stopdaemon
+ Command.Watch.start True foreground stopdaemon startdelay
{- Run outside a git repository. Check to see if any parameter is
- --autostart and enter autostart mode. -}
checkAutoStart :: IO ()
checkAutoStart = ifM (elem "--autostart" <$> getArgs)
- ( autoStart
+ ( autoStart Nothing
, error "Not in a git repository."
)
-autoStart :: IO ()
-autoStart = do
+autoStart :: Maybe Duration -> IO ()
+autoStart startdelay = do
dirs <- liftIO readAutoStartFile
when (null dirs) $ do
f <- autoStartFile
@@ -67,5 +79,10 @@ autoStart = do
go haveionice program dir = do
setCurrentDirectory dir
if haveionice
- then boolSystem "ionice" [Param "-c3", Param program, Param "assistant"]
- else boolSystem program [Param "assistant"]
+ then boolSystem "ionice" (Param "-c3" : Param program : baseparams)
+ else boolSystem program baseparams
+ where
+ baseparams =
+ [ Param "assistant"
+ , Param $ "--startdelay=" ++ fromDuration (fromMaybe (Duration 5) startdelay)
+ ]
diff --git a/Command/Watch.hs b/Command/Watch.hs
index c5fd1a8cd..0b34b0f84 100644
--- a/Command/Watch.hs
+++ b/Command/Watch.hs
@@ -11,6 +11,7 @@ import Common.Annex
import Assistant
import Command
import Option
+import Utility.HumanTime
def :: [Command]
def = [notBareRepo $ withOptions [foregroundOption, stopOption] $
@@ -19,7 +20,7 @@ def = [notBareRepo $ withOptions [foregroundOption, stopOption] $
seek :: [CommandSeek]
seek = [withFlag stopOption $ \stopdaemon ->
withFlag foregroundOption $ \foreground ->
- withNothing $ start False foreground stopdaemon]
+ withNothing $ start False foreground stopdaemon Nothing]
foregroundOption :: Option
foregroundOption = Option.flag [] "foreground" "do not daemonize"
@@ -27,9 +28,9 @@ foregroundOption = Option.flag [] "foreground" "do not daemonize"
stopOption :: Option
stopOption = Option.flag [] "stop" "stop daemon"
-start :: Bool -> Bool -> Bool -> CommandStart
-start assistant foreground stopdaemon = do
+start :: Bool -> Bool -> Bool -> Maybe Duration -> CommandStart
+start assistant foreground stopdaemon startdelay = do
if stopdaemon
then stopDaemon
- else startDaemon assistant foreground Nothing Nothing -- does not return
+ else startDaemon assistant foreground startdelay Nothing Nothing -- does not return
stop
diff --git a/Command/WebApp.hs b/Command/WebApp.hs
index 6577ce02b..88c1537d0 100644
--- a/Command/WebApp.hs
+++ b/Command/WebApp.hs
@@ -69,7 +69,7 @@ start' allowauto listenhost = do
url <- liftIO . readFile
=<< fromRepo gitAnnexUrlFile
liftIO $ openBrowser browser f url Nothing Nothing
- , startDaemon True True listenhost $ Just $
+ , startDaemon True True Nothing listenhost $ Just $
\origout origerr url htmlshim ->
if isJust listenhost
then maybe noop (`hPutStrLn` url) origout
@@ -155,7 +155,7 @@ firstRun listenhost = do
_wait <- takeMVar v
state <- Annex.new =<< Git.CurrentRepo.get
Annex.eval state $
- startDaemon True True listenhost $ Just $
+ startDaemon True True Nothing listenhost $ Just $
sendurlback v
sendurlback v _origout _origerr url _htmlshim = do
recordUrl url