blob: 1635ac0442ced71c04de93376ecc5055b30c8620 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
{- git-annex webapp launcher
-
- Copyright 2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.WebApp where
import Common.Annex
import Command
import Assistant
import Utility.WebApp
import Utility.Daemon (checkDaemon)
import Option
def :: [Command]
def = [withOptions [restartOption] $
command "webapp" paramNothing seek "launch webapp"]
restartOption :: Option
restartOption = Option.flag [] "restart" "restart the assistant daemon"
seek :: [CommandSeek]
seek = [withFlag restartOption $ \restart -> withNothing $ start restart]
start :: Bool -> CommandStart
start restart = notBareRepo $ do
f <- liftIO . absPath =<< fromRepo gitAnnexHtmlShim
if restart
then do
stopDaemon
void $ liftIO . nukeFile =<< fromRepo gitAnnexPidFile
startassistant f
else ifM (checkpid <&&> checkshim f) $
( liftIO $ go f
, startassistant f
)
stop
where
checkpid = do
pidfile <- fromRepo gitAnnexPidFile
liftIO $ isJust <$> checkDaemon pidfile
checkshim f = liftIO $ doesFileExist f
startassistant = startDaemon True False . Just . go
go f = unlessM (runBrowser url) $
error $ "failed to start web browser on url " ++ url
where
url = "file://" ++ f
|