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

[Event listener] Add a new supervisord event listener to pmon container #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
49 changes: 49 additions & 0 deletions sonic-event-listener/scripts/event-listener
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python2

'''
event-listener
Supervisord event listener for SONiC pmon container
This event listener will monitor the 'SUPERVISOR_STATE_CHANGE_STOPPING' event of supervisord when it is shutting down.
On this event, event listener will call command 'post-syseeprom -c' to clear the state DB.
'''

try:
import sys
import subprocess
from supervisor.childutils import listener
except ImportError, e:
raise ImportError (str(e) + " - required module not found")

EVENT_TO_LISTEN = 'SUPERVISOR_STATE_CHANGE_STOPPING'
COMMAND_ON_EVENT = 'post-syseeprom -c'

def write_log(s):
sys.stderr.write(s)
sys.stderr.flush()

class EventListener:
def __init__(self, event, command_string):
self.event = event
self.command = (command_string.strip()).split()

def run(self):
write_log("Event-listener start up...\n")

while True:
headers, body = listener.wait()
if headers["eventname"] == self.event:
subprocess.call(self.command)
write_log("Event-listener process docker stopping... \n")
listener.ok(sys.stdout)
break

listener.ok(sys.stdout)

write_log("Event-listener shutting down...\n")

def main():
event_listener = EventListener(EVENT_TO_LISTEN, COMMAND_ON_EVENT)
event_listener.run()

if __name__ == '__main__':
main()
29 changes: 29 additions & 0 deletions sonic-event-listener/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from setuptools import setup

setup(
name='sonic-event-listener',
version='1.0',
description='Sonic pmon supervisord event listener ',
license='Apache 2.0',
author='SONiC Team',
author_email='linuxnetdev@microsoft.com',
url='https://github.com/Azure/sonic-platform-daemons',
maintainer='Kebo Liu',
maintainer_email='kebol@mellanox.com',
scripts=[
'scripts/event-listener',
],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: No Input/Output (Daemon)',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Topic :: System :: Supervisord',
],
keywords='sonic SONiC SUPERVISORD supervisord EVENT-LISTENER event-listener',
)