+-- | Create the directory in which we intend to store the PID
+-- file. This will *not* create any parent directories. The PID
+-- directory will have its owner/group changed to the user/group
+-- under which we'll be running. No permissions will be set; the
+-- system's umask must allow owner-write.
+--
+-- This is intended to create one level beneath either /var/run or
+-- /run which often do not survive a reboot.
+--
+-- If the directory already exists, it is left alone; that is, we
+-- don't change its owner/group.
+--
+create_pid_directory :: FilePath -- ^ The directory to contain the PID file.
+ -> UserID -- ^ Owner of the new directory if created.
+ -> GroupID -- ^ Group of the new directory if created.
+ -> IO ()
+create_pid_directory pid_directory uid gid = do
+ it_exists <- doesDirectoryExist pid_directory
+ unless it_exists $ do
+ report_info $ "Creating PID directory " ++ pid_directory ++ "."
+ createDirectory pid_directory
+ report_info $ "Changing owner/group of " ++ pid_directory ++
+ " to " ++ (show uid) ++ "/" ++ (show gid) ++ "."
+ setOwnerAndGroup pid_directory uid gid
+