Fix: Cleanly exit on SIGTERM
This commit is contained in:
parent
69e5f137a6
commit
401ebcf685
2 changed files with 21 additions and 2 deletions
|
|
@ -1,5 +1,12 @@
|
||||||
# OctoPrint Changelog
|
# OctoPrint Changelog
|
||||||
|
|
||||||
|
## 1.2.1 (unreleased)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [IRC] - OctoPrint will now exit cleanly on `SIGTERM`, calling the shutdown functions provided by plugins.
|
||||||
|
Thanks @Salandora for the heads-up.
|
||||||
|
|
||||||
## 1.2.0 (2015-06-25)
|
## 1.2.0 (2015-06-25)
|
||||||
|
|
||||||
### Note for Upgraders
|
### Note for Upgraders
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import atexit
|
import atexit
|
||||||
|
import signal
|
||||||
|
|
||||||
SUCCESS = {}
|
SUCCESS = {}
|
||||||
NO_CONTENT = ("", 204)
|
NO_CONTENT = ("", 204)
|
||||||
|
|
@ -440,16 +441,27 @@ class Server():
|
||||||
|
|
||||||
# prepare our shutdown function
|
# prepare our shutdown function
|
||||||
def on_shutdown():
|
def on_shutdown():
|
||||||
self._logger.info("Goodbye!")
|
# will be called on clean system exit and shutdown the watchdog observer and call the on_shutdown methods
|
||||||
|
# on all registered ShutdownPlugins
|
||||||
|
self._logger.info("Shutting down...")
|
||||||
observer.stop()
|
observer.stop()
|
||||||
observer.join()
|
observer.join()
|
||||||
octoprint.plugin.call_plugin(octoprint.plugin.ShutdownPlugin,
|
octoprint.plugin.call_plugin(octoprint.plugin.ShutdownPlugin,
|
||||||
"on_shutdown")
|
"on_shutdown")
|
||||||
|
self._logger.info("Goodbye!")
|
||||||
atexit.register(on_shutdown)
|
atexit.register(on_shutdown)
|
||||||
|
|
||||||
|
def sigterm_handler(*args, **kwargs):
|
||||||
|
# will stop tornado on SIGTERM, making the program exit cleanly
|
||||||
|
def shutdown_tornado():
|
||||||
|
ioloop.stop()
|
||||||
|
ioloop.add_callback_from_signal(shutdown_tornado)
|
||||||
|
signal.signal(signal.SIGTERM, sigterm_handler)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# this is the main loop - as long as tornado is running, OctoPrint is running
|
||||||
ioloop.start()
|
ioloop.start()
|
||||||
except KeyboardInterrupt:
|
except (KeyboardInterrupt, SystemExit):
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
self._logger.fatal("Now that is embarrassing... Something really really went wrong here. Please report this including the stacktrace below in OctoPrint's bugtracker. Thanks!")
|
self._logger.fatal("Now that is embarrassing... Something really really went wrong here. Please report this including the stacktrace below in OctoPrint's bugtracker. Thanks!")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue