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

[Pmon] Add new daemon "syseepromd" to pmon docker #2866

Merged
merged 14 commits into from
Jun 18, 2019
2 changes: 1 addition & 1 deletion dockers/docker-platform-monitor/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RUN apt-get autoclean -y
RUN apt-get autoremove -y
RUN rm -rf /debs /python-wheels ~/.cache

COPY ["docker_init.sh", "lm-sensors.sh", "/usr/bin/"]
COPY ["docker_init.sh", "lm-sensors.sh", "event-listener", "/usr/bin/"]
COPY ["docker-pmon.supervisord.conf.j2", "start.sh.j2", "/usr/share/sonic/templates/"]

ENTRYPOINT ["/usr/bin/docker_init.sh"]
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ stdout_logfile=syslog
stderr_logfile=syslog
startsecs=0
{% endif %}

[eventlistener:event-listener]
command=/usr/bin/event-listener
events=SUPERVISOR_STATE_CHANGE_STOPPING
stderr_logfile=syslog

49 changes: 49 additions & 0 deletions dockers/docker-platform-monitor/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()
7 changes: 7 additions & 0 deletions dockers/docker-platform-monitor/start.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ supervisorctl start xcvrd
{% if not skip_psud %}
supervisorctl start psud
{% endif %}

post-syseeprom -w
keboliu marked this conversation as resolved.
Show resolved Hide resolved
rc=$?
if [ $rc != 0 ]; then
exit $rc
fi

keboliu marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion rules/docker-platform-monitor.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DOCKER_PLATFORM_MONITOR = docker-platform-monitor.gz
$(DOCKER_PLATFORM_MONITOR)_PATH = $(DOCKERS_PATH)/docker-platform-monitor
$(DOCKER_PLATFORM_MONITOR)_DEPENDS += $(LIBSENSORS) $(LM_SENSORS) $(FANCONTROL) $(SENSORD) $(LIBSWSSCOMMON) $(PYTHON_SWSSCOMMON) $(SMARTMONTOOLS)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_DEBS += $(SONIC_LEDD) $(SONIC_XCVRD) $(SONIC_PSUD)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_DEBS += $(SONIC_LEDD) $(SONIC_XCVRD) $(SONIC_PSUD) $(SONIC_POST_SYSEEPROM)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_COMMON_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SWSSSDK_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
Expand Down
5 changes: 5 additions & 0 deletions rules/sonic-post-syseeprom.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# sonic-post-syseeprom (SONiC Syseeprom gathering task) Debian package

SONIC_POST_SYSEEPROM = python-sonic-post-syseeprom_1.0-1_all.deb
$(SONIC_POST_SYSEEPROM)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-post-syseeprom
SONIC_PYTHON_STDEB_DEBS += $(SONIC_POST_SYSEEPROM)