16127335f4
Add the '-1' parameter to lxc-ls so each container is listed on a single line, otherwise multiple container names were being listed on a single line and causing the command to fail when in a tty. Also use the '--filter' parameter to return only the utility containers rather than having lxc-ls process and return each container. Change-Id: Ifcf1f13392d17464a088ce2928f434387ca39365
57 lines
1.6 KiB
Bash
Executable File
57 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Copyright 2016, Rackspace US, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
# What this script is for:
|
|
# This script runs the supplied commands in the utility container on
|
|
# localhost. It simplifies performing actions from the utility
|
|
# container. It's most useful for use with an AIO installation.
|
|
|
|
__check_cmd_avail ()
|
|
{
|
|
if [ "z$(which $1)" == "z" ]; then
|
|
echo "The command '$1' could not be found, exiting"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Make sure we're running as root
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "This script must be run as root. Exiting..." 2>&1
|
|
exit 1
|
|
fi
|
|
|
|
# Ensure a command was provided
|
|
if [ $# -eq 0 ]; then
|
|
echo "Usage: $(basename $0) <command>"
|
|
exit 1
|
|
fi
|
|
|
|
LXCATTACH="lxc-attach"
|
|
LXCLS="lxc-ls"
|
|
|
|
# Verify we have the commands we need
|
|
__check_cmd_avail ${LXCATTACH}
|
|
__check_cmd_avail ${LXCLS}
|
|
|
|
# Find the first utility container to execute in
|
|
UTIL=$(${LXCLS} -1 --filter utility | head -n 1)
|
|
if [ "z${UTIL}" == "z" ]; then
|
|
echo "*** Couldn't find a utility container. Exiting..."
|
|
exit 1
|
|
fi
|
|
|
|
${LXCATTACH} -n ${UTIL} -- bash -c ". /root/openrc && $*"
|