daemon: Log output from state hooks to a file.
Also close other file descriptors when running state hooks.
This commit is contained in:
parent
6e092389af
commit
6fb1eb9bd6
1 changed files with 11 additions and 2 deletions
|
@ -14,6 +14,7 @@ that manages a CORE session.
|
|||
import os, sys, tempfile, shutil, shlex, atexit, gc, pwd
|
||||
import threading, time, random
|
||||
import traceback
|
||||
import subprocess
|
||||
|
||||
from core.api import coreapi
|
||||
if os.uname()[0] == "Linux":
|
||||
|
@ -293,8 +294,16 @@ class Session(object):
|
|||
self.warn("Error writing hook '%s': %s" % (filename, e))
|
||||
self.info("Running hook %s for state %s" % (filename, state))
|
||||
try:
|
||||
check_call(["/bin/sh", filename], cwd=self.sessiondir,
|
||||
env=self.getenviron())
|
||||
stdout = open(os.path.join(self.sessiondir,
|
||||
filename + '.log'), 'w')
|
||||
stderr = subprocess.STDOUT
|
||||
except:
|
||||
stdout = None
|
||||
stderr = None
|
||||
try:
|
||||
check_call(["/bin/sh", filename], stdout=stdout,
|
||||
stderr=stderr, close_fds=True,
|
||||
cwd=self.sessiondir, env=self.getenviron())
|
||||
except Exception, e:
|
||||
self.warn("Error running hook '%s' for state %s: %s" %
|
||||
(filename, state, e))
|
||||
|
|
Loading…
Reference in a new issue