packages feed

wai-cli 0.2.1 → 0.2.3

raw patch · 3 files changed

+40/−23 lines, 3 filesdep +transformersdep −socket-activationdep ~basedep ~network

Dependencies added: transformers

Dependencies removed: socket-activation

Dependency ranges changed: base, network

Files

README.md view
@@ -1,4 +1,4 @@-# wai-cli [![Hackage](https://img.shields.io/hackage/v/wai-cli.svg?style=flat)](https://hackage.haskell.org/package/wai-cli) [![Build Status](https://img.shields.io/travis/myfreeweb/wai-cli.svg?style=flat)](https://travis-ci.org/myfreeweb/wai-cli) [![unlicense](https://img.shields.io/badge/un-license-green.svg?style=flat)](http://unlicense.org)+# wai-cli [![Hackage](https://img.shields.io/hackage/v/wai-cli.svg?style=flat)](https://hackage.haskell.org/package/wai-cli) [![Build Status](https://github.com/unrelentingtech/wai-cli/workflows/WaiCLI%20CI/badge.svg)](https://github.com/unrelentingtech/wai-cli/actions?query=workflow%3A%22WaiCLI+CI%22) [![unlicense](https://img.shields.io/badge/un-license-green.svg?style=flat)](http://unlicense.org)  A command line runner for Wai apps (using Warp) with support for: @@ -6,15 +6,15 @@ - `--protocol unix --socket /var/run/app/sock` UNIX domain sockets - `--protocol cgi` running as a CGI app (the original serverless lambda functions from the 90s) - `--protocol fastcgi` running as a FastCGI app (OPTIONAL! You need to build with the `fastcgi` cabal flag and you need to have `libfcgi` (e.g. `fcgi-devkit` package on FreeBSD) installed)-- `--protocol activate` socket activation (systemd-compatible, but not restricted to systemd in any way. see [soad](https://github.com/myfreeweb/soad) for an interesting use of (de)activation!)+- `--protocol activate` socket activation (systemd-compatible, but not restricted to systemd in any way. see [soad](https://github.com/unrelentingtech/soad) for an interesting use of (de)activation!) - `--protocol (http+tls|unix+tls|activate+tls) --tlskey key.pem --tlscert cert.pem` TLS (can be turned off with a cabal flag to avoid compiling [the TLS library](https://github.com/vincenthz/hs-tls)) - `--graceful (none|serve-normally|serve-503)` graceful shutdown (on TERM signal) - `--devlogging` development logging (from `wai-extra`) - printing a pretty and colorful run message (e.g. `Running on http port 3000 with 4 CPUs`) (you can replace it with your own, or with nothing) -Extracted from [sweetroll](https://github.com/myfreeweb/sweetroll) and [microformats2-parser](https://github.com/myfreeweb/microformats2-parser)'s demo web app.+Extracted from [sweetroll](https://github.com/unrelentingtech/sweetroll) and [microformats2-parser](https://github.com/unrelentingtech/microformats2-parser)'s demo web app. -Now used in the [magicbane](https://github.com/myfreeweb/magicbane) framework (which was also extracted from sweetroll).+Now used in the [magicbane](https://github.com/unrelentingtech/magicbane) framework (which was also extracted from sweetroll).  ## Usage 
library/Network/Wai/Cli.hs view
@@ -14,11 +14,15 @@ #ifdef WaiCliUnix import           Network.Wai (responseLBS, Application) import           Network.HTTP.Types (serviceUnavailable503)-import           Network.Socket.Activation+import           System.Posix.Env+import           System.Posix.Process+import           Foreign.C.Types(CInt(..)) import           System.Posix.Internals (setNonBlockingFD) import           System.Posix.Signals (installHandler, sigTERM, Handler(CatchOnce)) import           Data.Streaming.Network (bindPath, bindPortTCP) import           Control.Monad+import           Control.Monad.Trans.Maybe+import           Control.Monad.Trans.Class import           Control.Monad.Trans (liftIO) import           Control.Concurrent.STM import           GHC.Conc (getNumCapabilities, forkIO)@@ -88,13 +92,26 @@   #ifdef WaiCliUnix++fdStart ∷ CInt+fdStart = 3++getActivatedSockets ∷ IO (Maybe [S.Socket])+getActivatedSockets = runMaybeT $ do+    listenPid ← read <$> MaybeT (getEnv "LISTEN_PID")+    listenFDs ← read <$> MaybeT (getEnv "LISTEN_FDS")+    myPid     ← lift getProcessID+    guard $ listenPid == myPid+    mapM (lift . S.mkSocket) [fdStart .. fdStart + listenFDs - 1]+ runActivated ∷ (Settings → S.Socket → Application → IO ()) → Settings → Application → IO () runActivated run warps app = do   sockets ← getActivatedSockets   case sockets of     Just socks →       void $ forM socks $ \sock → do-        setNonBlockingFD (S.fdSocket sock) True+        S.withFdSocket sock $ \sfd →+          setNonBlockingFD sfd True         forkIO $ run warps sock app     Nothing → putStrLn "No sockets to activate" @@ -123,20 +140,20 @@ -- | Adjusts 'WaiOptions' with an address assigned to a newly created -- server socket, uses those to set a "before main loop" function in -- Warp 'Settings', which are then used to run an application.-runWarp :: (WaiOptions -> IO ())+runWarp ∷ (WaiOptions → IO ())         -- ^ A "before main loop" function-        -> WaiOptions+        → WaiOptions         -- ^ Original options-        -> (Settings -> S.Socket -> Application -> IO ())+        → (Settings → S.Socket → Application → IO ())         -- ^ A function such as 'runSettingsSocket'-        -> Settings -> Application -> IO ()+        → Settings → Application → IO () runWarp putListening opts runSocket set app = S.withSocketsDo $-  bracket (bindPortTCP (getPort set) (getHost set)) S.close $ \s -> do-  sa <- S.getSocketName s-  S.setCloseOnExecIfNeeded $ S.fdSocket s+  bracket (bindPortTCP (getPort set) (getHost set)) S.close $ \s → do+  sa ← S.getSocketName s+  S.withFdSocket s S.setCloseOnExecIfNeeded   runSocket (setBeforeMainLoop (putListening $ updateOptions sa opts) set) s app   where-    updateOptions :: S.SockAddr -> WaiOptions -> WaiOptions+    updateOptions ∷ S.SockAddr → WaiOptions → WaiOptions     updateOptions (S.SockAddrInet pn ha) opt =       opt { wHttpPort = fromIntegral pn, wHttpHost = show (fromHostAddress ha) }     updateOptions (S.SockAddrInet6 pn _flow ha _scope) opt =
wai-cli.cabal view
@@ -1,15 +1,15 @@ name:            wai-cli-version:         0.2.1+version:         0.2.3 synopsis:        Command line runner for Wai apps (using Warp) with TLS, CGI, socket activation & graceful shutdown description:     Command line runner for Wai apps (using Warp) with support for UNIX domain sockets,     TLS (can be turned off with a cabal flag to avoid compiling the TLS library), CGI,-    socket activation (systemd-compatible, but see https://github.com/myfreeweb/soad for a more interesting (and not linux-only) thing than what systemd does),+    socket activation (systemd-compatible, but see https://github.com/unrelentingtech/soad for a more interesting (and not linux-only) thing than what systemd does),     and graceful shutdown (on TERM signal). category:        Web-homepage:        https://github.com/myfreeweb/wai-cli+homepage:        https://github.com/unrelentingtech/wai-cli author:          Greg V-copyright:       2017-2019 Greg V <greg@unrelenting.technology>+copyright:       2017-2021 Greg V <greg@unrelenting.technology> maintainer:      greg@unrelenting.technology license:         PublicDomain license-file:    UNLICENSE@@ -18,11 +18,11 @@ extra-source-files:     README.md tested-with:-    GHC == 8.6.3+    GHC == 8.8.4  source-repository head     type: git-    location: git://github.com/myfreeweb/wai-cli.git+    location: git://github.com/unrelentingtech/wai-cli.git  flag tls     description: Include warp-tls@@ -38,14 +38,14 @@  library     build-depends:-        base >= 4.8.0.0 && < 5+        base >= 4.8.0.0 && < 10       , options       , warp       , streaming-commons       , http-types       , monads-tf       , stm-      , network >= 2.7+      , network       , wai       , wai-extra       , ansi-terminal@@ -65,5 +65,5 @@         cpp-options: -DWaiCliUnix         build-depends:             unix-            , socket-activation+          , transformers