ax_nagios_get_init 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. # ===========================================================================
  2. # SYNOPSIS
  3. #
  4. # AX_NAGIOS_GET_INIT
  5. #
  6. # DESCRIPTION
  7. #
  8. # This macro determines the O/S distribution of the computer it is run on.
  9. # $init_type will be set and will be one of:
  10. # unknown (could not be determined)
  11. # launchd (Mac OS X)
  12. # bsd (Slackware Linux)
  13. # newbsd (FreeBSD, OpenBSD, NetBSD, Dragonfly, etc)
  14. # smf10 (Solaris)
  15. # smf11 (Solaris)
  16. # systemd (Linux SystemD)
  17. # gentoo (Older Gentoo)
  18. # openrc (Recent Gentoo and some others)
  19. # upstart (Older Debian)
  20. # sysv (The rest)
  21. #
  22. # LICENSE
  23. #
  24. # Copyright (c) 2016 Nagios Core Development Team
  25. #
  26. # This program is free software; you can redistribute it and/or modify it
  27. # under the terms of the GNU General Public License as published by the
  28. # Free Software Foundation; either version 2 of the License, or (at your
  29. # option) any later version.
  30. #
  31. # This program is distributed in the hope that it will be useful, but
  32. # WITHOUT ANY WARRANTY; without even the implied warranty of
  33. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  34. # Public License for more details.
  35. #
  36. # You should have received a copy of the GNU General Public License along
  37. # with this program. If not, see <http://www.gnu.org/licenses/>.
  38. #
  39. # As a special exception, the respective Autoconf Macro's copyright owner
  40. # gives unlimited permission to copy, distribute and modify the configure
  41. # scripts that are the output of Autoconf when processing the Macro. You
  42. # need not follow the terms of the GNU General Public License when using
  43. # or distributing such scripts, even though portions of the text of the
  44. # Macro appear in them. The GNU General Public License (GPL) does govern
  45. # all other use of the material that constitutes the Autoconf Macro.
  46. #
  47. # This special exception to the GPL applies to versions of the Autoconf
  48. # Macro released by the Autoconf Archive. When you make and distribute a
  49. # modified version of the Autoconf Macro, you may extend this special
  50. # exception to the GPL to apply to your modified version as well.
  51. # ===========================================================================
  52. AU_ALIAS([AC_NAGIOS_GET_INIT], [AX_NAGIOS_GET_INIT])
  53. AC_DEFUN([AX_NAGIOS_GET_INIT],
  54. [
  55. #
  56. # Get user hints for possible cross-compile
  57. #
  58. AC_MSG_CHECKING(what init system is being used )
  59. AC_ARG_WITH(init_type,AC_HELP_STRING([--with-init-type=type],
  60. [specify init type (bsd, sysv, systemd, launchd, smf10, smf11, upstart,
  61. openrc, etc.)]),
  62. [
  63. #
  64. # Run this if --with was specified
  65. #
  66. if test "x$withval" = x -o x$withval = xno; then
  67. init_type_wanted=yes
  68. else
  69. init_type_wanted=no
  70. init_type="$withval"
  71. AC_MSG_RESULT($init_type)
  72. fi
  73. ], [
  74. #
  75. # Run this if --with was not specified
  76. #
  77. init_type_wanted=yes
  78. ])
  79. if test x$init_type = xno; then
  80. init_type_wanted=yes
  81. elif test x$init_type = xyes; then
  82. AC_MSG_ERROR([you must enter an init type if '--with-init-type' is specified])
  83. fi
  84. #
  85. # Determine init type if it wasn't supplied
  86. #
  87. if test $init_type_wanted = yes; then
  88. init_type=""
  89. if test x"$opsys" = x; then
  90. init_type="unknown"
  91. init_type_wanted=no
  92. elif test x"$dist_type" = x; then
  93. init_type="unknown"
  94. init_type_wanted=no
  95. elif test "$opsys" = "osx"; then
  96. init_type="launchd"
  97. init_type_wanted=no
  98. elif test "$opsys" = "bsd"; then
  99. init_type="newbsd"
  100. init_type_wanted=no
  101. elif test "$dist_type" = "solaris"; then
  102. if test -d "/lib/svc/manifest"; then
  103. init_type="smf11"
  104. init_type_wanted=no
  105. elif test -d "/lib/svc/monitor"; then
  106. init_type="smf10"
  107. init_type_wanted=no
  108. else
  109. init_type="sysv"
  110. init_type_wanted=no
  111. fi
  112. elif test "$dist_type" = "slackware"; then
  113. init_type="bsd"
  114. init_type_wanted=no
  115. fi
  116. fi
  117. PSCMD="ps -p1 -o args"
  118. AS_CASE([$dist_type],
  119. [aix], PSCMD="env UNIX95=1; ps -p1 -o args",
  120. [solaris], PSCMD="env UNIX95=1; ps -p1 -o args",
  121. [hp-ux], PSCMD="env UNIX95=1; ps -p1 -o args")
  122. if test "$init_type_wanted" = yes; then
  123. pid1=`$PSCMD | grep -vi COMMAND | cut -d' ' -f1`
  124. if test x"$pid1" = "x"; then
  125. init_type="unknown"
  126. init_type_wanted=no
  127. fi
  128. if `echo $pid1 | grep "systemd" > /dev/null`; then
  129. init_type="systemd"
  130. init_type_wanted=no
  131. fi
  132. if test "$init_type_wanted" = yes; then
  133. if test "$pid1" = "init"; then
  134. if test -e "/sbin/init"; then
  135. pid1="/sbin/init";
  136. elif test -e "/usr/sbin/init"; then
  137. pid1="/usr/sbin/init"
  138. else
  139. init_type="unknown"
  140. init_type_wanted=no
  141. fi
  142. fi
  143. if test -L "$pid1"; then
  144. pid1=`readlink "$pid1"`
  145. fi
  146. fi
  147. if test "$init_type_wanted" = yes; then
  148. if `echo $pid1 | grep "systemd" > /dev/null`; then
  149. init_type="systemd"
  150. init_type_wanted=no
  151. elif test -f "/sbin/rc"; then
  152. if test -f /sbin/runscript; then
  153. init_type_wanted=no
  154. if `/sbin/start-stop-daemon -V | grep "OpenRC" > /dev/null`; then
  155. init_type="openrc"
  156. else
  157. init_type="gentoo"
  158. fi
  159. fi
  160. fi
  161. fi
  162. if test "$init_type_wanted" = yes; then
  163. if test "$pid1" = "/sbin/init" -o "$pid1" = "/usr/sbin/init"; then
  164. if `/sbin/init --version 2>/dev/null | grep "upstart" >/dev/null`; then
  165. init_type="upstart"
  166. init_type_wanted=no
  167. elif test -f "/etc/rc" -a ! -L "/etc/rc"; then
  168. init_type="newbsd"
  169. init_type_wanted=no
  170. else
  171. init_type="sysv"
  172. init_type_wanted=no
  173. fi
  174. fi
  175. fi
  176. if test "$init_type_wanted" = yes; then
  177. init_type="unknown"
  178. fi
  179. fi
  180. AC_MSG_RESULT($init_type)
  181. ])