charon 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: charon
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: strongSwan charon IKE daemon
  9. # Description: with swanctl the strongSwan charon daemon must be
  10. # running in the background
  11. ### END INIT INFO
  12. # Author: Andreas Steffen <andreas.steffen@strongswa.org>
  13. #
  14. # Do NOT "set -e"
  15. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  16. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  17. DESC="strongSwan charon IKE daemon"
  18. NAME=charon
  19. DAEMON=/usr/local/libexec/ipsec/$NAME
  20. DAEMON_ARGS=""
  21. PIDFILE=/var/run/$NAME.pid
  22. SCRIPTNAME=/etc/init.d/charon
  23. # Exit if the package is not installed
  24. [ -x "$DAEMON" ] || exit 0
  25. # Read configuration variable file if it is present
  26. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  27. # Load the VERBOSE setting and other rcS variables
  28. . /lib/init/vars.sh
  29. # Define LSB log_* functions.
  30. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  31. # and status_of_proc is working.
  32. . /lib/lsb/init-functions
  33. #
  34. # Function that starts the daemon/service
  35. #
  36. do_start()
  37. {
  38. # Return
  39. # 0 if daemon has been started
  40. # 1 if daemon was already running
  41. # 2 if daemon could not be started
  42. start-stop-daemon --start --quiet --background --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  43. || return 1
  44. start-stop-daemon --start --quiet --background --pidfile $PIDFILE --exec $DAEMON -- \
  45. $DAEMON_ARGS \
  46. || return 2
  47. # Add code here, if necessary, that waits for the process to be ready
  48. # to handle requests from services started subsequently which depend
  49. # on this one. As a last resort, sleep for some time.
  50. }
  51. #
  52. # Function that stops the daemon/service
  53. #
  54. do_stop()
  55. {
  56. # Return
  57. # 0 if daemon has been stopped
  58. # 1 if daemon was already stopped
  59. # 2 if daemon could not be stopped
  60. # other if a failure occurred
  61. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  62. RETVAL="$?"
  63. [ "$RETVAL" = 2 ] && return 2
  64. # Wait for children to finish too if this is a daemon that forks
  65. # and if the daemon is only ever run from this initscript.
  66. # If the above conditions are not satisfied then add some other code
  67. # that waits for the process to drop all resources that could be
  68. # needed by services started subsequently. A last resort is to
  69. # sleep for some time.
  70. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  71. [ "$?" = 2 ] && return 2
  72. # Many daemons don't delete their pidfiles when they exit.
  73. rm -f $PIDFILE
  74. return "$RETVAL"
  75. }
  76. #
  77. # Function that sends a SIGHUP to the daemon/service
  78. #
  79. do_reload() {
  80. #
  81. # If the daemon can reload its configuration without
  82. # restarting (for example, when it is sent a SIGHUP),
  83. # then implement that here.
  84. #
  85. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  86. return 0
  87. }
  88. case "$1" in
  89. start)
  90. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  91. do_start
  92. case "$?" in
  93. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  94. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  95. esac
  96. ;;
  97. stop)
  98. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  99. do_stop
  100. case "$?" in
  101. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  102. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  103. esac
  104. ;;
  105. status)
  106. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  107. ;;
  108. #reload|force-reload)
  109. #
  110. # If do_reload() is not implemented then leave this commented out
  111. # and leave 'force-reload' as an alias for 'restart'.
  112. #
  113. #log_daemon_msg "Reloading $DESC" "$NAME"
  114. #do_reload
  115. #log_end_msg $?
  116. #;;
  117. restart|force-reload)
  118. #
  119. # If the "reload" option is implemented then remove the
  120. # 'force-reload' alias
  121. #
  122. log_daemon_msg "Restarting $DESC" "$NAME"
  123. do_stop
  124. case "$?" in
  125. 0|1)
  126. do_start
  127. case "$?" in
  128. 0) log_end_msg 0 ;;
  129. 1) log_end_msg 1 ;; # Old process is still running
  130. *) log_end_msg 1 ;; # Failed to start
  131. esac
  132. ;;
  133. *)
  134. # Failed to stop
  135. log_end_msg 1
  136. ;;
  137. esac
  138. ;;
  139. *)
  140. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  141. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  142. exit 3
  143. ;;
  144. esac
  145. :