Commit 9cb427b4 authored by Kean Johnston's avatar Kean Johnston
Browse files

[433] Check to make sure msqg isnt already running.

Check to ensure there is no existing daemon running before removing
the socket endpoint. Fail to start if one is. Added a new test to
check this behaviour.
parent 9b7cc4af
......@@ -74,6 +74,8 @@ SPECFILE_LOCATION = SPECFILE_PATH + "/msgq.spec"
class MsgQReceiveError(Exception): pass
class MsgQRunningError(Exception): pass
class MsgQCloseOnReceive(Exception):
"""Exception raised when reading data from a socket results in 'shutdown'.
......@@ -268,11 +270,28 @@ class MsgQ:
"""Set up the listener socket. Internal function."""
logger.debug(TRACE_BASIC, MSGQ_LISTENER_SETUP, self.socket_file)
self.listen_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
if os.path.exists(self.socket_file):
# Rather than just blindly removing the socket file, attempt to
# connect to the existing socket to see if there is an existing
# msgq running. Only if that fails do we remove the file and
# attempt to create a new socket.
self._existing = True
self._session =
self._existing = False
self._session = None
if self._existing:
raise MsgQRunningError("Message Queue daemon already running")
self.listen_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
except Exception as e:
......@@ -19,6 +19,10 @@
# <topsrcdir>/tools/ to make sure the
# messages are in the correct order.
% MSGQ_ALREADY_RUNNING Another copy of the message queue daemon is already running.
Only a single instance of the message queue daemon should ever be run at one
time. This instance will now terminate.
% MSGQ_CFGMGR_SUBSCRIBED The config manager subscribed to message queue
This is a debug message. The message queue has little bit of special handling
for the configuration manager. This special handling is happening now.
......@@ -328,6 +328,14 @@ class MsgqRunTest(unittest.TestCase):
'group': 'notifications/cc_members'
}]}, msg)
def test_multiple_invocations(self):
Check to make sure that an attempt to start a second copy of the MsgQ
daemon fails.
self.__retcode =[MSGQ_PATH, '-s', SOCKET_PATH])
self.assertNotEqual(self.__retcode, 0)
if __name__ == '__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment