File: shutdown.xml

package info (click to toggle)
kamailio 5.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 68,332 kB
  • sloc: ansic: 744,091; xml: 196,848; cpp: 14,471; makefile: 8,859; sh: 8,814; sql: 7,844; yacc: 3,863; perl: 2,955; python: 2,710; java: 449; javascript: 269; php: 258; ruby: 225; cs: 40; awk: 27
file content (100 lines) | stat: -rw-r--r-- 3,906 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 
   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<section id="shutdown" xmlns:xi="http://www.w3.org/2001/XInclude">
    <sectioninfo>
	<revhistory>
	    <revision>
		<revnumber>$Revision$</revnumber>
		<date>$Date$</date>
	    </revision>
	</revhistory>
    </sectioninfo>
    
    <title>The Server Showdown</title>
    <para>
	The server shutdown can be triggered by sending a signal to the
	server. The server will behave differently upon receiving various types
	of signals, here is a brief summary:
    </para>
    <itemizedlist>
	<listitem>
	    <para>
		<emphasis>SIGINT, SIGPIPE, SIGTERM, SIGCHLD</emphasis> will terminate the server.
	    </para>
	</listitem>
	<listitem>
	    <para>
		<emphasis>SIGUSR1</emphasis> will print statistics and let the server continue.
	    </para>
	</listitem>
	<listitem>
	    <para>
		<emphasis>SIGHUP, SIGUSR2</emphasis> will be ignored.
	    </para>
	</listitem>
    </itemizedlist>
    
    <para>
	There is only one common signal handler for all signals - function
	<function>sig_usr</function> in file <filename>main.c</filename>.
    </para>
    
    <para>
	In normal mode of operation (<varname>dont_fork</varname> variable is
	not set), the main server is not processing any requests, it calls
	<function>pause</function> function and will be waiting for signals
	only. What happens when a signal arrives is shown in the previous
	paragraph.
    </para>
    <para>
	When in normal mode (<varname>dont_fork</varname> is not set), the
	signal handler of the main process will only store number of the signal
	received.  All the processing logic will be executed by the main
	process outside the signal handler (function
	<function>handle_sigs</function>) The function will be called
	immediately after the signal handler finish. The main process usually
	does some cleanup and running such things outside the signal handler is
	much more safe than doing it from the handler itself. Children only
	print statistics and exit or ignore the signal completely, that is
	quite safe and can be done directly from the signal handler of
	children.
    </para>
    <para>
	When <varname>dont_fork</varname> is set, all the cleanup will be done
	directly from the signal handler, because there is only one process -
	the main process. This is not so safe as the previous case, but this
	mode should be used for debugging only and such shortcoming doesn't
	harm in that case.
    </para>
    <para>
	Upon receipt of SIGINT, SIGPIPE or SIGTERM
	<function>destroy_modules</function> will be called.  Each module may
	register so-called <function>destroy</function> function if it needs to
	do some cleanup when the server is terminating (flush of cache to disk
	for example). <function>destroy_modules</function> will call destroy
	function of all loaded modules.
    </para>
     <para>
	If you need to terminate the server and all of its children, the best
	way how to do it is to send SIGTERM to the main process, the main
	process will in turn send the same signal to its children.
    </para>
    <para>
	The main process and its children are in the same process
	group. Therefore the main process can kill all its children simply by
	sending a signal to pid 0, sending to pid 0 will send the signal to all
	processes in the same process group as the sending process. This is how
	the main process will terminate all children when it is going to shut
	down.
    </para>
    <para>
	If one child exited during normal operation, the whole server will be
	shut down. This is better than let the server continue - a dead child
	might hold a lock and that could block the whole server, such situation
	cannot be avoided easily. Instead of that it is better to shutdown the
	whole server and let it restart.
    </para>

</section> <!-- server-shutdown -->