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