shutdown.xml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  4. <section id="shutdown" xmlns:xi="http://www.w3.org/2001/XInclude">
  5. <sectioninfo>
  6. <revhistory>
  7. <revision>
  8. <revnumber>$Revision$</revnumber>
  9. <date>$Date$</date>
  10. </revision>
  11. </revhistory>
  12. </sectioninfo>
  13. <title>The Server Showdown</title>
  14. <para>
  15. The server shutdown can be triggered by sending a signal to the
  16. server. The server will behave differently upon receiving various types
  17. of signals, here is a brief summary:
  18. </para>
  19. <itemizedlist>
  20. <listitem>
  21. <para>
  22. <emphasis>SIGINT, SIGPIPE, SIGTERM, SIGCHLD</emphasis> will terminate the server.
  23. </para>
  24. </listitem>
  25. <listitem>
  26. <para>
  27. <emphasis>SIGUSR1</emphasis> will print statistics and let the server continue.
  28. </para>
  29. </listitem>
  30. <listitem>
  31. <para>
  32. <emphasis>SIGHUP, SIGUSR2</emphasis> will be ignored.
  33. </para>
  34. </listitem>
  35. </itemizedlist>
  36. <para>
  37. There is only one common signal handler for all signals - function
  38. <function>sig_usr</function> in file <filename>main.c</filename>.
  39. </para>
  40. <para>
  41. In normal mode of operation (<varname>dont_fork</varname> variable is
  42. not set), the main server is not processing any requests, it calls
  43. <function>pause</function> function and will be waiting for signals
  44. only. What happens when a signal arrives is shown in the previous
  45. paragraph.
  46. </para>
  47. <para>
  48. When in normal mode (<varname>dont_fork</varname> is not set), the
  49. signal handler of the main process will only store number of the signal
  50. received. All the processing logic will be executed by the main
  51. process outside the signal handler (function
  52. <function>handle_sigs</function>) The function will be called
  53. immediately after the signal handler finish. The main process usually
  54. does some cleanup and running such things outside the signal handler is
  55. much more safe than doing it from the handler itself. Children only
  56. print statistics and exit or ignore the signal completely, that is
  57. quite safe and can be done directly from the signal handler of
  58. children.
  59. </para>
  60. <para>
  61. When <varname>dont_fork</varname> is set, all the cleanup will be done
  62. directly from the signal handler, because there is only one process -
  63. the main process. This is not so safe as the previous case, but this
  64. mode should be used for debugging only and such shortcoming doesn't
  65. harm in that case.
  66. </para>
  67. <para>
  68. Upon receipt of SIGINT, SIGPIPE or SIGTERM
  69. <function>destroy_modules</function> will be called. Each module may
  70. register so-called <function>destroy</function> function if it needs to
  71. do some cleanup when the server is terminating (flush of cache to disk
  72. for example). <function>destroy_modules</function> will call destroy
  73. function of all loaded modules.
  74. </para>
  75. <para>
  76. If you need to terminate the server and all of its children, the best
  77. way how to do it is to send SIGTERM to the main process, the main
  78. process will in turn send the same signal to its children.
  79. </para>
  80. <para>
  81. The main process and its children are in the same process
  82. group. Therefore the main process can kill all its children simply by
  83. sending a signal to pid 0, sending to pid 0 will send the signal to all
  84. processes in the same process group as the sending process. This is how
  85. the main process will terminate all children when it is going to shut
  86. down.
  87. </para>
  88. <para>
  89. If one child exited during normal operation, the whole server will be
  90. shut down. This is better than let the server continue - a dead child
  91. might hold a lock and that could block the whole server, such situation
  92. cannot be avoided easily. Instead of that it is better to shutdown the
  93. whole server and let it restart.
  94. </para>
  95. </section> <!-- server-shutdown -->