summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Hess2016-03-28 05:52:46 -0400
committerJoey Hess2016-03-28 05:52:46 -0400
commitb1d1a85038a0a7193c8db8b8e27ac404309741dd (patch)
tree66b6890d852c19daec2306920fecf9108e055273 /src
parent1bd062c5336db6aff3b6128f7821f8ebed6b6ca0 (diff)
parentebf30061d8f8a251330070e69c2710fe4a8fd9da (diff)
Merge branch 'master' into typed-os-requirements
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/Property/Uwsgi.hs6
-rw-r--r--src/Propellor/Ssh.hs41
2 files changed, 41 insertions, 6 deletions
diff --git a/src/Propellor/Property/Uwsgi.hs b/src/Propellor/Property/Uwsgi.hs
index 491c77d1..4eb94103 100644
--- a/src/Propellor/Property/Uwsgi.hs
+++ b/src/Propellor/Property/Uwsgi.hs
@@ -31,13 +31,13 @@ appAvailable an cf = ("uwsgi app available " ++ an) ==>
comment = "# deployed with propellor, do not modify"
appCfg :: AppName -> FilePath
-appCfg an = "/etc/uwsgi/apps-available/" ++ an
+appCfg an = "/etc/uwsgi/apps-available" </> an <.> "ini"
appVal :: AppName -> FilePath
-appVal an = "/etc/uwsgi/apps-enabled/" ++ an
+appVal an = "/etc/uwsgi/apps-enabled/" </> an <.> "ini"
appValRelativeCfg :: AppName -> File.LinkTarget
-appValRelativeCfg an = File.LinkTarget $ "../apps-available/" ++ an
+appValRelativeCfg an = File.LinkTarget $ "../apps-available" </> an <.> "ini"
installed :: Property DebianLike
installed = Apt.installed ["uwsgi"]
diff --git a/src/Propellor/Ssh.hs b/src/Propellor/Ssh.hs
index b00eb651..3e4806ea 100644
--- a/src/Propellor/Ssh.hs
+++ b/src/Propellor/Ssh.hs
@@ -2,9 +2,11 @@ module Propellor.Ssh where
import Propellor.Base
import Utility.UserInfo
+import Utility.FileSystemEncoding
import System.PosixCompat
import Data.Time.Clock.POSIX
+import qualified Data.Hash.MD5 as MD5
-- Parameters can be passed to both ssh and scp, to enable a ssh connection
-- caching socket.
@@ -16,9 +18,8 @@ import Data.Time.Clock.POSIX
sshCachingParams :: HostName -> IO [CommandParam]
sshCachingParams hn = do
home <- myHomeDir
- let cachedir = home </> ".ssh" </> "propellor"
- createDirectoryIfMissing False cachedir
- let socketfile = cachedir </> hn ++ ".sock"
+ let socketfile = socketFile home hn
+ createDirectoryIfMissing False (takeDirectory socketfile)
let ps =
[ Param "-o"
, Param ("ControlPath=" ++ socketfile)
@@ -42,3 +43,37 @@ sshCachingParams hn = do
[ Param "localhost" ]
nukeFile f
tenminutes = 600
+
+-- Generate a socket filename inside the home directory.
+--
+-- There's a limit in the size of unix domain sockets, of approximately
+-- 100 bytes. Try to never construct a filename longer than that.
+--
+-- When space allows, include the full hostname in the socket filename.
+-- Otherwise, include at least a partial md5sum of it,
+-- to avoid using the same socket file for multiple hosts.
+socketFile :: FilePath -> HostName -> FilePath
+socketFile home hn = selectSocketFile
+ [ sshdir </> hn ++ ".sock"
+ , sshdir </> hn
+ , sshdir </> take 10 hn ++ "-" ++ md5
+ , sshdir </> md5
+ , home </> ".propellor-" ++ md5
+ ]
+ (".propellor-" ++ md5)
+ where
+ sshdir = home </> ".ssh" </> "propellor"
+ md5 = take 9 $ MD5.md5s $ MD5.Str hn
+
+selectSocketFile :: [FilePath] -> FilePath -> FilePath
+selectSocketFile [] fallback = fallback
+selectSocketFile [f] _ = f
+selectSocketFile (f:fs) fallback
+ | valid_unix_socket_path f = f
+ | otherwise = selectSocketFile fs fallback
+
+valid_unix_socket_path :: FilePath -> Bool
+valid_unix_socket_path f = length (decodeW8 f) < 100 - reservedbyssh
+ where
+ -- ssh tacks on 17 or so characters when making a socket
+ reservedbyssh = 18