Merge pull request #67 from dtroyer/7-stack-home
stack home dir
diff --git a/stack.sh b/stack.sh
index dc85abb..61c0f57 100755
--- a/stack.sh
+++ b/stack.sh
@@ -44,45 +44,6 @@
fi
-# 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
# ========
@@ -117,6 +78,45 @@
# 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
diff --git a/tools/build_ramdisk.sh b/tools/build_ramdisk.sh
index 63d37a9..decdeb2 100755
--- a/tools/build_ramdisk.sh
+++ b/tools/build_ramdisk.sh
@@ -18,6 +18,9 @@
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}
@@ -42,7 +45,7 @@
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
@@ -112,6 +115,34 @@
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 <<EOF
+#!/usr/bin/env bash
+
+# Get IP range
+set \`ip addr show dev eth0 | grep inet\`
+PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
+export FLOATING_RANGE="\$PREFIX.224/27"
+
+# Kill any existing screens
+killall screen
+
+# Run stack.sh
+cd $DEST/devstack && \$STACKSH_PARAMS ./stack.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
+chroot $CHROOTCACHE/natty-stack chown stack $DEST/run.sh
+
# build a new image
BASE=$CHROOTCACHE/build.$$
IMG=$BASE.img