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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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
  10. ### END INIT INFO
  11. # Author: Vsevolod Stakhov <vsevolod@rspamd.com>
  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. RSPAMADM=/usr/bin/rspamadm
  18. DAEMON_ARGS="-c /etc/rspamd/rspamd.conf"
  19. DESC="rapid spam filtering system"
  20. PIDFILE=/run/rspamd/$NAME.pid
  21. SCRIPTNAME=/etc/init.d/$NAME
  22. # Exit if the package is not installed
  23. [ -x "$DAEMON" ] || exit 0
  24. # Load the VERBOSE setting and other rcS variables
  25. . /lib/init/vars.sh
  26. # Define LSB log_* functions.
  27. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  28. . /lib/lsb/init-functions
  29. #
  30. # Function that starts the daemon/service
  31. #
  32. do_start()
  33. {
  34. # Return
  35. # 0 if daemon has been started
  36. # 1 if daemon was already running
  37. # 2 if daemon could not be started
  38. mkdir -m 755 -p /run/rspamd
  39. chown _rspamd:_rspamd /run/rspamd
  40. $RSPAMADM configtest $DAEMON_ARGS > /dev/null \
  41. || return 1
  42. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  43. $DAEMON_ARGS -u _rspamd -g _rspamd \
  44. || return 2
  45. }
  46. #
  47. # Function that stops the daemon/service
  48. #
  49. do_stop()
  50. {
  51. # Return
  52. # 0 if daemon has been stopped
  53. # 1 if daemon was already stopped
  54. # 2 if daemon could not be stopped
  55. # other if a failure occurred
  56. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
  57. RETVAL="$?"
  58. [ "$RETVAL" = 2 ] && return 2
  59. # Many daemons don't delete their pidfiles when they exit.
  60. rm -f $PIDFILE
  61. return "$RETVAL"
  62. }
  63. #
  64. # Function that sends a SIGHUP to the daemon/service
  65. #
  66. do_reload() {
  67. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
  68. return 0
  69. }
  70. #
  71. # Function that sends a SIGUSR1 to the daemon/service
  72. #
  73. do_reopenlog() {
  74. start-stop-daemon --stop --signal 10 --quiet --pidfile $PIDFILE
  75. return 0
  76. }
  77. case "$1" in
  78. start)
  79. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  80. do_start
  81. case "$?" in
  82. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  83. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  84. esac
  85. ;;
  86. stop)
  87. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  88. do_stop
  89. case "$?" in
  90. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  91. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  92. esac
  93. ;;
  94. status)
  95. status_of_proc -p $PIDFILE "$DAEMON" "$NAME" || exit $?
  96. ;;
  97. reload|force-reload)
  98. log_daemon_msg "Reloading $DESC" "$NAME"
  99. do_reload
  100. log_end_msg $?
  101. ;;
  102. reopenlog)
  103. log_daemon_msg "Reopen logs for $DESC" "$NAME"
  104. do_reopenlog
  105. log_end_msg $?
  106. ;;
  107. restart)
  108. log_daemon_msg "Restarting $DESC" "$NAME"
  109. do_stop
  110. case "$?" in
  111. 0|1)
  112. do_start
  113. case "$?" in
  114. 0) log_end_msg 0 ;;
  115. 1) log_end_msg 1 ;; # Old process is still running
  116. *) log_end_msg 1 ;; # Failed to start
  117. esac
  118. ;;
  119. *)
  120. # Failed to stop
  121. log_end_msg 1
  122. ;;
  123. esac
  124. ;;
  125. *)
  126. echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|reopenlog}" >&2
  127. exit 3
  128. ;;
  129. esac
  130. exit 0