Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/laserpants/monitor-warp
Introduces nominal support for process management via SIGHUP and SIGTERM to the Warp web server.
https://github.com/laserpants/monitor-warp
Last synced: about 1 month ago
JSON representation
Introduces nominal support for process management via SIGHUP and SIGTERM to the Warp web server.
- Host: GitHub
- URL: https://github.com/laserpants/monitor-warp
- Owner: laserpants
- License: other
- Created: 2014-09-12T14:14:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-09-21T00:05:48.000Z (over 7 years ago)
- Last Synced: 2024-10-13T00:47:54.715Z (2 months ago)
- Language: Haskell
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
monitor-warp
============Provides some nominal support for process management via SIGHUP and SIGTERM to the Warp web server.
### Credit where credit is due
This module is largely based on the following GitHub Gist by Nathan Howell:
https://gist.github.com/NathanHowell/5435345
The included `Main.hs` illustrates the basic use case:
```
{-# LANGUAGE OverloadedStrings #-}
module Main whereimport Control.Concurrent ( threadDelay )
import Monitor.Warp
import Data.ByteString.Lazy ( ByteString )
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Handler.Warpimport qualified Data.ByteString.Lazy.Char8 as BL
data AppData = AppData ByteString
app :: AppData -> Application
app (AppData a) req resp = do
threadDelay 2000000 -- Sleep for 2 secs.
resp $ responseLBS ok200 [] $ BL.concat [a, " says: YOLO!\n"]onStartup :: IO (ServerSettings AppData)
onStartup = do
putStrLn "Service starting."
return $ ServerSettings
{ handler = app
, config = setPort 3333 $ defaultSettings
, response = responseLBS serviceUnavailable503 [] "Server shutting down."
, options = AppData "demo"
}-- | Do nothing in particular.
onExit :: ServerSettings AppData -> Shutdown -> IO ()
onExit _ action = do
case action of
Restart -> putStrLn "Service closing down for restart.\n"
Exit -> putStrLn "Service terminating.\n"main :: IO ()
main = sigServ onStartup onExit```
Build and run the demo. You should then be able to manage the process using the normal unix shell commands. E.g., to restart the process:
```
$ kill -1
```