另外根據[云原生十二要素方法論] 第9條: 快速啟動和優雅終止可最大化健壯性 , 也推薦各位遵守實踐。 Fast startup and shutdown are advocated for a more robust and resilient system.
粗淺的認知方案: 捕獲程序的終止信號, 主動去卸任。
標準信號 Linux支持如下標準信號,第二列指示該信號遵守的標準。
Signal Standard Action Comment────────────────────────────────────────────────────────────────────────SIGABRT P1990 Core Abort signal from abort(3)SIGALRM P1990 Term Timer signal from alarm(2)SIGBUS P2001 Core Bus error (bad memory access)SIGCHLD P1990 Ign Child stopped or terminatedSIGCLD - Ign A synonym for SIGCHLDSIGCONT P1990 Cont Continue if stoppedSIGEMT - Term Emulator trapSIGFPE P1990 Core Floating-point exceptionSIGHUP P1990 Term Hangup detected on controlling terminalor death of controlling processSIGILL P1990 Core Illegal InstructionSIGINFO - A synonym for SIGPWRSIGINT P1990 Term Interrupt from keyboardSIGIO - Term I/O now possible (4.2BSD)SIGIOT - Core IOT trap. A synonym for SIGABRTSIGKILL P1990 Term Kill signalSIGLOST - Term File lock lost (unused)SIGPIPE P1990 Term Broken pipe: write to pipe with noreaders; see pipe(7)SIGPOLL P2001 Term Pollable event (Sys V);synonym for SIGIOSIGPROF P2001 Term Profiling timer expiredSIGPWR - Term Power failure (System V)SIGQUIT P1990 Core Quit from keyboardSIGSEGV P1990 Core Invalid memory referenceSIGSTKFLT - Term Stack fault on coprocessor (unused)SIGSTOP P1990 Stop Stop processSIGTSTP P1990 Stop Stop typed at terminalSIGSYS P2001 Core Bad system call (SVr4);see also seccomp(2)SIGTERM P1990 Term Termination signalSIGTRAP P2001 Core Trace/breakpoint trapSIGTTIN P1990 Stop Terminal input for background processSIGTTOU P1990 Stop Terminal output for background processSIGUNUSED - Core Synonymous with SIGSYSSIGURG P2001 Ign Urgent condition on socket (4.2BSD)SIGUSR1 P1990 Term User-defined signal 1SIGUSR2 P1990 Term User-defined signal 2SIGVTALRM P2001 Term Virtual alarm clock (4.2BSD)SIGXCPU P2001 Core CPU time limit exceeded (4.2BSD);see setrlimit(2)SIGXFSZ P2001 Core File size limit exceeded (4.2BSD);see setrlimit(2)SIGWINCH - Ign Window resize signal (4.3BSD, Sun)