|
172 | 172 | # ----------- |
173 | 173 |
|
174 | 174 | # OpenStack is designed to be run as a non-root user; Horizon will fail to run |
175 | | -# as **root** since Apache will not serve content from **root** user). If |
176 | | -# ``stack.sh`` is run as **root**, it automatically creates a **stack** user with |
177 | | -# sudo privileges and runs as that user. |
| 175 | +# as **root** since Apache will not serve content from **root** user). |
| 176 | +# ``stack.sh`` must not be run as **root**. It aborts and suggests one course of |
| 177 | +# action to create a suitable user account. |
178 | 178 |
|
179 | 179 | if [[ $EUID -eq 0 ]]; then |
180 | | - ROOTSLEEP=${ROOTSLEEP:-10} |
181 | 180 | echo "You are running this script as root." |
182 | | - echo "In $ROOTSLEEP seconds, we will create a user '$STACK_USER' and run as that user" |
183 | | - sleep $ROOTSLEEP |
184 | | - |
185 | | - # Give the non-root user the ability to run as **root** via ``sudo`` |
186 | | - is_package_installed sudo || install_package sudo |
187 | | - if ! getent group $STACK_USER >/dev/null; then |
188 | | - echo "Creating a group called $STACK_USER" |
189 | | - groupadd $STACK_USER |
190 | | - fi |
191 | | - if ! getent passwd $STACK_USER >/dev/null; then |
192 | | - echo "Creating a user called $STACK_USER" |
193 | | - useradd -g $STACK_USER -s /bin/bash -d $DEST -m $STACK_USER |
194 | | - fi |
195 | | - |
196 | | - echo "Giving stack user passwordless sudo privileges" |
197 | | - # UEC images ``/etc/sudoers`` does not have a ``#includedir``, add one |
198 | | - grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers || |
199 | | - echo "#includedir /etc/sudoers.d" >> /etc/sudoers |
200 | | - ( umask 226 && echo "$STACK_USER ALL=(ALL) NOPASSWD:ALL" \ |
201 | | - > /etc/sudoers.d/50_stack_sh ) |
202 | | - |
203 | | - STACK_DIR="$DEST/${TOP_DIR##*/}" |
204 | | - echo "Copying files to $STACK_DIR" |
205 | | - cp -r -f -T "$TOP_DIR" "$STACK_DIR" |
206 | | - safe_chown -R $STACK_USER "$STACK_DIR" |
207 | | - cd "$STACK_DIR" |
208 | | - if [[ "$SHELL_AFTER_RUN" != "no" ]]; then |
209 | | - exec sudo -u $STACK_USER bash -l -c "set -e; bash stack.sh; bash" |
210 | | - else |
211 | | - exec sudo -u $STACK_USER bash -l -c "set -e; source stack.sh" |
212 | | - fi |
| 181 | + echo "Cut it out." |
| 182 | + echo "Really." |
| 183 | + echo "If you need an account to run DevStack, do this (as root, heh) to create $STACK_USER:" |
| 184 | + echo "$TOP_DIR/tools/create-stack-user.sh" |
213 | 185 | exit 1 |
214 | | -else |
215 | | - # We're not **root**, make sure ``sudo`` is available |
216 | | - is_package_installed sudo || die "Sudo is required. Re-run stack.sh as root ONE TIME ONLY to set up sudo." |
217 | | - |
218 | | - # UEC images ``/etc/sudoers`` does not have a ``#includedir``, add one |
219 | | - sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers || |
220 | | - echo "#includedir /etc/sudoers.d" | sudo tee -a /etc/sudoers |
221 | | - |
222 | | - # Set up devstack sudoers |
223 | | - TEMPFILE=`mktemp` |
224 | | - echo "$STACK_USER ALL=(root) NOPASSWD:ALL" >$TEMPFILE |
225 | | - # Some binaries might be under /sbin or /usr/sbin, so make sure sudo will |
226 | | - # see them by forcing PATH |
227 | | - echo "Defaults:$STACK_USER secure_path=/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin" >> $TEMPFILE |
228 | | - chmod 0440 $TEMPFILE |
229 | | - sudo chown root:root $TEMPFILE |
230 | | - sudo mv $TEMPFILE /etc/sudoers.d/50_stack_sh |
231 | | - |
232 | | - # Remove old file |
233 | | - sudo rm -f /etc/sudoers.d/stack_sh_nova |
234 | 186 | fi |
235 | 187 |
|
| 188 | +# We're not **root**, make sure ``sudo`` is available |
| 189 | +is_package_installed sudo || install_package sudo |
| 190 | + |
| 191 | +# UEC images ``/etc/sudoers`` does not have a ``#includedir``, add one |
| 192 | +sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers || |
| 193 | + echo "#includedir /etc/sudoers.d" | sudo tee -a /etc/sudoers |
| 194 | + |
| 195 | +# Set up devstack sudoers |
| 196 | +TEMPFILE=`mktemp` |
| 197 | +echo "$STACK_USER ALL=(root) NOPASSWD:ALL" >$TEMPFILE |
| 198 | +# Some binaries might be under /sbin or /usr/sbin, so make sure sudo will |
| 199 | +# see them by forcing PATH |
| 200 | +echo "Defaults:$STACK_USER secure_path=/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin" >> $TEMPFILE |
| 201 | +chmod 0440 $TEMPFILE |
| 202 | +sudo chown root:root $TEMPFILE |
| 203 | +sudo mv $TEMPFILE /etc/sudoers.d/50_stack_sh |
| 204 | + |
| 205 | + |
236 | 206 | # Create the destination directory and ensure it is writable by the user |
237 | 207 | # and read/executable by everybody for daemons (e.g. apache run for horizon) |
238 | 208 | sudo mkdir -p $DEST |
|
0 commit comments