From 8f851e716e0945cb5debeb2321ebd4cfe25843a5 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Tue, 11 Oct 2011 20:22:23 -0500 Subject: [PATCH 1/5] Create run.sh --- tools/build_ramdisk.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/build_ramdisk.sh b/tools/build_ramdisk.sh index 63d37a9..b9f4afd 100755 --- a/tools/build_ramdisk.sh +++ b/tools/build_ramdisk.sh @@ -18,6 +18,9 @@ CWD=`pwd` DEST=${DEST:-/opt/stack} +# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova" +STACKSH_PARAMS=${STACKSH_PARAMS:-} + # Option to use the version of devstack on which we are currently working USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1} @@ -112,6 +115,29 @@ auto eth0 iface eth0 inet dhcp EOF +# Configure the runner +RUN_SH=$CHROOTCACHE/natty-stack/$DEST/run.sh +cat > $RUN_SH < $DEST/run.sh.log +echo >> $DEST/run.sh.log +echo >> $DEST/run.sh.log +echo "All done! Time to start clicking." >> $DEST/run.sh.log +EOF + +# Make the run.sh executable +chmod 755 $RUN_SH + # build a new image BASE=$CHROOTCACHE/build.$$ IMG=$BASE.img From 7c076eeff5db638cba5e1e274fd85056f4dd67ed Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 13 Oct 2011 13:20:13 -0500 Subject: [PATCH 2/5] Add FLOATING_RANGE default --- tools/build_ramdisk.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/build_ramdisk.sh b/tools/build_ramdisk.sh index b9f4afd..14224b1 100755 --- a/tools/build_ramdisk.sh +++ b/tools/build_ramdisk.sh @@ -120,8 +120,14 @@ RUN_SH=$CHROOTCACHE/natty-stack/$DEST/run.sh cat > $RUN_SH < Date: Thu, 13 Oct 2011 15:50:44 -0500 Subject: [PATCH 3/5] Set hostname in ramdisk image --- tools/build_ramdisk.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/build_ramdisk.sh b/tools/build_ramdisk.sh index 14224b1..6a168bf 100755 --- a/tools/build_ramdisk.sh +++ b/tools/build_ramdisk.sh @@ -45,7 +45,7 @@ if [ ! -d $CHROOTCACHE/natty-dev ]; then chroot $CHROOTCACHE/natty-dev groupadd libvirtd chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd mkdir -p $CHROOTCACHE/natty-dev/$DEST - chown stack $CHROOTCACHE/natty-dev/$DEST + chroot $CHROOTCACHE/natty-dev chown stack $DEST # a simple password - pass echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd @@ -115,6 +115,10 @@ auto eth0 iface eth0 inet dhcp EOF +# Set hostname +echo "ramstack" >$CHROOTCACHE/natty-stack/etc/hostname +echo "127.0.0.1 localhost ramstack" >$CHROOTCACHE/natty-stack/etc/hosts + # Configure the runner RUN_SH=$CHROOTCACHE/natty-stack/$DEST/run.sh cat > $RUN_SH < Date: Mon, 17 Oct 2011 10:48:21 -0500 Subject: [PATCH 4/5] Remove natty image fakery --- tools/build_ramdisk.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tools/build_ramdisk.sh b/tools/build_ramdisk.sh index 6a168bf..decdeb2 100755 --- a/tools/build_ramdisk.sh +++ b/tools/build_ramdisk.sh @@ -129,12 +129,6 @@ set \`ip addr show dev eth0 | grep inet\` PREFIX=\`echo \$2 | cut -d. -f1,2,3\` export FLOATING_RANGE="\$PREFIX.224/27" -# Pre-empt download of natty image -tar czf $DEST/devstack/files/natty.tgz /etc/hosts -mkdir -p $DEST/devstack/files/images -touch $DEST/devstack/files/images/natty-server-cloudimg-amd64-vmlinuz-virtual -touch $DEST/devstack/files/images/natty-server-cloudimg-amd64.img - # Kill any existing screens killall screen From 9122e7b17344dc80710f3a50aa6e8896f9ba8c71 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Mon, 17 Oct 2011 14:07:11 -0500 Subject: [PATCH 5/5] Set stack user's home dir to DEST --- stack.sh | 78 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/stack.sh b/stack.sh index a7eacbf..8e116a9 100755 --- a/stack.sh +++ b/stack.sh @@ -43,45 +43,6 @@ fi # Keep track of the current devstack directory. TOP_DIR=$(cd $(dirname "$0") && pwd) -# OpenStack is designed to be run as a regular user (Dashboard will fail to run -# as root, since apache refused to startup serve content from root user). If -# stack.sh is run as root, it automatically creates a stack user with -# sudo privileges and runs as that user. - -if [[ $EUID -eq 0 ]]; then - echo "You are running this script as root." - echo "In 10 seconds, we will create a user 'stack' and run as that user" - sleep 10 - - # since this script runs as a normal user, we need to give that user - # ability to run sudo - apt-get update - apt-get install -y sudo - - if ! getent passwd stack >/dev/null; then - echo "Creating a user called stack" - useradd -U -G sudo -s /bin/bash -m stack - fi - - echo "Giving stack user passwordless sudo priviledges" - # natty uec images sudoers does not have a '#includedir'. add one. - grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers || - echo "#includedir /etc/sudoers.d" >> /etc/sudoers - ( umask 226 && echo "stack ALL=(ALL) NOPASSWD:ALL" \ - > /etc/sudoers.d/50_stack_sh ) - - echo "Copying files to stack user" - STACK_DIR="/home/stack/${PWD##*/}" - cp -r -f "$PWD" "$STACK_DIR" - chown -R stack "$STACK_DIR" - if [[ "$SHELL_AFTER_RUN" != "no" ]]; then - exec su -c "set -e; cd $STACK_DIR; bash stack.sh; bash" stack - else - exec su -c "set -e; cd $STACK_DIR; bash stack.sh" stack - fi - exit 1 -fi - # Settings # ======== @@ -116,6 +77,45 @@ source ./stackrc # Destination path for installation ``DEST`` DEST=${DEST:-/opt/stack} +# OpenStack is designed to be run as a regular user (Dashboard will fail to run +# as root, since apache refused to startup serve content from root user). If +# stack.sh is run as root, it automatically creates a stack user with +# sudo privileges and runs as that user. + +if [[ $EUID -eq 0 ]]; then + echo "You are running this script as root." + echo "In 10 seconds, we will create a user 'stack' and run as that user" + sleep 10 + + # since this script runs as a normal user, we need to give that user + # ability to run sudo + apt-get update + apt-get install -y sudo + + if ! getent passwd stack >/dev/null; then + echo "Creating a user called stack" + useradd -U -G sudo -s /bin/bash -d $DEST -m stack + fi + + echo "Giving stack user passwordless sudo priviledges" + # natty uec images sudoers does not have a '#includedir'. add one. + grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers || + echo "#includedir /etc/sudoers.d" >> /etc/sudoers + ( umask 226 && echo "stack ALL=(ALL) NOPASSWD:ALL" \ + > /etc/sudoers.d/50_stack_sh ) + + echo "Copying files to stack user" + STACK_DIR="$DEST/${PWD##*/}" + cp -r -f "$PWD" "$STACK_DIR" + chown -R stack "$STACK_DIR" + if [[ "$SHELL_AFTER_RUN" != "no" ]]; then + exec su -c "set -e; cd $STACK_DIR; bash stack.sh; bash" stack + else + exec su -c "set -e; cd $STACK_DIR; bash stack.sh" stack + fi + exit 1 +fi + # Set the destination directories for openstack projects NOVA_DIR=$DEST/nova DASH_DIR=$DEST/dash