/
eucalyptus-nc.in
executable file
·557 lines (503 loc) · 17.6 KB
/
eucalyptus-nc.in
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
#!/bin/bash
#
# Init script for the Eucalyptus node controller
#
# Copyright 2009-2013 Eucalyptus Systems, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta
# CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need
# additional information or have any questions.
#
# This file may incorporate work covered under the following copyright
# and permission notice:
#
# Software License Agreement (BSD License)
#
# Copyright (c) 2008, Regents of the University of California
# All rights reserved.
#
# Redistribution and use of this software in source and binary forms,
# with or without modification, are permitted provided that the
# following conditions are met:
#
# Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. USERS OF THIS SOFTWARE ACKNOWLEDGE
# THE POSSIBLE PRESENCE OF OTHER OPEN SOURCE LICENSED MATERIAL,
# COPYRIGHTED MATERIAL OR PATENTED MATERIAL IN THIS SOFTWARE,
# AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
# IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA,
# SANTA BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY,
# WHICH IN THE REGENTS' DISCRETION MAY INCLUDE, WITHOUT LIMITATION,
# REPLACEMENT OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO
# IDENTIFIED, OR WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT
# NEEDED TO COMPLY WITH ANY SUCH LICENSES OR RIGHTS.
#
# chkconfig: 2345 99 05
# description: eucalyptus node controller
#
### BEGIN INIT INFO
# Provides: eucalyptus-nc
# Required-Start: $remote_fs $syslog libvirtd
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Eucalyptus node controller
# Description: Eucalyptus node controller
### END INIT INFO
#
# Do NOT "set -e"
# Use the functions script for distributions that support it (e.g., RHEL)
# This allows Eucalyptus to use correct localization settings
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
# For fault reporting: $LOCALE can be set in /etc/sysconfig/i18n
[ -n "$LOCALE" ] && export LOCALE || unset LOCALE
LOCKFILE=/var/lock/subsys/eucalyptus-nc
# if we have lsb functions let's source them
WE_HAVE_LSB="N"
if [ -e /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
# very old lsb don't have the functions we need
if type log_daemon_msg > /dev/null 2> /dev/null ; then
WE_HAVE_LSB="Y"
fi
fi
if [ "$EUID" != "0" ]; then
echo "Eucalyptus init scritps must be run as root."
exit 1
fi
# I just wanted to set PATH to be the system PATH, but if a user install
# eucalyptus manually, it may have binaries in a non-standard position:
# hence we need to keep the PATH we receive.
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
DESC="Eucalyptus services"
NAME=eucalyptus-nc
BRCTL="`which brctl 2> /dev/null`"
MODPROBE="`which modprobe 2> /dev/null`"
EUCA_USER="eucalyptus"
# honor the ENV variable if found otherwise look in root
if [ -z "$EUCALYPTUS" ] ; then
EUCALYPTUS="@prefix@"
if [ ! -e ${EUCALYPTUS}/etc/eucalyptus/eucalyptus.conf ] ; then
EUCALYPTUS="/"
fi
fi
export EUCALYPTUS
create_httpd_config() {
IPS="all"
# let's configure the common parts for both CC and NC
sed -e "s|EUCALYPTUS|$EUCALYPTUS|" \
-e "s|APACHE2_MODULE_DIR|$APACHE2_MODULE_DIR|" \
-e "s|AXIS2C_HOME|$AXIS2C_HOME|" \
-e "s|\(ServerRoot\).*|\1 "$HTTPD_HOME"|" \
-e "s|EUCA_USER|$EUCA_USER|" \
$EUCALYPTUS/etc/eucalyptus/httpd.conf \
> $EUCALYPTUS/etc/eucalyptus/httpd-tmp.conf
# load authz if we have it (ubuntu needs it)
if [ -e $HTTPD_HOME/usr/lib/apache2/modules/mod_authz_host.so ]; then
echo "LoadModule authz_host_module /usr/lib/apache2/modules/mod_authz_host.so" >> $EUCALYPTUS/etc/eucalyptus/httpd-tmp.conf
fi
# let's configure the NC
sed -e "s|\(Listen\).*|\1 $NC_PORT|" \
-e "s|\(PidFile\).*|\1 $EUCALYPTUS/var/run/eucalyptus/eucalyptus-nc.pid|" \
-e "s|\(Allow from\).*|\1 $IPS|" \
-e "s|\(ErrorLog\).*|\1 $EUCALYPTUS/var/log/eucalyptus/httpd-nc_error_log|" \
$EUCALYPTUS/etc/eucalyptus/httpd-tmp.conf \
> $EUCALYPTUS/etc/eucalyptus/httpd-nc.conf
}
# crude way to start the axis2c services
do_start() {
# Set kernel parameters for connection tracking (EUCA-5697)
$EUCALYPTUS/usr/libexec/eucalyptus/conntrack_kernel_params
# check if NTPD is running and throw a fault if it is not
if [ ! `pgrep -n ntp` ]; then
# write fault to stdout
echo
$EUCALYPTUS/usr/sbin/euca-generate-fault 1008 daemon ntp
# and to NC's fault log
$EUCALYPTUS/usr/sbin/euca-generate-fault -c nc 1008 daemon ntp
fi
# check for virt extensions in CPU
# First, lets check CPU flags to see if we have hardware support
HYPERVISOR=$(grep ^HYPERVISOR ${EUCALYPTUS}/etc/eucalyptus/eucalyptus.conf | cut -d'"' -f 2)
CPU_MODEL=$(egrep -m1 -w '^flags[[:blank:]]*:' /proc/cpuinfo | egrep -wo '(vmx|svm)')
# Be heavy-handed, exit with failure on lack of CPU virtualization support.
egrep -m1 -w '^flags[[:blank:]]*:' /proc/cpuinfo | egrep -wo '(vmx|svm)'
if [ $? -ne 0 ] ; then
echo "Terminating! This Node Controller does not have CPU virtualization support. You will not be able to run instances."
echo
$EUCALYPTUS/usr/sbin/euca-generate-fault -c nc 1013 component nc
exit 1
fi
# Now we check to see if it's enabled in BIOS by loading the kvm modules. Warn rather than exit and suggest the user enables this.
# For Intel systems
if [ $CPU_MODEL == vmx -a $HYPERVISOR == kvm ] ; then
modprobe kvm_intel
if [ $? -ne 0 ] ; then
echo "Unable to load KVM module, VT-x may be disabled in your systems BIOS, please enable it. You will not be able to launch instances."
echo
$EUCALYPTUS/usr/sbin/euca-generate-fault -c nc 1013 component nc
fi
fi
# For AMD systems
if [ $CPU_MODEL == svm -a $HYPERVISOR == kvm ] ; then
modprobe kvm_amd
if [ $? -ne 0 ] ; then
echo "Unable to load KVM module, AMD-V may be disabled in your systems BIOS, please enable it. You will not be able to launch instances."
echo
$EUCALYPTUS/usr/sbin/euca-generate-fault -c nc 1013 component nc
fi
fi
# fixes #469984
IPTABLES="`which iptables 2> /dev/null`"
if [ -n "$IPTABLES" ]; then
[ -x $IPTABLES ] && $IPTABLES -L -n > /dev/null 2> /dev/null
fi
if [ ! -x $HTTPD ]; then
echo
echo "cannot find httpd (was set to <$HTTPD>)!"
exit 1
fi
if [ ! -x $EUCALYPTUS/usr/sbin/euca_conf ]; then
echo "Some eucalyptus components are missing"
exit 1
fi
# Add loop devices if necessary (and possible)
[ -z "$CREATE_NC_LOOP_DEVICES" ] && CREATE_NC_LOOP_DEVICES=256
if [ "$CREATE_NC_LOOP_DEVICES" -gt 0 ] 2>/dev/null; then
"$EUCALYPTUS/usr/share/eucalyptus/create-loop-devices" $CREATE_NC_LOOP_DEVICES
fi
# let's see how many loop devices we have available
LOOP_AVL_DEV="`/bin/ls -1d /dev/loop* 2>/dev/null | wc -l`"
LOOP_AVL_SYS="`/bin/ls -1d /sys/block/loop* 2>/dev/null | wc -l`"
if [ -z "$LOOP_AVL_DEV" -o "$LOOP_AVL_DEV" = "0" ]; then
echo "warning: no loop devices found in /dev; expect problems" >&2
elif [ $LOOP_AVL_DEV -lt 50 ]; then
echo "warning: found $LOOP_AVL_DEV loop devices in /dev; at least 50 are recommended" >&2
elif [ -z "$LOOP_AVL_SYS" -o "$LOOP_AVL_SYS" -lt "$LOOP_AVL_DEV" ] && [[ `uname -r` < 2.6.22 ]]; then # The version comparison does not work in every shell
# When then loop driver's max_loop option is not 0, loop device nodes
# that are not automatically created by the kernel do not work. We can
# check for this case by looking for too few loop device entries in
# sysfs.
#
# Trying to determine whether or not max_loop is 0 is difficult on
# Linux 2, so in general we make no attempt to do so. However, max_loop
# *cannot* be 0 on Linux < 2.6.22, so we perform this check on those
# systems so it will hopefully cover the majority of cases.
echo "warning: found fewer loop devices in /sys/block than in /dev ($LOOP_AVL_SYS < $LOOP_AVL_DEV); expect problems"
fi
if ! $EUCALYPTUS/usr/sbin/euca_conf --check nc ; then
exit 1
fi
# Ensure libvirtd can start up in "--listen" mode by generating unusable stub keys if none are already present.
if [ ! -f /etc/pki/libvirt/servercert.pem ]; then
if [ ! -x $EUCALYPTUS/usr/share/eucalyptus/generate-migration-keys.sh ]; then
echo
echo "Cannot generate stub migration keys for libvirtd: missing generate-migration-keys.sh."
else
$EUCALYPTUS/usr/share/eucalyptus/generate-migration-keys.sh `hostname` INACTIVE
fi
fi
# Ensure any previously authorized migration credentials have been removed from libvirtd.conf
# and that it defaults to not allowing client connections.
#
# Restarts libvirtd (synchronously) as a side-effect.
if [ ! -x $EUCALYPTUS/usr/share/eucalyptus/authorize-migration-keys.pl ]; then
echo
echo "Cannot reset migration credentials in libvirtd.conf: missing authorize-migration-keys.pl."
else
$EUCALYPTUS/usr/share/eucalyptus/authorize-migration-keys.pl -D -r
fi
# we have a program to test the hypervisor and more for the NC
if [ ! -x $EUCALYPTUS/usr/sbin/euca_test_nc ]; then
echo
echo "Cannot check Node Controller: missing euca_test_nc."
else
# sometimes, libvirtd takes some time to start on init, so retry euca_test_nc a few times before failing
for i in 1 2 3 4 5
do
PASSED=0
if ( $EUCALYPTUS/usr/sbin/euca_test_nc $HYPERVISOR > $EUCALYPTUS/var/log/eucalyptus/euca_test_nc.log 2>&1 ); then
PASSED=1
else
sleep 1
fi
done
if ( test $PASSED = "0" ); then
echo
echo "Node Controller cannot be started: errors in $EUCALYPTUS/var/log/eucalyptus/euca_test_nc.log"
exit 1
fi
fi
# on SYSTEM or STATIC mode the bridge needs to exists
if [ "$VNET_MODE" = "SYSTEM" -o "$VNET_MODE" = "STATIC" ]; then
if [ -n "$BRCTL" -a -x $BRCTL ]; then
if ! $BRCTL show |grep $VNET_BRIDGE > /dev/null 2> /dev/null ; then
echo
echo "Warning! Cannot find bridge $VNET_BRIDGE: instances may be without net"
fi
fi
fi
# we need IP forwarding and we need to use iptable over the bridge
if [ -w /proc/sys/net/ipv4/ip_forward ]; then
VAL=`cat /proc/sys/net/ipv4/ip_forward`
if [ "$VAL" = "0" ]; then
echo
echo "Enabling IP forwarding for eucalyptus."
echo -n 1 > /proc/sys/net/ipv4/ip_forward
fi
fi
if [ -w /proc/sys/net/bridge/bridge-nf-call-iptables ]; then
VAL=`cat /proc/sys/net/bridge/bridge-nf-call-iptables`
if [ "$VAL" = "0" ]; then
echo
echo "Enabling bridge netfiltering for eucalyptus."
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
fi
fi
# let's be sure we have the right port for NC and CC
create_httpd_config
if [ -x $EUCALYPTUS/usr/sbin/eucanetd ]; then
if ! $EUCALYPTUS/usr/sbin/eucanetd ; then
echo
echo "Failed to start the eucanetd"
fi
fi
if ! $HTTPD -f $EUCALYPTUS/etc/eucalyptus/httpd-nc.conf ; then
echo
echo "Failed to start the NC!"
exit 1
fi
touch $LOCKFILE
}
do_status() {
pidfile=$EUCALYPTUS/var/run/eucalyptus/eucalyptus-nc.pid
if [ -s $pidfile ]; then
pid=`cat $pidfile 2> /dev/null`
if ps axww|grep $pid|grep httpd-nc.conf > /dev/null ; then
# we are good
return 0
fi
fi
return 1
}
do_stop() {
netpid="$EUCALYPTUS/var/run/eucalyptus/eucanetd.pid"
if [ -f "$netpid" ]; then
kill `cat $netpid` >/dev/null 2>&1
rm -f $netpid
fi
pidfile=$EUCALYPTUS/var/run/eucalyptus/eucalyptus-nc.pid
# let's be sure we are killing the right process
if ! do_status ; then
rm -f $pidfile
return
fi
# now kill the services
if [ -s $pidfile ]; then
pid=`cat $pidfile 2> /dev/null`
kill $pid > /dev/null 2>&1
else
return
fi
timeout=5
while [ $timeout -gt 0 ]; do
if ps $pid > /dev/null 2>&1 ; then
sleep 1
timeout=$(($timeout - 1))
else
break
fi
done
if [ $timeout -eq 0 ]; then
kill -9 $pid > /dev/null 2>&1
fi
rm -f $pidfile
rm -f $LOCKFILE
}
# Read configuration variable file if it is present
if [ -r $EUCALYPTUS/etc/eucalyptus/eucalyptus.conf ]; then
. $EUCALYPTUS/etc/eucalyptus/eucalyptus.conf
else
echo "Cannot find eucalyptus configuration file!"
exit 1
fi
if [ "$EUCALYPTUS" = "not_configured" ]; then
echo "EUCALYPTUS not configured!"
exit 1
fi
if [ -z "$EUCA_USER" ] ; then
EUCA_USER="root"
fi
# let's try to pick the system apache2
HTTPD="`which apache2 2> /dev/null`" # .deb based machines
if [ -z "$HTTPD" ]; then
HTTPD="`which httpd 2> /dev/null`" # .rpm based machines
fi
if [ -z "$HTTPD" ]; then
HTTPD="`which httpd2 2> /dev/null`" # newer .rpm based machines
fi
HTTPD_HOME="/"
if [ -d "@AXIS2C_HOME@" -a -e @AXIS2C_HOME@/services/EucalyptusNC ]; then
export AXIS2C_HOME="@AXIS2C_HOME@"
else
# let's find our dependencies
for y in $EUCALYPTUS/opt $EUCALYPTUS/packages $EUCALYPTUS /opt ; do
for x in `/bin/ls $y 2> /dev/null`; do
# this is for system or source installed
if [ "`echo $x | cut -f 1 -d -`" = "axis2c" ]; then
if [ -e $y/$x/lib/libmod_axis2.so -a \
-e $y/$x/services/EucalyptusNC ]; then
export AXIS2C_HOME="$y/$x"
break
fi
fi
done
done
fi
if [ -z "$AXIS2C_HOME" ]; then
echo "Cannot find AXIS2C_HOME?"
exit 1
fi
# do we have the httpd daemon?
if [ -z "${HTTPD}" ]; then
echo "apache2/httpd daemon not found!"
exit 1
fi
if [ -z "${APACHE2_MODULE_DIR}" ]; then
export APACHE2_MODULE_DIR="@APACHE2_MODULE_DIR@"
fi
if [ ! -d "$APACHE2_MODULE_DIR" ]; then
echo "Cannot find APACHE2_MODULE_DIR?"
exit 1
fi
# set the library path correctly
export LD_LIBRARY_PATH="$AXIS2C_HOME/lib:$AXIS2C_HOME/modules/rampart:$EUCALYPTUS/usr/lib/eucalyptus"
case "$1" in
start)
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_daemon_msg "Starting $DESC" "$NAME"
else
echo -n "Starting $DESC: "
fi
fi
# let's check there is no previous NC running
if do_status ; then
echo
echo "another NC is already running!"
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_end_msg 1
fi
fi
exit 1
fi
rm -f /dev/shm/sem.eucalyptus-nc* /dev/shm/sem.eucalyptus-st*
do_start
case "$?" in
0|1)
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_end_msg 0
else
echo "done."
fi
fi
;;
*)
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_end_msg 1
else
echo "failed!"
fi
fi
;;
esac
;;
stop)
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_begin_msg "Stopping $DESC"
else
echo -n "Stopping $DESC: "
fi
fi
do_stop
rm -f /dev/shm/sem.eucalyptus-nc* /dev/shm/sem.eucalyptus-st*
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_end_msg 0
else
echo "done."
fi
fi
;;
restart)
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_begin_msg "Restarting $DESC"
else
echo -n "Restarting $DESC: "
fi
fi
# restart allow the CC to mantain the state across restart
do_stop
do_start
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_end_msg 0
else
echo "done."
fi
fi
;;
status)
if do_status ; then
echo "NC is running"
else
exit 3
fi
;;
config)
echo "EUCALYPTUS=${EUCALYPTUS}"
echo "AXIS2C_HOME=${AXIS2C_HOME}"
echo "HTTPD_HOME=${HTTPD_HOME}"
echo "HTTPD=${HTTPD}"
;;
*)
echo "Usage: $NAME {start|stop|restart}" >&2
exit 3
;;
esac
: