summaryrefslogtreecommitdiff
path: root/Propellor/Property/Cmd.hs
diff options
context:
space:
mode:
authorJoey Hess2014-04-08 17:10:52 -0400
committerJoey Hess2014-04-08 17:10:52 -0400
commit4ea2771b69617bc537687f9b2fec4b0a32880de5 (patch)
tree19a4511b1890bdc80587828e362fa9193c559343 /Propellor/Property/Cmd.hs
parentc40fb997ed3026526c7fa14ce58322a84375ed8c (diff)
propellor spin
Diffstat (limited to 'Propellor/Property/Cmd.hs')
-rw-r--r--Propellor/Property/Cmd.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/Propellor/Property/Cmd.hs b/Propellor/Property/Cmd.hs
index dc5073d3..f661cf81 100644
--- a/Propellor/Property/Cmd.hs
+++ b/Propellor/Property/Cmd.hs
@@ -4,6 +4,7 @@ module Propellor.Property.Cmd (
scriptProperty,
userScriptProperty,
serviceRunning,
+ serviceRestarted,
) where
import Control.Monad
@@ -47,13 +48,21 @@ userScriptProperty user script = cmdProperty "su" ["-c", shellcmd, user]
where
shellcmd = intercalate " ; " ("set -e" : "cd" : script)
+type ServiceName = String
+
-- | Ensures that a service is running.
--
-- Note that due to the general poor state of init scripts, the best
-- we can do is try to start the service, and if it fails, assume
-- this means it's already running.
-serviceRunning :: String -> Property
+serviceRunning :: ServiceName -> Property
serviceRunning svc = Property ("running " ++ svc) $ do
void $ ensureProperty $
scriptProperty ["service " ++ shellEscape svc ++ " start >/dev/null 2>&1 || true"]
return NoChange
+
+serviceRestarted :: ServiceName -> Property
+serviceRestarted svc = Property ("restarted " ++ svc) $ do
+ void $ ensureProperty $
+ scriptProperty ["service " ++ shellEscape svc ++ " restart >/dev/null 2>&1 || true"]
+ return NoChange