use --detach of git daemon

This commit is contained in:
Yann Esposito (Yogsototh) 2018-10-21 22:25:08 +02:00
parent f05b8bf6f8
commit 1e8bbcb006
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
4 changed files with 14 additions and 13 deletions

View file

@ -2,7 +2,7 @@
-- --
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
-- --
-- hash: d9338d9561ff06dc6d13e3df5b3985256d508cfa09d153b26fa2eaf00dff864f -- hash: 04bfdb9ffa855881f6cd6cc09bf3b494a2107ded6cc33c41699546a12526099e
name: gpm name: gpm
version: 0.1.0.0 version: 0.1.0.0
@ -45,7 +45,6 @@ library
, protolude , protolude
, text , text
, turtle , turtle
, unix
default-language: Haskell2010 default-language: Haskell2010
executable gpm executable gpm
@ -67,5 +66,4 @@ executable gpm
, protolude , protolude
, text , text
, turtle , turtle
, unix
default-language: Haskell2010 default-language: Haskell2010

View file

@ -32,7 +32,6 @@ dependencies:
- protolude - protolude
- text - text
- turtle - turtle
- unix
library: library:
source-dirs: src source-dirs: src
executables: executables:

View file

@ -36,7 +36,7 @@ subtitle "Cleaning Up"
gpm serve stop gpm serve stop
subtitle "Create Project $testproj" subtitle "Create Project $testproj"
mkdir $testproj mkdir -p $testproj
pushd $testproj pushd $testproj
echo "README 1" > README echo "README 1" > README
git init . git init .
@ -78,6 +78,9 @@ pushd $testproj2
subtitle "git clone" subtitle "git clone"
git clone git://localhost:9418/${prjname}.git $testproj2 git clone git://localhost:9418/${prjname}.git $testproj2
subtitle "gpm init (into the cloned repo)"
gpm init
subtitle "gpm serve stop" subtitle "gpm serve stop"
gpm serve stop gpm serve stop
popd popd

View file

@ -14,7 +14,7 @@ module GPM.Serve
where where
-- | Generic Import -- | Generic Import
import Protolude hiding (die, stdout, (%), (<.>)) import Protolude hiding (die, (%), (<.>))
import Turtle import Turtle
-- | Local Imports -- | Local Imports
@ -23,7 +23,6 @@ import GPM.Helpers (debug, debug_, getGPMDataDir,
-- | External Lib Imports -- | External Lib Imports
import qualified Data.Text as Text import qualified Data.Text as Text
import qualified System.Posix.Process as Process
-- | Retrieve a public dir to serve git repositories -- | Retrieve a public dir to serve git repositories
getPublicDir :: IO Turtle.FilePath getPublicDir :: IO Turtle.FilePath
@ -121,18 +120,20 @@ handleProjectDir = getPublicDir >>= putText . format fp
dirServe :: Turtle.FilePath -> IO () dirServe :: Turtle.FilePath -> IO ()
dirServe pubdir = do dirServe pubdir = do
processId <- Process.forkProcess $
debug_ $ format ("git daemon --reuseaddr --export-all --base-path="%fp%" "%fp) pubdir pubdir
gpmDataDir <- getGPMDataDir gpmDataDir <- getGPMDataDir
inDir gpmDataDir $ do let pidfiledir = gpmDataDir </> "procs"
mktree "procs" debug_ $
writeTextFile ("procs" </> "gitServePID") (show processId) format ("git daemon --detach --pid-file="%fp
%" --reuseaddr --export-all --base-path="%fp%" "%fp)
(pidfiledir </> "gitServePID")
pubdir
pubdir
dirStopServe :: IO () dirStopServe :: IO ()
dirStopServe = do dirStopServe = do
gpmDataDir <- getGPMDataDir gpmDataDir <- getGPMDataDir
inDir gpmDataDir $ do inDir gpmDataDir $ do
pidtxt <- readTextFile ("procs" </> "gitServePID") pidtxt <- readTextFile (gpmDataDir </>"procs" </> "gitServePID")
if Text.null pidtxt if Text.null pidtxt
then putErrText "git daemon doesn't appear to be running" then putErrText "git daemon doesn't appear to be running"
else debug_ ("kill " <> pidtxt) else debug_ ("kill " <> pidtxt)