Revision 60d6a13b
b/logic/dispatcher.py | ||
---|---|---|
28 | 28 |
import time |
29 | 29 |
import socket |
30 | 30 |
from daemon import pidfile, daemon |
31 |
import lockfile.pidlockfile |
|
31 | 32 |
|
32 | 33 |
from synnefo.logic import callbacks |
33 | 34 |
|
... | ... | |
47 | 48 |
self.debug = debug |
48 | 49 |
self._init() |
49 | 50 |
|
50 |
|
|
51 | 51 |
def wait(self): |
52 | 52 |
while True: |
53 | 53 |
try: |
... | ... | |
220 | 220 |
|
221 | 221 |
# Create pidfile |
222 | 222 |
pidf = pidfile.TimeoutPIDLockFile("/Volumes/Files/Developer/grnet/synnefo/dispatcher.pid", 10) |
223 |
pidf.acquire() |
|
224 |
pidf.__enter__() |
|
223 | 225 |
|
224 | 226 |
# Become a daemon |
225 | 227 |
daemon_context = daemon.DaemonContext( |
226 |
pidfile=pidf,
|
|
227 |
stdout=sys.stdout,
|
|
228 |
stderr=sys.stderr,
|
|
229 |
umask=022) |
|
228 |
stdout=sys.stdout,
|
|
229 |
stderr=sys.stderr,
|
|
230 |
umask=022)
|
|
231 |
|
|
230 | 232 |
daemon_context.open() |
231 | 233 |
logger.info("Became a daemon") |
232 | 234 |
|
... | ... | |
238 | 240 |
newpid = os.fork() |
239 | 241 |
|
240 | 242 |
if newpid == 0: |
241 |
signal(SIGINT, _exit_handler) |
|
243 |
signal(SIGINT, _exit_handler)
|
|
242 | 244 |
signal(SIGTERM, _exit_handler) |
243 | 245 |
child(sys.argv[1:]) |
244 |
try: |
|
245 |
sys.exit(0) |
|
246 |
except Exception: |
|
247 |
print "foo" |
|
246 |
sys.exit(1) |
|
248 | 247 |
else: |
249 | 248 |
pids = (os.getpid(), newpid) |
250 | 249 |
logger.debug("%d, forked child: %d" % pids) |
... | ... | |
262 | 261 |
except Exception: |
263 | 262 |
pass |
264 | 263 |
|
264 |
pidf.release() |
|
265 |
pidf.__exit__() |
|
265 | 266 |
|
266 | 267 |
if __name__ == "__main__": |
267 | 268 |
logging.basicConfig(level=logging.DEBUG) |
Also available in: Unified diff