Skip to content

Commit d7b6f77

Browse files
committed
add sigterm and exit handlers
Change-Id: Ifbfeed6b23a9cbce46cd4cb1724e5c769646653b Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
1 parent f2af3b5 commit d7b6f77

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

cloudbaseinit/shell.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15+
import atexit
16+
import signal
1517
import sys
1618

1719
from oslo_log import log as oslo_logging
@@ -29,6 +31,20 @@ def main():
2931
CONF(sys.argv[1:])
3032
logging.setup('cloudbaseinit')
3133

34+
def atexit_handler():
35+
LOG.debug("Process is exiting")
36+
try:
37+
atexit.register(atexit_handler)
38+
except Exception as exc:
39+
LOG.exception(exc)
40+
41+
def on_sigterm_handler(sig, frame):
42+
LOG.debug("Process has received sigterm")
43+
try:
44+
signal.signal(signal.SIGTERM, on_sigterm_handler)
45+
except Exception as exc:
46+
LOG.exception(exc)
47+
3248
try:
3349
init.InitManager().configure_host()
3450
except Exception as exc:

0 commit comments

Comments
 (0)