6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/amiral/providers/service.rb', line 6
def execute message
action = "reload"
service = message['command']['args'][0]
if message['command']['args'].length > 1
action = message['command']['args'][1]
end
raise "unknown service command" unless ["stop", "start", "restart", "status", "reload"].include? action
out = err = nil
status = POpen4::popen4("service #{service} #{action}"){|stdout, stderr, stdin, pid|
out = stdout.read
err = stderr.read
}
{
:exit => status.exitstatus,
:short => (status.exitstatus == 0) ?
"service #{service} #{action} successful" :
"service #{service} #{action} failed!",
:out => out,
:err => err
}
end
|