From a3206d45d6fe161091d008d39ec86a2263d95446 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 4 Apr 2014 02:06:19 -0400 Subject: redo a change I lost somewhere fixes ghc spain in i386 container on amd64 host --- Propellor/CmdLine.hs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Propellor/CmdLine.hs') diff --git a/Propellor/CmdLine.hs b/Propellor/CmdLine.hs index a9c61993..d10211f0 100644 --- a/Propellor/CmdLine.hs +++ b/Propellor/CmdLine.hs @@ -11,6 +11,7 @@ import System.PosixCompat import Propellor import qualified Propellor.Property.Docker as Docker +import qualified Propellor.Property.Docker.Shim as DockerShim import Utility.FileMode import Utility.SafeCommand @@ -53,6 +54,7 @@ processCmdLine = go =<< getArgs defaultMain :: [HostName -> Maybe [Property]] -> IO () defaultMain getprops = do + DockerShim.cleanEnv checkDebugMode cmdline <- processCmdLine debug ["command line: ", show cmdline] -- cgit v1.2.3 From da3976b9e2f9abf0f2d37300b70bc8884e4ab2f8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 4 Apr 2014 16:20:20 -0400 Subject: propellor spin --- Propellor/CmdLine.hs | 16 +++++++++++++++- debian/changelog | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'Propellor/CmdLine.hs') diff --git a/Propellor/CmdLine.hs b/Propellor/CmdLine.hs index d10211f0..3974f1d5 100644 --- a/Propellor/CmdLine.hs +++ b/Propellor/CmdLine.hs @@ -8,6 +8,8 @@ import System.Log.Formatter import System.Log.Handler (setFormatter, LogHandler) import System.Log.Handler.Simple import System.PosixCompat +import Control.Exception (bracket) +import System.Posix.IO import Propellor import qualified Propellor.Property.Docker as Docker @@ -71,7 +73,7 @@ defaultMain getprops = do go True cmdline = updateFirst cmdline $ go False cmdline go False (Spin host) = withprops host $ const $ spin host go False (Run host) = ifM ((==) 0 <$> getRealUserID) - ( withprops host ensureProperties + ( onlyProcess $ withprops host ensureProperties , go True (Spin host) ) go False (Boot host) = withprops host $ boot @@ -79,6 +81,18 @@ defaultMain getprops = do withprops host a = maybe (unknownhost host) a $ headMaybe $ catMaybes $ map (\get -> get host) getprops +onlyProcess :: IO a -> IO a +onlyProcess a = bracket lock unlock (const a) + where + lock = do + l <- openFd lockfile ReadWrite Nothing defaultFileFlags + setLock l (WriteLock, AbsoluteSeek, 0, 0) + `catchIO` (const alreadyrunning) + return l + unlock = closeFd + alreadyrunning = error "Propellor is already running on this host!" + lockfile = localdir ".lock" + unknownhost :: HostName -> IO a unknownhost h = errorMessage $ unlines [ "Unknown host: " ++ h diff --git a/debian/changelog b/debian/changelog index 0fdd42b2..a02c27d7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,7 @@ propellor (0.2.3) UNRELEASED; urgency=medium * docker: Fix laziness bug that caused running containers to be unnecessarily stopped and committed. + * Add locking so only one propellor can run at a time on a host. -- Joey Hess Fri, 04 Apr 2014 15:58:03 -0400 -- cgit v1.2.3 From 160b598756ad08c0d4e8d7da038a63d988e0ab7a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 4 Apr 2014 16:23:20 -0400 Subject: add a lock --- Propellor/CmdLine.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Propellor/CmdLine.hs') diff --git a/Propellor/CmdLine.hs b/Propellor/CmdLine.hs index 3974f1d5..560e774d 100644 --- a/Propellor/CmdLine.hs +++ b/Propellor/CmdLine.hs @@ -76,7 +76,7 @@ defaultMain getprops = do ( onlyProcess $ withprops host ensureProperties , go True (Spin host) ) - go False (Boot host) = withprops host $ boot + go False (Boot host) = onlyProcess $ withprops host $ boot withprops host a = maybe (unknownhost host) a $ headMaybe $ catMaybes $ map (\get -> get host) getprops -- cgit v1.2.3 From 0636846848ce3a68c2f66cd798bf37d9afcf0877 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 4 Apr 2014 18:34:03 -0400 Subject: propellor spin --- Propellor/CmdLine.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Propellor/CmdLine.hs') diff --git a/Propellor/CmdLine.hs b/Propellor/CmdLine.hs index 560e774d..5ea982c3 100644 --- a/Propellor/CmdLine.hs +++ b/Propellor/CmdLine.hs @@ -85,9 +85,9 @@ onlyProcess :: IO a -> IO a onlyProcess a = bracket lock unlock (const a) where lock = do - l <- openFd lockfile ReadWrite Nothing defaultFileFlags + l <- createFile lockfile stdFileMode setLock l (WriteLock, AbsoluteSeek, 0, 0) - `catchIO` (const alreadyrunning) + `catchIO` const alreadyrunning return l unlock = closeFd alreadyrunning = error "Propellor is already running on this host!" -- cgit v1.2.3