ax_nagios_get_init 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. AC_SUBST(init_type)
  56. #
  57. # Get user hints for possible cross-compile
  58. #
  59. AC_MSG_CHECKING(what init system is being used )
  60. AC_ARG_WITH(init_type,AC_HELP_STRING([--with-init-type=type],
  61. [specify init type (bsd, sysv, systemd, launchd, smf10, smf11, upstart,
  62. openrc, etc.)]),
  63. [
  64. #
  65. # Run this if --with was specified
  66. #
  67. if test "x$withval" = x -o x$withval = xno; then
  68. init_type_wanted=yes
  69. else
  70. init_type_wanted=no
  71. init_type="$withval"
  72. AC_MSG_RESULT($init_type)
  73. fi
  74. ], [
  75. #
  76. # Run this if --with was not specified
  77. #
  78. init_type_wanted=yes
  79. ])
  80. if test x$init_type = xno; then
  81. init_type_wanted=yes
  82. elif test x$init_type = xyes; then
  83. AC_MSG_ERROR([you must enter an init type if '--with-init-type' is specified])
  84. fi
  85. #
  86. # Determine init type if it wasn't supplied
  87. #
  88. if test $init_type_wanted = yes; then
  89. init_type=""
  90. if test x"$opsys" = x; then
  91. init_type="unknown"
  92. init_type_wanted=no
  93. elif test x"$dist_type" = x; then
  94. init_type="unknown"
  95. init_type_wanted=no
  96. elif test "$opsys" = "osx"; then
  97. init_type="launchd"
  98. init_type_wanted=no
  99. elif test "$opsys" = "bsd"; then
  100. init_type="newbsd"
  101. init_type_wanted=no
  102. elif test "$dist_type" = "solaris"; then
  103. if test -d "/lib/svc/manifest"; then
  104. init_type="smf11"
  105. init_type_wanted=no
  106. elif test -d "/lib/svc/monitor"; then
  107. init_type="smf10"
  108. init_type_wanted=no
  109. else
  110. init_type="sysv"
  111. init_type_wanted=no
  112. fi
  113. elif test "$dist_type" = "slackware"; then
  114. init_type="bsd"
  115. init_type_wanted=no
  116. elif test "$dist_type" = "aix"; then
  117. init_type="bsd"
  118. init_type_wanted=no
  119. elif test "$dist_type" = "hp-ux"; then
  120. init_type="unknown"
  121. init_type_wanted=no
  122. fi
  123. fi
  124. PSCMD="ps -p1 -o args"
  125. if test $dist_type = solaris; then
  126. PSCMD="env UNIX95=1; ps -p1 -o args"
  127. fi
  128. if test "$init_type_wanted" = yes; then
  129. pid1=`$PSCMD | grep -vi COMMAND | cut -d' ' -f1`
  130. if test x"$pid1" = "x"; then
  131. init_type="unknown"
  132. init_type_wanted=no
  133. fi
  134. if `echo $pid1 | grep "systemd" > /dev/null`; then
  135. init_type="systemd"
  136. init_type_wanted=no
  137. fi
  138. if test "$init_type_wanted" = yes; then
  139. if test "$pid1" = "init"; then
  140. if test -e "/sbin/init"; then
  141. pid1="/sbin/init";
  142. elif test -e "/usr/sbin/init"; then
  143. pid1="/usr/sbin/init"
  144. else
  145. init_type="unknown"
  146. init_type_wanted=no
  147. fi
  148. fi
  149. if test -L "$pid1"; then
  150. pid1=`readlink "$pid1"`
  151. fi
  152. fi
  153. if test "$init_type_wanted" = yes; then
  154. if `echo $pid1 | grep "systemd" > /dev/null`; then
  155. init_type="systemd"
  156. init_type_wanted=no
  157. elif test -f "/sbin/rc"; then
  158. if test -f /sbin/runscript; then
  159. init_type_wanted=no
  160. if `/sbin/start-stop-daemon -V | grep "OpenRC" > /dev/null`; then
  161. init_type="openrc"
  162. else
  163. init_type="gentoo"
  164. fi
  165. fi
  166. fi
  167. fi
  168. if test "$init_type_wanted" = yes; then
  169. if test "$pid1" = "/sbin/init" -o "$pid1" = "/usr/sbin/init"; then
  170. if `$pid1 --version 2>/dev/null | grep "upstart" >/dev/null`; then
  171. init_type="upstart"
  172. init_type_wanted=no
  173. elif test -f "/etc/rc" -a ! -L "/etc/rc"; then
  174. init_type="newbsd"
  175. init_type_wanted=no
  176. else
  177. init_type="sysv"
  178. init_type_wanted=no
  179. fi
  180. fi
  181. fi
  182. if test "$init_type_wanted" = yes; then
  183. init_type="unknown"
  184. fi
  185. fi
  186. AC_MSG_RESULT($init_type)
  187. ])