Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

snf-server.redhat 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #!/bin/bash
  2. #
  3. # snf-server Starts and stops the SNFServer daemon (RedHat).
  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 provides email filtering (anti-spam) services \
  12. # See www.armresearch.com for details.
  13. # processname: SNFServer
  14. # Directory to run in.
  15. runDir=PREFIX/share/PACKAGE_NAME
  16. # Define mode files.
  17. debugModeFile=$runDir/debug_mode
  18. productionModeFile=$runDir/production_mode
  19. # Set debug mode flag.
  20. if [ -f $debugModeFile ]
  21. then
  22. debugMode=true
  23. fi
  24. # Source function library.
  25. . /etc/rc.d/init.d/functions
  26. # Source networking configuration.
  27. . /etc/sysconfig/network
  28. # Debug output file.
  29. debugOutputFile=/var/log/PACKAGE_NAME/debug.log
  30. # Location of installation.
  31. installedDir="PREFIX"
  32. # Location of programs.
  33. dir="$installedDir/sbin"
  34. # Name of config file.
  35. configFile="CONFFILE"
  36. # Name of daemon.
  37. debugProg="SNFDebugServer"
  38. productionProg="SNFServer"
  39. # Name of client.
  40. clientProg="SNFClient"
  41. # Name of user to run as.
  42. userName="snfuser"
  43. # Name of lockfile.
  44. lockFile="/var/lock/subsys/PACKAGE_NAME"
  45. #
  46. # Function to create the mode file.
  47. #
  48. createModeFile()
  49. {
  50. fileName=$1
  51. # Remove any existing mode files.
  52. rm -f $productionModeFile $debugModeFile $fileName
  53. (
  54. echo $"PACKAGE_NAME mode file"
  55. echo
  56. echo $"This file specifies whether PACKAGE_NAME is configured to run in"
  57. echo $"production mode or debug mode. If the name of this file is"
  58. echo $"'production_mode', then PACKAGE_NAME is configured to run in"
  59. echo $"production mode. If the name is 'debug_mode', then PACKAGE_NAME is"
  60. echo $"configured to run in debug mode."
  61. echo
  62. echo $"To run in debug mode:"
  63. echo
  64. echo $" 1) Run 'PACKAGE_NAME debug_mode'"
  65. echo
  66. echo $" 2) Run 'PACKAGE_NAME restart' (if PACKAGE_NAME is already running),"
  67. echo $" or 'PACKAGE_NAME start' (to start PACKAGE_NAME)"
  68. echo
  69. echo $"To run in production mode:"
  70. echo
  71. echo $" 1) Run 'PACKAGE_NAME production_mode'"
  72. echo
  73. echo $" 2) Run 'PACKAGE_NAME restart' (if PACKAGE_NAME is already running),"
  74. echo $" or 'PACKAGE_NAME start' (to start PACKAGE_NAME)"
  75. echo
  76. echo $"By default, PACKAGE_NAME is configured to run in production mode."
  77. ) > $fileName
  78. }
  79. start(){
  80. echo -n $"Starting $productionProg: "
  81. for prog in $productionProg $debugProg
  82. do
  83. SNFPID=$(pidof -s $dir/$prog)
  84. if [ -n "$SNFPID" ] ; then
  85. echo -n $"$productionProg is already running"
  86. failure
  87. echo
  88. return 1
  89. fi
  90. done
  91. # Start.
  92. if [ $debugMode ]
  93. then
  94. # Enable core dumps and start with strace and output redirected.
  95. (ulimit -c unlimited; \
  96. su $userName -s /bin/sh -c \
  97. "echo Starting $dir/$debugProg on $(date) >> $debugOutputFile"; \
  98. cd PREFIX/share/PACKAGE_NAME; \
  99. su $userName -c \
  100. "strace -r -tt -v $dir/$debugProg $configFile >> $debugOutputFile 2>&1 &" \
  101. -s /bin/sh)
  102. else
  103. (cd PREFIX/share/PACKAGE_NAME; \
  104. su $userName -c "$dir/$productionProg $configFile > /dev/null 2>&1 &" \
  105. -s /bin/sh > /dev/null 2>&1)
  106. fi
  107. RETVAL=$?
  108. if [ $RETVAL -eq 0 ]; then
  109. $dir/$clientProg -status.second > /dev/null 2>&1
  110. RETVAL=$?
  111. fi
  112. if [ $RETVAL -eq 0 ]; then
  113. touch $lockFile
  114. success
  115. echo
  116. else
  117. failure
  118. echo
  119. fi
  120. return $RETVAL
  121. }
  122. stop(){
  123. echo -n $"Stopping $productionProg: "
  124. DEBUG_SNFPID=$(pidof -s $dir/$debugProg)
  125. PRODUCTION_SNFPID=$(pidof -s $dir/$productionProg)
  126. if [ -n "$DEBUG_SNFPID" ] || [ -n "$PRODUCTION_SNFPID" ]; then
  127. $dir/$clientProg -shutdown > /dev/null 2>&1
  128. sleep 10
  129. # Check that the programs are no longer running.
  130. RETVAL=0
  131. for prog in $debugProg $productionProg
  132. do
  133. SNFPID=$(pidof -s $dir/$prog)
  134. if [ -n "$SNFPID" ]; then
  135. kill $SNFPID
  136. RETVAL=$(($RETVAL+$?))
  137. fi
  138. done
  139. else
  140. echo -n $"$productionProg is not running"
  141. RETVAL=1
  142. failure
  143. echo
  144. fi
  145. if [ $RETVAL -eq 0 ]; then
  146. success
  147. echo
  148. rm -f $lockFile
  149. fi
  150. return $RETVAL
  151. }
  152. restart(){
  153. stop
  154. start
  155. }
  156. # See how we were called.
  157. case "$1" in
  158. start)
  159. start
  160. ;;
  161. stop)
  162. stop
  163. ;;
  164. status)
  165. status $productionProg
  166. status $debugProg
  167. ;;
  168. restart)
  169. restart
  170. ;;
  171. debug_mode)
  172. #
  173. # Remove any mode flags, and create the debug_mode file.
  174. #
  175. echo $"Switching to debug mode"
  176. createModeFile $debugModeFile
  177. ;;
  178. production_mode)
  179. #
  180. # Remove any mode flags, and create the debug_mode file.
  181. #
  182. echo $"Switching to production mode"
  183. createModeFile $productionModeFile
  184. ;;
  185. *)
  186. echo $"Usage: $0 {start|stop|status|restart|production_mode|debug_mode}"
  187. exit 1
  188. esac
  189. exit $?