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 os, sys, tempfile, shutil, shlex, atexit, gc, pwd
|
||||||
import threading, time, random
|
import threading, time, random
|
||||||
import traceback
|
import traceback
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from core.api import coreapi
|
from core.api import coreapi
|
||||||
if os.uname()[0] == "Linux":
|
if os.uname()[0] == "Linux":
|
||||||
|
@ -293,8 +294,16 @@ class Session(object):
|
||||||
self.warn("Error writing hook '%s': %s" % (filename, e))
|
self.warn("Error writing hook '%s': %s" % (filename, e))
|
||||||
self.info("Running hook %s for state %s" % (filename, state))
|
self.info("Running hook %s for state %s" % (filename, state))
|
||||||
try:
|
try:
|
||||||
check_call(["/bin/sh", filename], cwd=self.sessiondir,
|
stdout = open(os.path.join(self.sessiondir,
|
||||||
env=self.getenviron())
|
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:
|
except Exception, e:
|
||||||
self.warn("Error running hook '%s' for state %s: %s" %
|
self.warn("Error running hook '%s' for state %s: %s" %
|
||||||
(filename, state, e))
|
(filename, state, e))
|
||||||
|
|
Loading…
Add table
Reference in a new issue