Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #!/bin/bash
  2. #
  3. # SNFServer This shell script takes care of starting and stopping
  4. # the MicroNeil SNFServer daemon for SUSE 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. # chkconfig: 345 80 30
  12. # description: SNFServer providing email filtering.
  13. #
  14. ### BEGIN INIT INFO
  15. # Provides: SNFServer
  16. # Required-Start: $syslog $remote_fs $network $named
  17. # Should-Start: $time ypbind smtp
  18. # Required-Stop: $syslog $remote_fs
  19. # Should-Stop: $time ypbind smtp
  20. # Default-Start: 3 4 5
  21. # Default-Stop: 0 1 2 6
  22. # Short-Description: SNFServer providing email filtering.
  23. # Description: Start SNFServer to filter email for spam,
  24. # blacklist IP addresses, etc.
  25. ### END INIT INFO
  26. # Location of programs.
  27. installedDir="PREFIX"
  28. # Location of programs.
  29. dir="$installedDir/sbin"
  30. # Name of config file.
  31. configFile="CONFFILE"
  32. # Name of daemon.
  33. prog="SNFServer"
  34. # Name of client.
  35. clientProg="SNFClient"
  36. # Name of user to run as.
  37. userName="snfilter"
  38. # Name of lockfile.
  39. lockFile="/var/lock/subsys/$prog"
  40. # Start command.
  41. snfStartCmd="$dir/$prog $configFile > /dev/null 2>&1 &"
  42. # Check for missing binaries (stale symlinks should not happen)
  43. # Note: Special treatment of stop for LSB conformance
  44. SNFServer_BIN=$dir/$prog
  45. test -x $SNFServer_BIN || { echo "$SNFServer_BIN not installed";
  46. if [ "$1" = "stop" ]; then exit 0;
  47. else exit 5; fi; }
  48. # Use the SUSE rc_ init script functions;
  49. # emulate them on LSB, RH and other systems
  50. # Default: Assume sysvinit binaries exist
  51. start_daemon() { /sbin/start_daemon ${1+"$@"}; }
  52. killproc() { /sbin/killproc ${1+"$@"}; }
  53. pidofproc() { /sbin/pidofproc ${1+"$@"}; }
  54. checkproc() { /sbin/checkproc ${1+"$@"}; }
  55. if test -e /etc/rc.status; then
  56. # SUSE rc script library
  57. . /etc/rc.status
  58. else
  59. export LC_ALL=POSIX
  60. _cmd=$1
  61. declare -a _SMSG
  62. if test "${_cmd}" = "status"; then
  63. _SMSG=(running dead dead unused unknown reserved)
  64. _RC_UNUSED=3
  65. else
  66. _SMSG=(done failed failed missed failed skipped unused failed failed reserved)
  67. _RC_UNUSED=6
  68. fi
  69. if test -e /lib/lsb/init-functions; then
  70. # LSB
  71. . /lib/lsb/init-functions
  72. echo_rc()
  73. {
  74. if test ${_RC_RV} = 0; then
  75. log_success_msg " [${_SMSG[${_RC_RV}]}] "
  76. else
  77. log_failure_msg " [${_SMSG[${_RC_RV}]}] "
  78. fi
  79. }
  80. # TODO: Add checking for lockfiles
  81. checkproc() { return pidofproc ${1+"$@"} >/dev/null 2>&1; }
  82. elif test -e /etc/init.d/functions; then
  83. # RHAT
  84. . /etc/init.d/functions
  85. echo_rc()
  86. {
  87. #echo -n " [${_SMSG[${_RC_RV}]}] "
  88. if test ${_RC_RV} = 0; then
  89. success " [${_SMSG[${_RC_RV}]}] "
  90. else
  91. failure " [${_SMSG[${_RC_RV}]}] "
  92. fi
  93. }
  94. checkproc() { return status ${1+"$@"}; }
  95. start_daemon() { return daemon ${1+"$@"}; }
  96. else
  97. # emulate it
  98. echo_rc() { echo " [${_SMSG[${_RC_RV}]}] "; }
  99. fi
  100. rc_reset() { _RC_RV=0; }
  101. rc_failed()
  102. {
  103. if test -z "$1"; then
  104. _RC_RV=1;
  105. elif test "$1" != "0"; then
  106. _RC_RV=$1;
  107. fi
  108. return ${_RC_RV}
  109. }
  110. rc_check()
  111. {
  112. return rc_failed $?
  113. }
  114. rc_status()
  115. {
  116. rc_failed $?
  117. if test "$1" = "-r"; then _RC_RV=0; shift; fi
  118. if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
  119. if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
  120. if test "$1" = "-v"; then echo_rc; shift; fi
  121. if test "$1" = "-r"; then _RC_RV=0; shift; fi
  122. return ${_RC_RV}
  123. }
  124. rc_exit() { exit ${_RC_RV}; }
  125. rc_active()
  126. {
  127. if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
  128. if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
  129. return 1
  130. }
  131. fi
  132. # Reset status of this service
  133. rc_reset
  134. # Return values acc. to LSB for all commands but status:
  135. # 0 - success
  136. # 1 - generic or unspecified error
  137. # 2 - invalid or excess argument(s)
  138. # 3 - unimplemented feature (e.g. "reload")
  139. # 4 - user had insufficient privileges
  140. # 5 - program is not installed
  141. # 6 - program is not configured
  142. # 7 - program is not running
  143. # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
  144. #
  145. # Note that starting an already running service, stopping
  146. # or restarting a not-running service as well as the restart
  147. # with force-reload (in case signaling is not supported) are
  148. # considered a success.
  149. start(){
  150. SNFPID=$(pidof -s $dir/$prog)
  151. echo -n $"Starting $prog "
  152. if [ -n "$SNFPID" ] ; then
  153. return 0
  154. else
  155. su $userName -c "$snfStartCmd" -s /bin/sh
  156. RETVAL=$?
  157. if [ $RETVAL -eq 0 ]; then
  158. $dir/$clientProg -status.second > /dev/null 2>&1
  159. RETVAL=$?
  160. fi
  161. fi
  162. if [ $RETVAL -eq 0 ]; then
  163. touch $lockFile
  164. else
  165. rc_failed 1
  166. fi
  167. return $RETVAL
  168. }
  169. stop(){
  170. echo -n $"Stopping $prog "
  171. SNFPID=$(pidof -s $dir/$prog)
  172. if [ -n "$SNFPID" ]; then
  173. $dir/$clientProg -shutdown > /dev/null 2>&1
  174. sleep 10
  175. SNFPID=$(pidof -s $dir/$prog)
  176. if [ -n "$SNFPID" ]; then
  177. kill $SNFPID
  178. RETVAL=$?
  179. else
  180. RETVAL=0
  181. fi
  182. else
  183. # Process is not running.
  184. RETVAL=0
  185. fi
  186. if [ $RETVAL -eq 0 ]; then
  187. rm -f $lockFile
  188. else
  189. rc_failed 1
  190. fi
  191. return $RETVAL
  192. }
  193. restart(){
  194. stop
  195. start
  196. }
  197. case "$1" in
  198. start)
  199. start
  200. # Remember status and be verbose
  201. rc_status -v
  202. ;;
  203. stop)
  204. stop
  205. # Remember status and be verbose
  206. rc_status -v
  207. ;;
  208. restart)
  209. ## Stop the service and regardless of whether it was
  210. ## running or not, start it again.
  211. $0 stop
  212. $0 start
  213. # Remember status and be quiet
  214. rc_status
  215. ;;
  216. status)
  217. echo -n "Checking for service SNFServer "
  218. checkproc $SNFServer_BIN
  219. rc_status -v
  220. ;;
  221. try-restart|condrestart|force-reload|reload|probe)
  222. # Not supported.
  223. echo -n "$0 $1 "
  224. rc_failed 3
  225. rc_status -v
  226. ;;
  227. *)
  228. echo "Usage: $0 {start|stop|status|restart}"
  229. exit 1
  230. ;;
  231. esac
  232. rc_exit