Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

snf-server.archlinux 4.7KB

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