Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module lets you construct Properties by running commands and
scripts. To get from an UncheckedProperty
to a Property
, it's
up to the user to check if the command made a change to the system.
The best approach is to check
a property, so that the command is only
run when it needs to be. With this method, you avoid running the
cmdProperty
unnecessarily.
check (not <$> userExists "bob") (cmdProperty "useradd" ["bob"])
Sometimes it's just as expensive to check a property as it would be to
run the command that ensures the property. So you can let the command
run every time, and use changesFile
or checkResult
to determine if
anything changed:
cmdProperty "chmod" ["600", "/etc/secret"] `changesFile` "/etc/secret"
Or you can punt and assume
a change was made, but then propellor will
always say it make a change, and onChange
will always fire.
cmdProperty "service" ["foo", "reload"] `assume` MadeChange
Synopsis
- cmdProperty :: String -> [String] -> UncheckedProperty UnixLike
- cmdProperty' :: String -> [String] -> (CreateProcess -> CreateProcess) -> UncheckedProperty UnixLike
- cmdPropertyEnv :: String -> [String] -> [(String, String)] -> UncheckedProperty UnixLike
- type Script = [String]
- scriptProperty :: Script -> UncheckedProperty UnixLike
- userScriptProperty :: User -> Script -> UncheckedProperty UnixLike
- cmdResult :: Bool -> Result
- data CommandParam
- boolSystem :: FilePath -> [CommandParam] -> IO Bool
- boolSystemEnv :: FilePath -> [CommandParam] -> Maybe [(String, String)] -> IO Bool
- safeSystem :: FilePath -> [CommandParam] -> IO ExitCode
- safeSystemEnv :: FilePath -> [CommandParam] -> Maybe [(String, String)] -> IO ExitCode
- shellEscape :: String -> String
- createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
- waitForProcess :: ProcessHandle -> IO ExitCode
Constricting properties running commands and scripts
cmdProperty :: String -> [String] -> UncheckedProperty UnixLike Source #
A property that can be satisfied by running a command.
The command must exit 0 on success.
cmdProperty' :: String -> [String] -> (CreateProcess -> CreateProcess) -> UncheckedProperty UnixLike Source #
cmdPropertyEnv :: String -> [String] -> [(String, String)] -> UncheckedProperty UnixLike Source #
A property that can be satisfied by running a command, with added environment variables in addition to the standard environment.
scriptProperty :: Script -> UncheckedProperty UnixLike Source #
A property that can be satisfied by running a script.
userScriptProperty :: User -> Script -> UncheckedProperty UnixLike Source #
A property that can satisfied by running a script as user (cd'd to their home directory).
Lower-level interface for running commands
data CommandParam Source #
Parameters that can be passed to a shell command.
Instances
Show CommandParam Source # | |
Defined in Utility.SafeCommand showsPrec :: Int -> CommandParam -> ShowS # show :: CommandParam -> String # showList :: [CommandParam] -> ShowS # | |
Eq CommandParam Source # | |
Defined in Utility.SafeCommand (==) :: CommandParam -> CommandParam -> Bool # (/=) :: CommandParam -> CommandParam -> Bool # | |
Ord CommandParam Source # | |
Defined in Utility.SafeCommand compare :: CommandParam -> CommandParam -> Ordering # (<) :: CommandParam -> CommandParam -> Bool # (<=) :: CommandParam -> CommandParam -> Bool # (>) :: CommandParam -> CommandParam -> Bool # (>=) :: CommandParam -> CommandParam -> Bool # max :: CommandParam -> CommandParam -> CommandParam # min :: CommandParam -> CommandParam -> CommandParam # |
boolSystem :: FilePath -> [CommandParam] -> IO Bool Source #
Run a system command, and returns True or False if it succeeded or failed.
This and other command running functions in this module log the commands run at debug level, using System.Log.Logger.
boolSystemEnv :: FilePath -> [CommandParam] -> Maybe [(String, String)] -> IO Bool Source #
safeSystem :: FilePath -> [CommandParam] -> IO ExitCode Source #
Runs a system command, returning the exit status.
safeSystemEnv :: FilePath -> [CommandParam] -> Maybe [(String, String)] -> IO ExitCode Source #
shellEscape :: String -> String Source #
Escapes a filename or other parameter to be safely able to be exposed to the shell.
This method works for POSIX shells, as well as other shells like csh.
createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) Source #
Wrapper around createProcess
that does debug logging.
waitForProcess :: ProcessHandle -> IO ExitCode Source #
Wrapper around waitForProcess
that does debug logging.