def begin_handover(self, fdtx_dir='/tmp/ave'):
# call this function on the broker that is going to be replaced.
# steps:
# stop listening for new connections from clients, stop the notifier,
# disconnect all shares, disable further allocation (a session will
# receive a Restarting exception if it manages to allocate at precisely
# this moment and is expected to try again once or twice), create a
# UNIX domain socket to transfer file descriptors (in a separate step),
# serialize the state of the local allocator and all live sessions
# (PIDs and RPC keys). finally return serialized data and the path to
# UNIX domain socket.
# first of all check that fdtx_dir is writable. otherwise the socket
# will not be created in it and everything fails
if os.path.exists(fdtx_dir) and os.path.isdir(fdtx_dir):
if not os.access(fdtx_dir, os.R_OK | os.X_OK | os.W_OK):
raise Exception('directory not writable: %s' % fdtx_dir)
self.stop_listening()
self.stop_sharing()
self.drop_all_shares()
self.stop_listers()
self.allocating = False
self.fdtx = FdTx(None)
uds_path = self.fdtx.listen(fdtx_dir, 'handover-%s' % rand_authkey())
# make sure the caller will be able to interact with the new socket by
# making it world readable and world writable
mode = (stat.S_IRUSR # owner has read permission
| stat.S_IWUSR # owner has write permission
| stat.S_IRGRP # group has read permission
| stat.S_IWGRP # group has write permission
| stat.S_IROTH # others have read permission
| stat.S_IWOTH) # others have write permission
os.chmod(uds_path, mode)
return self.serialize(), self.config, uds_path
评论列表
文章目录