on master help sign in
Log the PID of the process using the port
commitb90f7c8455011a141e3f21e981e128781c356556 authorTom Smalley <tfsmalley@gmail.com> dateWed 16 May 2018, 18:47 (8 years ago) parentcbc03e4
2 files changed+10−12
lib/command/src/Obelisk/Command/Run.hs+1−1 lib/run/src/Obelisk/Run.hs+9−11
lib/command/src/Obelisk/Command/Run.hs+1−1
@@ -59,7 +59,7 @@ run = do
5959getLocalPkgs :: IO [FilePath]
6060getLocalPkgs = return ["backend", "common", "frontend"]
6161
62−parseHsSrcDir
62+parseHsSrcDir
6363 :: MonadObelisk m
6464 => FilePath -- ^ package cabal file path
6565 -> m (Maybe (NE.NonEmpty FilePath)) -- ^ List of hs src dirs of the library component
lib/run/src/Obelisk/Run.hs+9−11
@@ -60,9 +60,8 @@ runWidget conf w = do
6060 beforeMainLoop = do
6161 putStrLn $ "Frontend running on " <> T.unpack (URI.render uri)
6262 settings = setBeforeMainLoop beforeMainLoop (setPort port (setTimeout 3600 defaultSettings))
63− logErr p = putStrLn $ unwords [ "Port", show p, "is in use."]
6463 bracket
65− (bindPortTCPRetry settings (logErr port) (_runConfig_retryTimeout conf))
64+ (bindPortTCPRetry settings (logPortBindErr port) (_runConfig_retryTimeout conf))
6665 close
6766 (\skt -> do
6867 man <- newManager defaultManagerSettings
@@ -71,19 +70,18 @@ runWidget conf w = do
7170
7271-- | like 'bindPortTCP' but reconnects on exception
7372bindPortTCPRetry :: Settings
74− -> IO () -- ^ Action to run the first time an exception is caught
73+ -> (IOError -> IO ()) -- ^ Action to run the first time an exception is caught
7574 -> Int
7675 -> IO Socket
77−bindPortTCPRetry settings m n = catch (bindPortTCP (settingsPort settings) (settingsHost settings)) $ \(_ :: IOError) -> do
78− m
76+bindPortTCPRetry settings m n = catch (bindPortTCP (settingsPort settings) (settingsHost settings)) $ \(e :: IOError) -> do
77+ m e
7978 threadDelay $ 1000000 * n
80− bindPortTCPRetry settings (return ()) n
79+ bindPortTCPRetry settings (\_ -> pure ()) n
8180
82−-- TODO
83−logPortBindErr :: Int -> IO ()
84−logPortBindErr p = getProcessIdForPort p >>= \case
85− Nothing -> return ()
86− Just _ -> return ()
81+logPortBindErr :: Int -> IOError -> IO ()
82+logPortBindErr p e = getProcessIdForPort p >>= \case
83+ Nothing -> putStrLn $ "runWidget: " <> show e
84+ Just pid -> putStrLn $ unwords [ "Port", show p, "is being used by process ID", show pid <> ".", "Please kill that process or change the port in config/common/route."]
8785
8886getProcessIdForPort :: Int -> IO (Maybe Int)
8987getProcessIdForPort port = do