summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Service.hs
blob: 14e769d09f4fb7b13c683239715b02d66496b620 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Propellor.Property.Service where

import Propellor
import Utility.SafeCommand

type ServiceName = String

-- | Ensures that a service is running. Does not ensure that
-- any package providing that service is installed. See
-- Apt.serviceInstalledRunning
--
-- 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.
running :: ServiceName -> Property
running svc = property ("running " ++ svc) $ do
	void $ ensureProperty $
		scriptProperty ["service " ++ shellEscape svc ++ " start >/dev/null 2>&1 || true"]
	return NoChange

restarted :: ServiceName -> Property
restarted svc = property ("restarted " ++ svc) $ do
	void $ ensureProperty $
		scriptProperty ["service " ++ shellEscape svc ++ " restart >/dev/null 2>&1 || true"]
	return NoChange

reloaded :: ServiceName -> Property
reloaded svc = property ("reloaded " ++ svc) $ do
	void $ ensureProperty $
		scriptProperty ["service " ++ shellEscape svc ++ " reload >/dev/null 2>&1 || true"]
	return NoChange