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

snf-server.freebsd 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #!/bin/sh
  2. #
  3. # snf-server Starts and stops the SNFServer daemon (FreeBSD).
  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. # PROVIDE: SNFServer
  11. # REQUIRE: FILESYSTEMS
  12. # KEYWORD: shutdown
  13. . /etc/rc.subr
  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. # Debug output file.
  25. debugOutputFile=/var/log/PACKAGE_NAME/debug.log
  26. # Location of installation.
  27. installedDir="PREFIX"
  28. # Location of programs.
  29. dir="$installedDir/sbin"
  30. # Name of config file.
  31. configFile="CONFFILE"
  32. # Name of client.
  33. clientProg="SNFClient"
  34. # Names of daemons.
  35. debugProg="SNFDebugServer"
  36. productionProg="SNFServer"
  37. name="snfserver"
  38. rcvar=`set_rcvar`
  39. required_dirs=$dir
  40. required_files="$dir/$productionProg $dir/$clientProg $configFile"
  41. snfserver_user=snfuser
  42. snfserver_group=snfuser
  43. # Start in a directory that is writable.
  44. snfserver_chdir=PREFIX/share/PACKAGE_NAME
  45. if [ $debugMode ]
  46. then
  47. # Enable core dumps.
  48. ulimit -c unlimited
  49. # Run debug version.
  50. command=$dir/$debugProg
  51. # Alternative to run under strace to get system call info.
  52. #command="/usr/local/bin/strace"
  53. # Start with output redirected to a file.
  54. command_args="$configFile >> $debugOutputFile 2>&1 &"
  55. # Alternative for running under strace.
  56. #command_args="-r -tt -v $dir/$debugProg $configFile >> $debugOutputFile 2>&1 &"
  57. else
  58. # Run non-debug version.
  59. command=$dir/$productionProg
  60. # Start with output discarded.
  61. command_args="$configFile > /dev/null 2>&1 &"
  62. fi
  63. start_postcmd="${name}_poststart"
  64. snfserver_poststart()
  65. {
  66. $dir/$clientProg -status.second > /dev/null 2>&1
  67. return $?
  68. }
  69. status_cmd="${name}_status"
  70. snfserver_status()
  71. {
  72. # Check whether the programs are running.
  73. RETVAL=0
  74. for progName in $debugProg $productionProg
  75. do
  76. SNFPID=$(check_process $dir/$progName)
  77. if [ -n "$SNFPID" ]; then
  78. echo "$progName is running as pid $SNFPID."
  79. RETVAL=$(($RETVAL+1))
  80. else
  81. echo "$progName is not running."
  82. fi
  83. done
  84. if [ 0 -eq $RETVAL ]
  85. then
  86. # Not running.
  87. return 1
  88. else
  89. # At least one program is running.
  90. return 0
  91. fi
  92. }
  93. stop_cmd="${name}_stop"
  94. snfserver_stop()
  95. {
  96. echo "Stopping $name."
  97. $dir/$clientProg -shutdown > /dev/null 2>&1
  98. sleep 10
  99. }
  100. stop_postcmd="${name}_poststop"
  101. snfserver_poststop()
  102. {
  103. DEBUG_SNFPID=$(check_process $dir/$debugProg)
  104. PRODUCTION_SNFPID=$(check_process $dir/$productionProg)
  105. # Check that the programs are no longer running.
  106. RETVAL=0
  107. for progName in $debugProg $productionProg
  108. do
  109. SNFPID=$(check_process $dir/$progName)
  110. if [ -n "$SNFPID" ]; then
  111. kill $SNFPID
  112. RETVAL=$(($RETVAL+$?))
  113. fi
  114. done
  115. return $RETVAL
  116. }
  117. # Additional commands.
  118. extra_commands="production_mode debug_mode"
  119. #
  120. # Function to create the mode file.
  121. #
  122. createModeFile()
  123. {
  124. fileName=$1
  125. # Remove any existing mode files.
  126. rm -f $productionModeFile $debugModeFile $fileName
  127. (
  128. echo "PACKAGE_NAME mode file"
  129. echo
  130. echo "This file specifies whether PACKAGE_NAME is configured to run in"
  131. echo "production mode or debug mode. If the name of this file is"
  132. echo "'production_mode', then PACKAGE_NAME is configured to run in"
  133. echo "production mode. If the name is 'debug_mode', then PACKAGE_NAME is"
  134. echo "configured to run in debug mode."
  135. echo
  136. echo "To run in debug mode:"
  137. echo
  138. echo " 1) Run 'PACKAGE_NAME debug_mode'"
  139. echo
  140. echo " 2) Run 'PACKAGE_NAME restart' (if PACKAGE_NAME is already running),"
  141. echo " or 'PACKAGE_NAME start' (to start PACKAGE_NAME)"
  142. echo
  143. echo "To run in production mode:"
  144. echo
  145. echo " 1) Run 'PACKAGE_NAME production_mode'"
  146. echo
  147. echo " 2) Run 'PACKAGE_NAME restart' (if PACKAGE_NAME is already running),"
  148. echo " or 'PACKAGE_NAME start' (to start PACKAGE_NAME)"
  149. echo
  150. echo "By default, PACKAGE_NAME is configured to run in production mode."
  151. ) > $fileName
  152. }
  153. production_mode_cmd="${name}_production_mode"
  154. # Switch to production mode.
  155. snfserver_production_mode()
  156. {
  157. echo "Switching to production mode"
  158. createModeFile $productionModeFile
  159. }
  160. debug_mode_cmd="${name}_debug_mode"
  161. # Switch to debug mode.
  162. snfserver_debug_mode()
  163. {
  164. echo "Switching to debug mode"
  165. createModeFile $debugModeFile
  166. }
  167. load_rc_config $name
  168. run_rc_command "$1"