Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

snf-server.freebsd 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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=snfserver_enable
  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. # Get system call info.
  50. command="/usr/bin/truss"
  51. # Start with output redirected to a file.
  52. command_args="-d $dir/$debugProg $configFile >> $debugOutputFile 2>&1 &"
  53. else
  54. # Run non-debug version.
  55. command=$dir/$productionProg
  56. # Start with output discarded.
  57. command_args="$configFile > /dev/null 2>&1 &"
  58. fi
  59. start_postcmd="${name}_poststart"
  60. snfserver_poststart()
  61. {
  62. $dir/$clientProg -status.second > /dev/null 2>&1
  63. return $?
  64. }
  65. status_cmd="${name}_status"
  66. snfserver_status()
  67. {
  68. # Check whether the programs are running.
  69. RETVAL=0
  70. for progName in $debugProg $productionProg
  71. do
  72. SNFPID=$(check_process $dir/$progName)
  73. if [ -n "$SNFPID" ]; then
  74. echo "$progName is running as pid $SNFPID."
  75. RETVAL=$(($RETVAL+1))
  76. else
  77. echo "$progName is not running."
  78. fi
  79. done
  80. if [ 0 -eq $RETVAL ]
  81. then
  82. # Not running.
  83. return 1
  84. else
  85. # At least one program is running.
  86. return 0
  87. fi
  88. }
  89. stop_cmd="${name}_stop"
  90. snfserver_stop()
  91. {
  92. echo "Stopping $name."
  93. $dir/$clientProg -shutdown > /dev/null 2>&1
  94. sleep 10
  95. }
  96. stop_postcmd="${name}_poststop"
  97. snfserver_poststop()
  98. {
  99. DEBUG_SNFPID=$(check_process $dir/$debugProg)
  100. PRODUCTION_SNFPID=$(check_process $dir/$productionProg)
  101. # Check that the programs are no longer running.
  102. RETVAL=0
  103. for progName in $debugProg $productionProg
  104. do
  105. SNFPID=$(check_process $dir/$progName)
  106. if [ -n "$SNFPID" ]; then
  107. kill $SNFPID
  108. RETVAL=$(($RETVAL+$?))
  109. fi
  110. done
  111. return $RETVAL
  112. }
  113. # Additional commands.
  114. extra_commands="production_mode debug_mode"
  115. #
  116. # Function to create the mode file.
  117. #
  118. createModeFile()
  119. {
  120. fileName=$1
  121. # Remove any existing mode files.
  122. rm -f $productionModeFile $debugModeFile $fileName
  123. (
  124. echo "PACKAGE_NAME mode file"
  125. echo
  126. echo "This file specifies whether PACKAGE_NAME is configured to run in"
  127. echo "production mode or debug mode. If the name of this file is"
  128. echo "'production_mode', then PACKAGE_NAME is configured to run in"
  129. echo "production mode. If the name is 'debug_mode', then PACKAGE_NAME is"
  130. echo "configured to run in debug mode."
  131. echo
  132. echo "To run in debug mode:"
  133. echo
  134. echo " 1) Run 'PACKAGE_NAME debug_mode'"
  135. echo
  136. echo " 2) Run 'PACKAGE_NAME restart' (if PACKAGE_NAME is already running),"
  137. echo " or 'PACKAGE_NAME start' (to start PACKAGE_NAME)"
  138. echo
  139. echo "To run in production mode:"
  140. echo
  141. echo " 1) Run 'PACKAGE_NAME production_mode'"
  142. echo
  143. echo " 2) Run 'PACKAGE_NAME restart' (if PACKAGE_NAME is already running),"
  144. echo " or 'PACKAGE_NAME start' (to start PACKAGE_NAME)"
  145. echo
  146. echo "By default, PACKAGE_NAME is configured to run in production mode."
  147. ) > $fileName
  148. }
  149. production_mode_cmd="${name}_production_mode"
  150. # Switch to production mode.
  151. snfserver_production_mode()
  152. {
  153. echo "Switching to production mode"
  154. createModeFile $productionModeFile
  155. }
  156. debug_mode_cmd="${name}_debug_mode"
  157. # Switch to debug mode.
  158. snfserver_debug_mode()
  159. {
  160. echo "Switching to debug mode"
  161. createModeFile $debugModeFile
  162. }
  163. load_rc_config $name
  164. run_rc_command "$1"