Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Add RereadConfiguration event. Signal SIGHUP fires it. #105

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion pox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class (an instance of which is available as pox.core.core).
import inspect
import time
import os
import signal

_path = inspect.stack()[0][1]
_ext_path = _path[0:_path.rindex(os.sep)]
Expand Down Expand Up @@ -152,6 +153,10 @@ def __init__ (self, name, component):
self.name = name
self.component = component

class RereadConfiguration (Event):
""" Fired when modules should reread their configuration files. """
pass

import pox.lib.recoco as recoco

class POXCore (EventMixin):
Expand Down Expand Up @@ -179,7 +184,8 @@ class POXCore (EventMixin):
DownEvent,
GoingUpEvent,
GoingDownEvent,
ComponentRegistered
ComponentRegistered,
RereadConfiguration
])

version = (0,3,0)
Expand Down Expand Up @@ -317,6 +323,15 @@ def _get_platform_info (self):
except:
return "Unknown Platform"

def _add_signal_handlers (self):
try:
signal.signal(signal.SIGHUP, self._handler_signal_SIGHUP)
except ValueError:
log.warn('failed to install handler SIGHUP')

def _handler_signal_SIGHUP (self, signal, frame):
self.raiseLater(core, RereadConfiguration)

def goUp (self):
log.debug(self.version_string + " going up...")

Expand All @@ -337,6 +352,8 @@ def goUp (self):
self.starting_up = False
self.raiseEvent(GoingUpEvent())

self._add_signal_handlers()

self.raiseEvent(UpEvent())

self._waiter_notify()
Expand Down