Skip to content

Commit

Permalink
handle SIGTERM on linux & fix dockerfile (#47)
Browse files Browse the repository at this point in the history
* handle SIGTERM signal on linux

* fix dockerfile entrypoint
  • Loading branch information
jonschoning committed Jan 5, 2023
1 parent 373e91b commit 6654213
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
FROM jonschoning/espial:scratch
WORKDIR /app
COPY . .
CMD ./espial +RTS -T
CMD ["./espial", "+RTS", "-T"]
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
__v0.0.16__
Add SIGTERM handler on linux
Adjust docker CMD entrypoint

__v0.0.15__
Avoid using external static/tmp folder for generated static files

Expand Down
16 changes: 14 additions & 2 deletions espial.cabal
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.35.0.
-- This file has been generated from package.yaml by hpack version 0.35.1.
--
-- see: https://github.com/sol/hpack

name: espial
version: 0.0.15
version: 0.0.16
synopsis: Espial is an open-source, web-based bookmarking server.
description: .
Espial is an open-source, web-based bookmarking server.
Expand Down Expand Up @@ -218,6 +218,9 @@ library
, yesod-newsfeed >=1.6 && <1.8
, yesod-static >=1.6 && <1.8
default-language: Haskell2010
if !os(windows)
build-depends:
unix
if (flag(dev)) || (flag(library-only))
ghc-options: -Wall -fwarn-tabs -O0
cpp-options: -DDEVELOPMENT
Expand Down Expand Up @@ -331,6 +334,9 @@ executable espial
, yesod-newsfeed >=1.6 && <1.8
, yesod-static >=1.6 && <1.8
default-language: Haskell2010
if !os(windows)
build-depends:
unix
if flag(library-only)
buildable: False

Expand Down Expand Up @@ -442,6 +448,9 @@ executable migration
, yesod-newsfeed >=1.6 && <1.8
, yesod-static >=1.6 && <1.8
default-language: Haskell2010
if !os(windows)
build-depends:
unix
if flag(library-only)
buildable: False

Expand Down Expand Up @@ -557,3 +566,6 @@ test-suite test
, yesod-static >=1.6 && <1.8
, yesod-test
default-language: Haskell2010
if !os(windows)
build-depends:
unix
9 changes: 8 additions & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: espial
synopsis: Espial is an open-source, web-based bookmarking server.
version: "0.0.15"
version: "0.0.16"
description: ! '
Espial is an open-source, web-based bookmarking server.
Expand Down Expand Up @@ -144,6 +144,13 @@ dependencies:
- base64
- cryptohash-sha256

when:
- condition: "!os(windows)"
dependencies:
- unix



# The library contains all of our application code. The executable
# defined below is just a thin wrapper.
library:
Expand Down
10 changes: 9 additions & 1 deletion src/Application.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import Network.Wai.Middleware.Gzip
import Network.Wai.Middleware.MethodOverride
import Network.Wai.Middleware.RequestLogger (Destination(Logger), IPAddrSource(..), OutputFormat(..), destination, mkRequestLogger, outputFormat)
import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet, toLogStr)
#ifndef mingw32_HOST_OS
import qualified Control.Concurrent as CC (killThread, myThreadId)
import qualified System.Posix.Signals as PS (installHandler, Handler(CatchOnce), sigTERM)
#endif

-- Import all relevant handler modules here.
-- Don't forget to add new modules to your cabal file!
Expand Down Expand Up @@ -136,8 +140,12 @@ appMain = do
settings <- loadYamlSettingsArgs [configSettingsYmlValue] useEnv
foundation <- makeFoundation settings
app <- makeApplication foundation
#ifndef mingw32_HOST_OS
mainThreadId <- CC.myThreadId
void $ PS.installHandler PS.sigTERM (PS.CatchOnce (CC.killThread mainThreadId)) Nothing
#endif
runSettings (warpSettings foundation) app

getApplicationRepl :: IO (Int, App, Application)
getApplicationRepl = do
settings <- getAppSettings
Expand Down

0 comments on commit 6654213

Please sign in to comment.