isc-dhcp6-server.init.j2 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/sh
  2. #
  3. #
  4. ### BEGIN INIT INFO
  5. # Provides: isc-dhcp6-server
  6. # Required-Start: $remote_fs $network $syslog
  7. # Required-Stop: $remote_fs $network $syslog
  8. # Should-Start: $local_fs slapd $named
  9. # Should-Stop: $local_fs slapd
  10. # Default-Start: 2 3 4 5
  11. # Default-Stop: 0 1 6
  12. # Short-Description: DHCP6 server
  13. # Description: Dynamic Host Configuration Protocol Server V6
  14. ### END INIT INFO
  15. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  16. test -f /usr/sbin/dhcpd || exit 0
  17. DHCPD_DEFAULT="${DHCPD_DEFAULT:-/etc/default/isc-dhcp6-server}"
  18. # It is not safe to start if we don't have a default configuration...
  19. if [ ! -f "$DHCPD_DEFAULT" ]; then
  20. echo "$DHCPD_DEFAULT does not exist! - Aborting..."
  21. if [ "$DHCPD_DEFAULT" = "/etc/default/isc-dhcp6-server" ]; then
  22. echo "Run 'dpkg-reconfigure isc-dhcp-server' to fix the problem."
  23. fi
  24. exit 0
  25. fi
  26. . /lib/lsb/init-functions
  27. # Read init script configuration
  28. [ -f "$DHCPD_DEFAULT" ] && . "$DHCPD_DEFAULT"
  29. NAME=dhcpd
  30. DESC="ISC DHCP6 server"
  31. # fallback to default config file
  32. DHCPD_CONF=${DHCPD_CONF:-/etc/dhcp/dhcpd6.conf}
  33. # try to read pid file name from config file, with fallback to /var/run/dhcpd.pid
  34. if [ -z "$DHCPD_PID" ]; then
  35. DHCPD_PID=$(sed -n -e 's/^[ \t]*pid-file-name[ \t]*"(.*)"[ \t]*;.*$/\1/p' < "$DHCPD_CONF" 2>/dev/null | head -n 1)
  36. fi
  37. DHCPD_PID="${DHCPD_PID:-/var/run/dhcpd6.pid}"
  38. test_config()
  39. {
  40. if ! /usr/sbin/dhcpd -6 -t $OPTIONS -q -cf "$DHCPD_CONF" > /dev/null 2>&1; then
  41. echo "dhcpd self-test failed. Please fix $DHCPD_CONF."
  42. echo "The error was: "
  43. /usr/sbin/dhcpd -6 -t $OPTIONS -cf "$DHCPD_CONF"
  44. exit 1
  45. fi
  46. }
  47. # single arg is -v for messages, -q for none
  48. check_status()
  49. {
  50. if [ ! -r "$DHCPD_PID" ]; then
  51. test "$1" != -v || echo "$NAME is not running."
  52. return 3
  53. fi
  54. if read pid < "$DHCPD_PID" && ps -p "$pid" > /dev/null 2>&1; then
  55. test "$1" != -v || echo "$NAME is running."
  56. return 0
  57. else
  58. test "$1" != -v || echo "$NAME is not running but $DHCPD_PID exists."
  59. return 1
  60. fi
  61. }
  62. case "$1" in
  63. start)
  64. test_config
  65. log_daemon_msg "Starting $DESC" "$NAME"
  66. start-stop-daemon --start --quiet --pidfile "$DHCPD_PID" \
  67. --exec /usr/sbin/dhcpd -- \
  68. -6 -q $OPTIONS -cf "$DHCPD_CONF" -pf "$DHCPD_PID" $INTERFACES
  69. sleep 2
  70. if check_status -q; then
  71. log_end_msg 0
  72. else
  73. log_failure_msg "check syslog for diagnostics."
  74. log_end_msg 1
  75. exit 1
  76. fi
  77. ;;
  78. stop)
  79. log_daemon_msg "Stopping $DESC" "$NAME"
  80. start-stop-daemon --stop --quiet --pidfile "$DHCPD_PID"
  81. log_end_msg $?
  82. rm -f "$DHCPD_PID"
  83. ;;
  84. restart | force-reload)
  85. test_config
  86. $0 stop
  87. sleep 2
  88. $0 start
  89. if [ "$?" != "0" ]; then
  90. exit 1
  91. fi
  92. ;;
  93. status)
  94. echo -n "Status of $DESC: "
  95. check_status -v
  96. exit "$?"
  97. ;;
  98. *)
  99. echo "Usage: $0 {start|stop|restart|force-reload|status}"
  100. exit 1
  101. esac
  102. exit 0