maglev 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/base"
  3. true ${rvm_trace_flag:-0}
  4. if (( rvm_trace_flag == 2 ))
  5. then
  6. set -x
  7. export rvm_trace_flag
  8. fi
  9. system="${_system_type}"
  10. version="${rvm_ruby_string}.${system}"
  11. # Check we're on a suitable 64-bit machine
  12. case "$system" in
  13. Linux)
  14. if [[ "${_system_arch}" != "x86_64" ]]
  15. then
  16. rvm_error "This script only works on a 64-bit Linux OS."
  17. echo "The result from \"uname -sm\" is \"${_system_type} ${_system_arch}\" not \"Linux x86_64\""
  18. exit 1
  19. fi
  20. ;;
  21. Darwin)
  22. system_version="$(sw_vers -productVersion)"
  23. MAJOR="$(echo $system_version | cut -f1 -d.)"
  24. MINOR="$(echo $system_version | cut -f2 -d.)"
  25. CPU_CAPABLE="$(sysctl hw.cpu64bit_capable | cut -f2 -d' ')"
  26. #
  27. # Check the CPU and Mac OS profile.
  28. if [[ $CPU_CAPABLE -ne 1 || $MAJOR -lt 10 || $MINOR -lt 5 ]]
  29. then
  30. rvm_error "This script requires Mac OS 10.5 or later on a 64-bit Intel CPU."
  31. exit 1
  32. fi
  33. ;;
  34. SunOS)
  35. if [[ "${_system_arch}" != "i386" || "$(isainfo -b)" != "64" ]]
  36. then
  37. rvm_error "This script only works on a 64-bit Solaris-x86 OS."
  38. exit 1
  39. fi
  40. ;;
  41. *)
  42. rvm_error "This script only works on a 64-bit Linux, Mac OS X, or Solaris-x86 machine"
  43. echo "The result from \"uname -sm\" is \"${_system_type} ${_system_version}\""
  44. exit 1
  45. ;;
  46. esac
  47. # We should run this as a normal user, not root.
  48. if (( UID == 0 ))
  49. then
  50. rvm_error "This script should be run as a normal user, not root."
  51. exit 1
  52. fi
  53. # Check that the current directory is writable
  54. if [[ ! -w "." ]]
  55. then
  56. rvm_error "This script requires write permission on your current directory."
  57. __rvm_ls -ld $PWD
  58. exit 1
  59. fi
  60. # We're good to go. Let user know.
  61. machine_name="$(command uname -n)"
  62. rvm_log "Starting installation of $version on $machine_name"
  63. # Figure out how much total memory is installed
  64. rvm_log "Setting up shared memory"
  65. #
  66. # Ref: http://wiki.finkproject.org/index.php/Shared_Memory_Regions_on_Darwin
  67. # Ref: http://developer.postgresql.org/pgdocs/postgres/kernel-resources.html
  68. # Ref: http://www.idevelopment.info/data/Oracle/DBA_tips/Linux/LINUX_8.shtml
  69. #
  70. case "$system" in
  71. Linux)
  72. # use TotalMem: kB because Ubuntu doesn't have Mem: in Bytes
  73. totalMemKB=$(__rvm_awk '/MemTotal:/{print($2);}' /proc/meminfo)
  74. totalMem=$(($totalMemKB * 1024))
  75. # Figure out the max shared memory segment size currently allowed
  76. shmmax=$(\command \cat /proc/sys/kernel/shmmax)
  77. # Figure out the max shared memory currently allowed
  78. shmall=$(\command \cat /proc/sys/kernel/shmall)
  79. ;;
  80. Darwin)
  81. totalMem="$(sysctl hw.memsize | cut -f2 -d' ')"
  82. # Figure out the max shared memory segment size currently allowed
  83. shmmax="$(sysctl kern.sysv.shmmax | cut -f2 -d' ')"
  84. # Figure out the max shared memory currently allowed
  85. shmall="$(sysctl kern.sysv.shmall | cut -f2 -d' ')"
  86. ;;
  87. SunOS)
  88. # TODO: figure memory needs for SunOS
  89. # Investigate project.max-shm-memory
  90. totalMemMB="$(/usr/sbin/prtconf | __rvm_grep Memory | cut -f3 -d' ')"
  91. totalMem=$(($totalMemMB * 1048576))
  92. shmmax=$(($totalMem / 4))
  93. shmall=$(($shmmax / 4096))
  94. ;;
  95. *)
  96. rvm_error "Can't determine operating system. Check script."
  97. exit 1
  98. ;;
  99. esac
  100. totalMemMB=$(($totalMem / 1048576))
  101. shmmaxMB=$(($shmmax / 1048576))
  102. shmallMB=$(($shmall / 256))
  103. # Print current values
  104. echo " Total memory available is $totalMemMB MB"
  105. echo " Max shared memory segment size is $shmmaxMB MB"
  106. echo " Max shared memory allowed is $shmallMB MB"
  107. # Figure out the max shared memory segment size (shmmax) we want
  108. # Use 75% of available memory but not more than 2GB
  109. shmmaxNew=$(($totalMem * 3/4))
  110. if (( shmmaxNew > 2147483648 ))
  111. then
  112. shmmaxNew=2147483648
  113. fi
  114. shmmaxNewMB=$(($shmmaxNew / 1048576))
  115. # Figure out the max shared memory allowed (shmall) we want
  116. # The Darwin (OSX) default is 4MB, way too small
  117. # The Linux default is 2097152 or 8GB, so we should never need this
  118. # but things will certainly break if it's been reset too small
  119. # so ensure it's at least big enough to hold a fullsize shared memory segment
  120. shmallNew=$(($shmmaxNew / 4096))
  121. if (( shmallNew < shmall ))
  122. then
  123. shmallNew=$shmall
  124. fi
  125. shmallNewMB=$(($shmallNew / 256))
  126. # Increase shmmax if appropriate
  127. if (( shmmaxNew > shmmax ))
  128. then
  129. rvm_log "Increasing max shared memory segment size to $shmmaxNewMB MB"
  130. case "${system}" in
  131. Darwin)
  132. __rvm_try_sudo sysctl -w kern.sysv.shmmax=$shmmaxNew
  133. ;;
  134. Linux)
  135. __rvm_try_sudo bash -c "echo $shmmaxNew > /proc/sys/kernel/shmmax"
  136. ;;
  137. SunOS)
  138. echo "[[Warning]] shmmax must be set manually on SunOS"
  139. ;;
  140. esac
  141. else
  142. rvm_log "No need to increase max shared memory segment size"
  143. fi
  144. # Increase shmall if appropriate
  145. if (( shmallNew > shmall ))
  146. then
  147. rvm_log "Increasing max shared memory allowed to $shmallNewMB MB"
  148. case "${system}" in
  149. Darwin)
  150. __rvm_try_sudo sysctl -w kern.sysv.shmall=$shmallNew
  151. ;;
  152. Linux)
  153. __rvm_try_sudo bash -c "echo $shmallNew > /proc/sys/kernel/shmall"
  154. ;;
  155. SunOS)
  156. echo "[[Warning]]shmall must be set manually on SunOS"
  157. ;;
  158. esac
  159. else
  160. rvm_log "No need to increase max shared memory allowed"
  161. fi
  162. # At this point, shared memory settings contain the values we want,
  163. # put them in sysctl.conf so they are preserved.
  164. if [[ ! -f /etc/sysctl.conf ]] || (( $(__rvm_grep -sc "kern.*.shm" /etc/sysctl.conf) == 0 ))
  165. then
  166. case "$system" in
  167. Linux)
  168. echo "# kernel.shm* settings added by MagLev installation" > /tmp/sysctl.conf.$$
  169. echo "kernel.shmmax=$(\command \cat /proc/sys/kernel/shmmax)" >> /tmp/sysctl.conf.$$
  170. echo "kernel.shmall=$(\command \cat /proc/sys/kernel/shmall)" >> /tmp/sysctl.conf.$$
  171. ;;
  172. Darwin)
  173. # On Mac OS X Leopard, you must have all five settings in sysctl.conf
  174. # before they will take effect.
  175. echo "# kern.sysv.shm* settings added by MagLev installation" > /tmp/sysctl.conf.$$
  176. sysctl kern.sysv.shmmax kern.sysv.shmall kern.sysv.shmmin kern.sysv.shmmni \
  177. kern.sysv.shmseg | \command \tr ":" "=" | \command \tr -d " " >> /tmp/sysctl.conf.$$
  178. ;;
  179. SunOS)
  180. # Do nothing in SunOS since /etc/sysctl.conf is ignored on Solaris 10.
  181. # Must configure shared memory settings manually.
  182. ;;
  183. *)
  184. rvm_error "Can't determine operating system. Check script."
  185. exit 1
  186. ;;
  187. esac
  188. # Do nothing on SunOS since /etc/sysctl.conf is ignored on Solaris 10.
  189. if [[ "$system" != "SunOS" ]]
  190. then
  191. rvm_log "Adding the following section to /etc/sysctl.conf"
  192. \command \cat /tmp/sysctl.conf.$$
  193. __rvm_try_sudo bash -c "\command \cat /tmp/sysctl.conf.$$ >> /etc/sysctl.conf"
  194. /bin/\command \rm -f /tmp/sysctl.conf.$$
  195. fi
  196. else
  197. rvm_log "The following shared memory settings already exist in /etc/sysctl.conf"
  198. echo "To change them, remove the following lines from /etc/sysctl.conf and rerun this script"
  199. __rvm_grep "kern.*.shm" /etc/sysctl.conf
  200. fi
  201. # Now setup for NetLDI in case we ever need it.
  202. rvm_log "Setting up GemStone netldi service port"
  203. if (( $(__rvm_grep -sc "^gs64ldi" /etc/services) == 0 ))
  204. then
  205. echo '[[Info]] Adding "gs64ldi 50378/tcp" to /etc/services'
  206. __rvm_try_sudo bash -c 'echo "gs64ldi 50378/tcp # Gemstone netldi" >> /etc/services'
  207. else
  208. rvm_log "GemStone netldi service port is already set in /etc/services"
  209. echo "To change it, remove the following line from /etc/services and rerun this script"
  210. __rvm_grep "^gs64ldi" /etc/services
  211. fi