Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

snf-server.ubuntu 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #! /bin/sh
  2. #
  3. # snfServer. This shell script takes care of starting and stopping
  4. # the ARM Research SNFServer daemon for Ubuntu systems.
  5. #
  6. # Author: Alban Deniz
  7. #
  8. # Copyright (C) 2008 ARM Research Labs, LLC.
  9. # See www.armresearch.com for the copyright terms.
  10. #
  11. ### BEGIN INIT INFO
  12. # Provides: SNFServer
  13. # Required-Start: $syslog $remote_fs $network $named
  14. # Should-Start: $time ypbind smtp
  15. # Required-Stop: $syslog $remote_fs
  16. # Should-Stop: $time ypbind smtp
  17. # Default-Start: 3 4 5
  18. # Default-Stop: 0 1 2 6
  19. # Short-Description: SNFServer providing email filtering.
  20. # Description: Start SNFServer to filter email for spam,
  21. # blacklist IP addresses, etc.
  22. ### END INIT INFO
  23. # Location of installation.
  24. installedDir="PREFIX"
  25. # Location of programs.
  26. dir="$installedDir/sbin"
  27. # Name of config file.
  28. configFile="CONFFILE"
  29. # Name of daemon.
  30. prog="SNFServer"
  31. # Name of client.
  32. clientProg="SNFClient"
  33. # Name of user to run as.
  34. userName="snfilter"
  35. # Name of lockfile.
  36. lockFile="/var/lock/subsys/$prog"
  37. # Name of client.
  38. clientProg="SNFClient"
  39. # Start command.
  40. snfStartCmd="$dir/$prog $configFile > /dev/null 2>&1 &"
  41. # Do NOT "set -e"
  42. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  43. PATH=/usr/sbin:/usr/bin:/sbin:/bin
  44. DESC="SNFServer providing email filtering"
  45. NAME="snfServer"
  46. DAEMON=$dir/$prog
  47. DAEMON_ARGS="$configFile"
  48. SCRIPTNAME=/etc/init.d/$NAME
  49. # Exit if the package is not installed
  50. [ -x "$DAEMON" ] || exit 0
  51. # Read configuration variable file if it is present
  52. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  53. # Load the VERBOSE setting and other rcS variables
  54. [ -f /etc/default/rcS ] && . /etc/default/rcS
  55. # Define LSB log_* functions.
  56. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  57. . /lib/lsb/init-functions
  58. #
  59. # Function that starts the daemon/service
  60. #
  61. do_start()
  62. {
  63. # Return
  64. # 0 if daemon has been started
  65. # 1 if daemon was already running
  66. # 2 if daemon could not be started
  67. start-stop-daemon --chuid $userName --start --quiet \
  68. --exec $DAEMON --test > /dev/null 2>&1 \
  69. || return 1
  70. start-stop-daemon --chuid $userName --start --quiet \
  71. --background --exec $DAEMON -- $DAEMON_ARGS > /dev/null 2>&1 \
  72. || return 2
  73. # Check that process started.
  74. $dir/$clientProg -status.second > /dev/null 2>&1
  75. RETVAL=$?
  76. if [ $RETVAL -ne 0 ]; then
  77. RETVAL=2
  78. fi
  79. return $RETVAL
  80. }
  81. #
  82. # Function that stops the daemon/service
  83. #
  84. do_stop()
  85. {
  86. # Return
  87. # 0 if daemon has been stopped
  88. # 1 if daemon was already stopped
  89. # 2 if daemon could not be stopped
  90. # other if a failure occurred
  91. # Check whether SNFServer is running.
  92. start-stop-daemon --chuid $userName --start --quiet \
  93. --exec $DAEMON --test > /dev/null
  94. RETVAL=$?
  95. if [ $RETVAL -ne 1 ]; then
  96. return 1
  97. fi
  98. # Issue shutdown command
  99. $dir/$clientProg -shutdown > /dev/null 2>&1
  100. sleep 10
  101. # Check again whether SNFServer is running.
  102. start-stop-daemon --chuid $userName --start --quiet \
  103. --exec $DAEMON --test > /dev/null
  104. RETVAL=$?
  105. if [ $RETVAL -eq 1 ] ; then
  106. # Send TERM signal to stop SNFServer.
  107. start-stop-daemon --stop --quiet --retry=TERM/5 --exec $DAEMON
  108. RETVAL="$?"
  109. [ "$RETVAL" = 2 ] && return 2
  110. return "$RETVAL"
  111. fi
  112. # SNFServer isn't running.
  113. return 0
  114. }
  115. case "$1" in
  116. start)
  117. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  118. do_start
  119. case "$?" in
  120. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  121. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  122. esac
  123. ;;
  124. stop)
  125. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  126. do_stop
  127. case "$?" in
  128. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  129. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  130. esac
  131. ;;
  132. status)
  133. start-stop-daemon --chuid $userName --start --quiet \
  134. --exec $DAEMON --test > /dev/null
  135. RETVAL=$?
  136. if [ $RETVAL -eq 0 ]; then
  137. # Stopped
  138. echo "$prog is stopped"
  139. else
  140. # Running
  141. echo "$prog (pid $(pidof $dir/$prog)) is running"
  142. fi
  143. ;;
  144. restart|force-reload)
  145. #
  146. # If the "reload" option is implemented then remove the
  147. # 'force-reload' alias
  148. #
  149. log_daemon_msg "Restarting $DESC" "$NAME"
  150. do_stop
  151. case "$?" in
  152. 0|1)
  153. do_start
  154. case "$?" in
  155. 0) log_end_msg 0 ;;
  156. 1) log_end_msg 1 ;; # Old process is still running
  157. *) log_end_msg 1 ;; # Failed to start
  158. esac
  159. ;;
  160. *)
  161. # Failed to stop
  162. log_end_msg 1
  163. ;;
  164. esac
  165. ;;
  166. *)
  167. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  168. exit 3
  169. ;;
  170. esac