Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

snf-server.suse 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. #!/bin/bash
  2. #
  3. # snf-server Starts and stops the SNFServer daemon (SUSE).
  4. #
  5. # Author-- Alban Deniz
  6. #
  7. # Copyright (C) 2008 ARM Research Labs, LLC.
  8. # See www.armresearch.com for the copyright terms.
  9. #
  10. # chkconfig: 345 80 30
  11. # description: SNFServer providing email filtering.
  12. #
  13. ### BEGIN INIT INFO
  14. # Provides: SNFServer
  15. # Required-Start: $syslog $remote_fs $network $named
  16. # Should-Start: $time ypbind smtp
  17. # Required-Stop: $syslog $remote_fs
  18. # Should-Stop: $time ypbind smtp
  19. # Default-Start: 3 5
  20. # Default-Stop: 0 1 2 6
  21. # Short-Description: SNFServer providing email filtering.
  22. # Description: Start SNFServer to filter email for spam and
  23. # check IP addresses.
  24. ### END INIT INFO
  25. # Directory to run in.
  26. runDir=PREFIX/share/PACKAGE_NAME
  27. # Define mode files.
  28. debugModeFile=$runDir/debug_mode
  29. productionModeFile=$runDir/production_mode
  30. # Set debug mode flag.
  31. if [ -f $debugModeFile ]
  32. then
  33. debugMode=true
  34. fi
  35. # Debug output file.
  36. debugOutputFile=/var/log/PACKAGE_NAME/debug.log
  37. # Location of installation.
  38. installedDir="PREFIX"
  39. # Location of programs.
  40. dir="$installedDir/sbin"
  41. # Name of config file.
  42. configFile="CONFFILE"
  43. # Name of daemon.
  44. debugProg="SNFDebugServer"
  45. productionProg="SNFServer"
  46. # Name of client.
  47. clientProg="SNFClient"
  48. # Name of user to run as.
  49. userName="snfuser"
  50. # Name of lockfile.
  51. lockFile="/var/lock/$productionProg"
  52. # Name of client.
  53. clientProg="SNFClient"
  54. # Check for missing binaries (stale symlinks should not happen)
  55. # Note: Special treatment of stop for LSB conformance
  56. SNFServer_BIN=$dir/$productionProg
  57. test -x $SNFServer_BIN || { echo $"$SNFServer_BIN not installed";
  58. if [ "$1" = "stop" ]; then exit 0;
  59. else exit 5; fi; }
  60. # Use the SUSE rc_ init script functions;
  61. # emulate them on LSB, RH and other systems
  62. # Default: Assume sysvinit binaries exist
  63. start_daemon() { /sbin/start_daemon ${1+"$@"}; }
  64. killproc() { /sbin/killproc ${1+"$@"}; }
  65. pidofproc() { /sbin/pidofproc ${1+"$@"}; }
  66. checkproc() { /sbin/checkproc ${1+"$@"}; }
  67. if test -e /etc/rc.status; then
  68. # SUSE rc script library
  69. . /etc/rc.status
  70. else
  71. export LC_ALL=POSIX
  72. _cmd=$1
  73. declare -a _SMSG
  74. if test "${_cmd}" = "status"; then
  75. _SMSG=(running dead dead unused unknown reserved)
  76. _RC_UNUSED=3
  77. else
  78. _SMSG=(done failed failed missed failed skipped unused failed failed reserved)
  79. _RC_UNUSED=6
  80. fi
  81. if test -e /lib/lsb/init-functions; then
  82. # LSB
  83. . /lib/lsb/init-functions
  84. echo_rc()
  85. {
  86. if test ${_RC_RV} = 0; then
  87. log_success_msg " [${_SMSG[${_RC_RV}]}] "
  88. else
  89. log_failure_msg " [${_SMSG[${_RC_RV}]}] "
  90. fi
  91. }
  92. # TODO: Add checking for lockfiles
  93. checkproc() { return pidofproc ${1+"$@"} >/dev/null 2>&1; }
  94. elif test -e /etc/init.d/functions; then
  95. # RHAT
  96. . /etc/init.d/functions
  97. echo_rc()
  98. {
  99. #echo -n " [${_SMSG[${_RC_RV}]}] "
  100. if test ${_RC_RV} = 0; then
  101. success " [${_SMSG[${_RC_RV}]}] "
  102. else
  103. failure " [${_SMSG[${_RC_RV}]}] "
  104. fi
  105. }
  106. checkproc() { return status ${1+"$@"}; }
  107. start_daemon() { return daemon ${1+"$@"}; }
  108. else
  109. # emulate it
  110. echo_rc() { echo $" [${_SMSG[${_RC_RV}]}] "; }
  111. fi
  112. rc_reset() { _RC_RV=0; }
  113. rc_failed()
  114. {
  115. if test -z "$1"; then
  116. _RC_RV=1;
  117. elif test "$1" != "0"; then
  118. _RC_RV=$1;
  119. fi
  120. return ${_RC_RV}
  121. }
  122. rc_check()
  123. {
  124. return rc_failed $?
  125. }
  126. rc_status()
  127. {
  128. rc_failed $?
  129. if test "$1" = "-r"; then _RC_RV=0; shift; fi
  130. if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
  131. if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
  132. if test "$1" = "-v"; then echo_rc; shift; fi
  133. if test "$1" = "-r"; then _RC_RV=0; shift; fi
  134. return ${_RC_RV}
  135. }
  136. rc_exit() { exit ${_RC_RV}; }
  137. rc_active()
  138. {
  139. if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
  140. if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
  141. return 1
  142. }
  143. fi
  144. # Reset status of this service
  145. rc_reset
  146. #
  147. # Function to create the mode file.
  148. #
  149. createModeFile()
  150. {
  151. fileName=$1
  152. # Remove any existing mode files.
  153. rm -f $productionModeFile $debugModeFile $fileName
  154. (
  155. echo $"PACKAGE_NAME mode file"
  156. echo
  157. echo $"This file specifies whether PACKAGE_NAME is configured to run in"
  158. echo $"production mode or debug mode. If the name of this file is"
  159. echo $"'production_mode', then PACKAGE_NAME is configured to run in"
  160. echo $"production mode. If the name is 'debug_mode', then PACKAGE_NAME is"
  161. echo $"configured to run in debug mode."
  162. echo
  163. echo $"To run in debug mode:"
  164. echo
  165. echo $" 1) Run 'PACKAGE_NAME debug_mode'"
  166. echo
  167. echo $" 2) Run 'PACKAGE_NAME restart' (if PACKAGE_NAME is already running),"
  168. echo $" or 'PACKAGE_NAME start' (to start PACKAGE_NAME)"
  169. echo
  170. echo $"To run in production mode:"
  171. echo
  172. echo $" 1) Run 'PACKAGE_NAME production_mode'"
  173. echo
  174. echo $" 2) Run 'PACKAGE_NAME restart' (if PACKAGE_NAME is already running),"
  175. echo $" or 'PACKAGE_NAME start' (to start PACKAGE_NAME)"
  176. echo
  177. echo $"By default, PACKAGE_NAME is configured to run in production mode."
  178. ) > $fileName
  179. }
  180. # Return values acc. to LSB for all commands but status:
  181. # 0 - success
  182. # 1 - generic or unspecified error
  183. # 2 - invalid or excess argument(s)
  184. # 3 - unimplemented feature (e.g. "reload")
  185. # 4 - user had insufficient privileges
  186. # 5 - program is not installed
  187. # 6 - program is not configured
  188. # 7 - program is not running
  189. # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
  190. #
  191. # Note that starting an already running service, stopping
  192. # or restarting a not-running service as well as the restart
  193. # with force-reload (in case signaling is not supported) are
  194. # considered a success.
  195. start(){
  196. echo -n $"Starting $productionProg: "
  197. for prog in $productionProg $debugProg
  198. do
  199. SNFPID=$(pidof -s $dir/$prog)
  200. if [ -n "$SNFPID" ] ; then
  201. return 0
  202. fi
  203. done
  204. # Start.
  205. if [ $debugMode ]
  206. then
  207. # Enable core dumps and start with output redirected.
  208. (ulimit -c unlimited; \
  209. su $userName -s /bin/sh -c \
  210. "echo Starting $dir/$debugProg on $(date) >> $debugOutputFile"; \
  211. cd PREFIX/share/PACKAGE_NAME; \
  212. su $userName -c \
  213. "strace -r -tt -v $dir/$debugProg $configFile >> $debugOutputFile 2>&1 &" \
  214. -s /bin/sh)
  215. else
  216. (cd PREFIX/share/PACKAGE_NAME; \
  217. su $userName -c "$dir/$productionProg $configFile > /dev/null 2>&1 &" \
  218. -s /bin/sh > /dev/null 2>&1)
  219. fi
  220. RETVAL=$?
  221. if [ $RETVAL -eq 0 ]; then
  222. $dir/$clientProg -status.second > /dev/null 2>&1
  223. RETVAL=$?
  224. fi
  225. if [ $RETVAL -eq 0 ]; then
  226. touch $lockFile
  227. else
  228. rc_failed 1
  229. fi
  230. return $RETVAL
  231. }
  232. stop(){
  233. echo -n $"Stopping $productionProg: "
  234. DEBUG_SNFPID=$(pidof -s $dir/$debugProg)
  235. PRODUCTION_SNFPID=$(pidof -s $dir/$productionProg)
  236. if [ -n "$DEBUG_SNFPID" ] || [ -n "$PRODUCTION_SNFPID" ]; then
  237. $dir/$clientProg -shutdown > /dev/null 2>&1
  238. sleep 10
  239. # Check that the programs are no longer running.
  240. RETVAL=0
  241. for prog in $debugProg $productionProg
  242. do
  243. SNFPID=$(pidof -s $dir/$prog)
  244. if [ -n "$SNFPID" ]; then
  245. kill $SNFPID
  246. RETVAL=$(($RETVAL+$?))
  247. fi
  248. done
  249. else
  250. # Process is not running.
  251. RETVAL=0
  252. fi
  253. if [ $RETVAL -eq 0 ]; then
  254. rm -f $lockFile
  255. else
  256. rc_failed 1
  257. fi
  258. return $RETVAL
  259. }
  260. restart(){
  261. stop
  262. start
  263. }
  264. case "$1" in
  265. start)
  266. start
  267. # Remember status and be verbose
  268. rc_status -v
  269. ;;
  270. stop)
  271. stop
  272. # Remember status and be verbose
  273. rc_status -v
  274. ;;
  275. restart)
  276. ## Stop the service and regardless of whether it was
  277. ## running or not, start it again.
  278. $0 stop
  279. $0 start
  280. # Remember status and be quiet
  281. rc_status
  282. ;;
  283. status)
  284. echo -n "Checking for service SNFServer "
  285. checkproc $SNFServer_BIN
  286. rc_status -v
  287. echo -n "Checking for service SNFDebugServer "
  288. checkproc $dir/$debugProg
  289. rc_status -v
  290. ;;
  291. debug_mode)
  292. #
  293. # Remove any mode flags, and create the debug_mode file.
  294. #
  295. echo $"Switching to debug mode"
  296. createModeFile $debugModeFile
  297. ;;
  298. production_mode)
  299. #
  300. # Remove any mode flags, and create the production_mode file.
  301. #
  302. echo $"Switching to production mode"
  303. createModeFile $productionModeFile
  304. ;;
  305. try-restart|condrestart|force-reload|reload|probe)
  306. # Not supported.
  307. echo -n "$0 $1 "
  308. rc_failed 3
  309. rc_status -v
  310. ;;
  311. *)
  312. echo $"Usage: $0 {start|stop|status|restart|production_mode|debug_mode}"
  313. exit 1
  314. ;;
  315. esac
  316. rc_exit