You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

160 lines
4.2 KiB

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