Skip to content

Commit

Permalink
[thermalctld] Fix issue: thermalctld should be auto restarted when be…
Browse files Browse the repository at this point in the history
…ing killed (sonic-net#94)

Part of thermalctld function is to handle user space thermal policies for events like fan/PSU removing, it works together with kernel thermal algorithm to make sure the switch won't be overheat.

Recently, we found that commit sonic-net/sonic-buildimage@cbc75fe changes its autorestart configuration in supervisord, and it won't be auto restarted after being killed. This PR is to make sure that thermalctld will be always restarted when it is killed.
  • Loading branch information
Junchao-Mellanox authored Sep 18, 2020
1 parent e1842b2 commit 4fdf975
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
super(ThermalControlDaemon, self).__init__(log_identifier)
self.stop_event = threading.Event()

# Thermal control daemon is designed to never exit, it must always
# return non zero exit code when exiting and so that supervisord will
# restart it automatically.
self.exit_code = 1

# Signal handler
def signal_handler(self, sig, frame):
"""
Expand All @@ -632,11 +637,9 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
"""
if sig == signal.SIGHUP:
self.log_info("Caught SIGHUP - ignoring...")
elif sig == signal.SIGINT:
self.log_info("Caught SIGINT - exiting...")
self.stop_event.set()
elif sig == signal.SIGTERM:
self.log_info("Caught SIGTERM - exiting...")
elif sig == signal.SIGINT or sig == signal.SIGTERM:
self.log_info("Caught signal {} - exiting...".format(sig))
self.exit_code = sig + 128
self.stop_event.set()
else:
self.log_warning("Caught unhandled signal '" + sig + "'")
Expand Down Expand Up @@ -690,7 +693,8 @@ class ThermalControlDaemon(daemon_base.DaemonBase):

thermal_monitor.task_stop()

self.log_info("Shutdown...")
self.log_info("Shutdown with exit code {}...".format(self.exit_code))
exit(self.exit_code)


#
Expand Down

0 comments on commit 4fdf975

Please sign in to comment.