import errno import os pidfile_path = configuration.services.SERVICEMANAGER["pidfile_path"] if os.path.isfile(pidfile_path): print >> sys.stderr, "%s: file exists; daemon already running?" % pidfile_path sys.exit(1) try: os.makedirs(os.path.dirname(pidfile_path)) except OSError, error: if error.errno == errno.EEXIST: pass else: raise daemon.detach() pidfile = open(pidfile_path, "w") pidfile.write("%s\n" % os.getpid()) pidfile.close() was_terminated = False def terminated(signum, frame): global was_terminated was_terminated = True signal.signal(signal.SIGTERM, terminated) while not was_terminated: process = subprocess.Popen([sys.executable, sys.argv[0], "--slave"])
while True: filenames = glob.glob(starting_pattern) if not filenames: return 0 if time.time() > deadline: break time.sleep(0.1) print >>sys.stderr print >>sys.stderr, ("Startup synchronization timeout after %d seconds!" % STARTUP_SYNC_TIMEOUT) print >>sys.stderr, "Services still starting:" for filename in filenames: print >>sys.stderr, " " + os.path.basename(filename) return 1 with open(pidfile_path, "w") as pidfile: daemon.detach(parent_exit_hook=wait_for_startup_sync) pidfile.write("%s\n" % os.getpid()) os.umask(022) was_terminated = False def terminated(signum, frame): global was_terminated was_terminated = True signal.signal(signal.SIGTERM, terminated) while not was_terminated: process = subprocess.Popen( [sys.executable, "-m", "background.servicemanager", "--slave"], stdin=subprocess.PIPE
try: os.makedirs(os.path.dirname(pidfile_path)) except OSError, error: if error.errno != errno.EEXIST: raise else: os.chown(pidfile_path, uid, gid) os.chmod(pidfile_path, 0750 | stat.S_ISUID | stat.S_ISGID) os.environ["HOME"] = home os.chdir(home) os.setgid(gid) os.setuid(uid) daemon.detach() with open(pidfile_path, "w") as pidfile: pidfile.write("%s\n" % os.getpid()) was_terminated = False def terminated(signum, frame): global was_terminated was_terminated = True signal.signal(signal.SIGTERM, terminated) while not was_terminated: process = subprocess.Popen( [sys.executable, "-m", "background.servicemanager", "--slave"])
if not filenames: return 0 if time.time() > deadline: break time.sleep(0.1) print >> sys.stderr print >> sys.stderr, ( "Startup synchronization timeout after %d seconds!" % STARTUP_SYNC_TIMEOUT) print >> sys.stderr, "Services still starting:" for filename in filenames: print >> sys.stderr, " " + os.path.basename(filename) return 1 with open(pidfile_path, "w") as pidfile: daemon.detach(parent_exit_hook=wait_for_startup_sync) pidfile.write("%s\n" % os.getpid()) os.umask(022) was_terminated = False def terminated(signum, frame): global was_terminated was_terminated = True signal.signal(signal.SIGTERM, terminated) while not was_terminated: process = subprocess.Popen( [sys.executable, "-m", "background.servicemanager", "--slave"],