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.

rspamd.init 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #! /bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: rspamd
  4. # Required-Start: $syslog $remote_fs
  5. # Required-Stop: $syslog $remote_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Rspamd spam filtering system
  9. # Description: Rspamd is fast and modular spam filtering system written in C
  10. ### END INIT INFO
  11. # Author: Vsevolod Stakhov <vsevolod@highsecure.ru>
  12. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  13. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  14. DESC="Rspamd"
  15. NAME=rspamd
  16. DAEMON=/usr/bin/$NAME
  17. DAEMON_ARGS="-c /etc/rspamd.conf"
  18. DESC="rapid spam filtering system"
  19. PIDFILE=/var/lib/rspamd/$NAME.pid
  20. SCRIPTNAME=/etc/init.d/$NAME
  21. RSPAMD_USERNAME=rspamd
  22. RSPAMD_GROUPNAME=rspamd
  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.0-6) to ensure that this file is present.
  31. . /lib/lsb/init-functions
  32. FILES=(/etc/default/rspamd_*.conf)
  33. # check for alternative config schema
  34. if [ -r "${FILES[0]}" ]; then
  35. CONFIGS=(/etc/default/rspamd_*.conf)
  36. else
  37. CONFIGS=(/etc/default/$NAME)
  38. fi;
  39. CONFIG_NUM=${#CONFIGS[@]}
  40. #
  41. # Function that starts the daemon/service
  42. #
  43. do_start()
  44. {
  45. # Return
  46. # 0 if daemon has been started
  47. # 1 if daemon was already running
  48. # 2 if daemon could not be started
  49. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  50. || return 1
  51. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  52. $DAEMON_ARGS -u $RSPAMD_USERNAME -g $RSPAMD_GROUPNAME \
  53. || return 2
  54. }
  55. #
  56. # Function that stops the daemon/service
  57. #
  58. do_stop()
  59. {
  60. # Return
  61. # 0 if daemon has been stopped
  62. # 1 if daemon was already stopped
  63. # 2 if daemon could not be stopped
  64. # other if a failure occurred
  65. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
  66. RETVAL="$?"
  67. [ "$RETVAL" = 2 ] && return 2
  68. # Many daemons don't delete their pidfiles when they exit.
  69. rm -f $PIDFILE
  70. return "$RETVAL"
  71. }
  72. #
  73. # Function that sends a SIGHUP to the daemon/service
  74. #
  75. do_reload() {
  76. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
  77. return 0
  78. }
  79. #
  80. # Function that sends a SIGUSR1 to the daemon/service
  81. #
  82. do_reopenlog() {
  83. start-stop-daemon --stop --signal 10 --quiet --pidfile $PIDFILE
  84. return 0
  85. }
  86. _retcode=0
  87. for ((i=0; i < $CONFIG_NUM; i++)); do
  88. SCRIPT=${CONFIGS[${i}]}
  89. . ${SCRIPT}
  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 -p $PIDFILE "$DAEMON" "$NAME" || _retcode=$?
  109. ;;
  110. reload|force-reload)
  111. log_daemon_msg "Reloading $DESC" "$NAME"
  112. do_reload
  113. log_end_msg $?
  114. ;;
  115. reopenlog)
  116. log_daemon_msg "Reopen logs for $DESC" "$NAME"
  117. do_reopenlog
  118. log_end_msg $?
  119. ;;
  120. restart)
  121. log_daemon_msg "Restarting $DESC" "$NAME"
  122. do_stop
  123. case "$?" in
  124. 0|1)
  125. do_start
  126. case "$?" in
  127. 0) log_end_msg 0 ;;
  128. 1) log_end_msg 1 ;; # Old process is still running
  129. *) log_end_msg 1 ;; # Failed to start
  130. esac
  131. ;;
  132. *)
  133. # Failed to stop
  134. log_end_msg 1
  135. ;;
  136. esac
  137. ;;
  138. *)
  139. echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|reopenlog}" >&2
  140. exit 3
  141. ;;
  142. esac
  143. done
  144. exit $_retcode
  145. :