diff --git a/INSTALL.sh b/INSTALL.sh index d7aaf30..c5ba0f9 100755 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -27,17 +27,21 @@ mkdir -p "${PREFIX}/usr/bin" mkdir -p "${PREFIX}/$INSTALLDIR" mkdir -p "${PREFIX}/etc/mcc" -APPFILES="context/alpine context/front-end context/mcc context/ubuntu includes lib operations platform README.md version LICENSE" +APPFILES="includes lib operations platform README.md version LICENSE context/mcc" for i in $APPFILES; do - cp -r "$SRCFOLDER/$i" "${PREFIX}/$INSTALLDIR/$(dirname $i)" + D="${PREFIX}/$INSTALLDIR/$(dirname $i)" + mkdir -p "$D" + cp -r "$SRCFOLDER/$i" "$D" done for i in mcc; do cp -r "$SRCFOLDER/$i" "${PREFIX}/usr/bin" done -for i in mcc.conf; do - cp -r "$SRCFOLDER/$i" "${PREFIX}/etc/mcc" +for i in etc/mcc/mcc.conf etc/bash_completion.d etc/mcc/context/front-end etc/mcc/context/working-node; do + D="${PREFIX}/$(dirname $i)" + mkdir -p "$D" + cp -r "$SRCFOLDER/$i" "$D" done cat >> "${PREFIX}/etc/mcc/mcc.conf" << EOF @@ -46,8 +50,13 @@ MCC_FOLDER="$INSTALLDIR" EOF chmod 755 ${PREFIX}/usr/bin/* -chmod 755 ${PREFIX}/etc/mcc -chmod 644 ${PREFIX}/etc/mcc/* +chmod 755 ${PREFIX}/etc +chmod 755 $(find ${PREFIX}/etc/ -type d) +chmod 644 $(find ${PREFIX}/etc/ ! -type d) chmod 755 ${PREFIX}/$INSTALLDIR chmod 755 $(find ${PREFIX}/$INSTALLDIR/ -type d) -chmod 644 $(find ${PREFIX}/$INSTALLDIR/ ! -type d) \ No newline at end of file +chmod 644 $(find ${PREFIX}/$INSTALLDIR/ ! -type d) + +# Adjust permissions for execution +chmod 755 $(find ${PREFIX}/etc/mcc/context -type f) +chmod 755 $(find ${PREFIX}/$INSTALLDIR/context -type f) \ No newline at end of file diff --git a/bash_completion.d/mcc b/etc/bash_completion.d/mcc similarity index 100% rename from bash_completion.d/mcc rename to etc/bash_completion.d/mcc diff --git a/context/front-end/contextnode.d/10keys b/etc/mcc/context/front-end/contextnode.d/10keys similarity index 100% rename from context/front-end/contextnode.d/10keys rename to etc/mcc/context/front-end/contextnode.d/10keys diff --git a/mcc.conf b/etc/mcc/mcc.conf similarity index 76% rename from mcc.conf rename to etc/mcc/mcc.conf index 20ba796..740b5e4 100644 --- a/mcc.conf +++ b/etc/mcc/mcc.conf @@ -20,15 +20,21 @@ # COMMON - general variables: path, etc. # Commandline to access to the lxd daemon -# This is the lxd socket if LXD is installed using snap -LXD_SOCKET=/var/snap/lxd/common/lxd/unix.socket -# This is the lxd socket if LXD is installed from the repositories -LXD_SOCKET=/var/lib/lxd/unix.socket +# This is the lxd socket of the server. It is useful to build the default CURL_CMD command. +# The socket if LXD is installed from snap +# LXD_SOCKET=/var/snap/lxd/common/lxd/unix.socket +# The lxd socket if LXD is installed from the repositories (default value) +# LXD_SOCKET=/var/lib/lxd/unix.socket +LXD_SOCKET=${LXD_SOCKET:-/var/lib/lxd/unix.socket} -# Basic command to access the LXD daemon -CURL_CMD="curl -sf --unix-socket $LXD_SOCKET http:" -# MCC path where the basic contextualizacion for the front-end is stored (e.g. creation of shared keys for passwordless ssh) -MCC_FRONTEND_CONTEXT="$(dirname $0)/context/front-end" +# Basic command to access the LXD daemon. You can define your own command in case that you can access a remote server +# (if not defined, it will get the following value) +# CURL_CMD="curl -sf --unix-socket $LXD_SOCKET http:" + +# The default image for the front-end +MCC_DEFAULT_IMAGE_FRONTEND=ubuntu: +# The default image for the working nodes +MCC_DEFAULT_IMAGE_WN=ubuntu: # Names of the executables that will be executed on each corresponding action (i.e. launch the node, add a node to the cluster, remove a node from the cluster) # * If it exists a folder named contextnode.d inside the MCC_ETC_REMOTE_FOLDER, its contents will be executed just after the container has been launched MCC_SCRIPT_CONTEXT="context-node" @@ -36,8 +42,6 @@ MCC_SCRIPT_CONTEXT="context-node" MCC_SCRIPT_ADDNODE="add-node" # * If it exists a folder named removenode.d inside the MCC_ETC_REMOTE_FOLDER, its contents will be executed BEFORE removing the node MCC_SCRIPT_REMOVENODE="remove-node" -# Local path where the previous files are stored -MCC_LOCAL_FOLDER="$(dirname $0)/context/mcc" # Path in the container where the previous files are stored (in the container) MCC_REMOTE_FOLDER="/opt/context/mcc" # Path in the container where the contextualization scripts will be stored (those that will be executed on the creation of the node) @@ -53,9 +57,9 @@ MCC_SHELLS="bash sh" # DEVICES - devices-related variables # Path where the devices shared folders will be stored (in this path, MCC will create a folder per each cluster that needs a shared folder) -MCC_SHAREDFOLDER_PATH=/var/tmp/mcc +MCC_SHAREDFOLDER_PATH=$HOME/.mcc/var/tmp/mcc # Path where the description of the devices will be stored (in this path, MCC will create a folder per each cluster that needs devices) -MCC_DEVICES_FOLDER_PATH=/var/tmp/mcc +MCC_DEVICES_FOLDER_PATH=$HOME/.mcc/var/tmp/mcc # Path where the file that describes the devices is stored in the container MCC_DEVICES_REMOTE_FOLDER_PATH=/etc/mcc/devices/ # Base filename for the devices filename. The name convention will be ${MCC_DEVICES_FILE}.nodename @@ -65,11 +69,11 @@ MCC_DEVICES_FILE=devices MCC_DEVICES_SHAREDFOLDER_REMAP_PERMISSIONS=True # Platform +# Seconds that MCC will wait for the container to get a IP address +MCC_RETRIES_WAIT_IP=60 +LXC_PROFILE="${LXC_PROFILE:-"mcc-default"}" # Additional options to the lxc commandline to launch a container -# * this is specially useful to include the profile to be used (e.g. the default profile already has a NIC that will not be useful for us -# because we want our FIRST NIC to connect then cluster) -# In order to be easier to launch containers, I enable to get the options from a variable in env -LXC_LAUNCH_OPTS=${MCC_LXC_LAUNCH_OPTS:-""} +LXC_LAUNCH_OPTS= # Additional options to be included when creating a network (is of special interest to attach to specific bridges) LXC_NETWORK_CREATE_OPTS= diff --git a/includes b/includes index 9452141..41a7e38 100644 --- a/includes +++ b/includes @@ -21,6 +21,16 @@ [ "$__INCLUDES_INCLUDED__" != "" ] && return __INCLUDES_INCLUDED__=True +# MCC path where the default contextualizacion for the front-end and working-nodes are stored (e.g. creation of shared keys for passwordless ssh) +MCC_FRONTEND_CONTEXT="${MCC_ETC_FOLDER}/context/front-end" +MCC_WN_CONTEXT="${MCC_ETC_FOLDER}/context/working-node" + +# Command to contact the LXD daemon +CURL_CMD="${CURL_CMD:-curl -sf --unix-socket $LXD_SOCKET http:}" + +# Local path where the previous files are stored +MCC_LOCAL_FOLDER="${MCC_FOLDER}/context/mcc" + source "$MCC_FOLDER/version" source "$MCC_FOLDER/lib/common" source_folder "$MCC_FOLDER/operations" diff --git a/mcc b/mcc index 1f58f74..19b3ab0 100755 --- a/mcc +++ b/mcc @@ -19,8 +19,9 @@ # limitations under the License. # +MCC_ETC_FOLDER=/etc/mcc # File in which is stored specific for the global system -MCC_ETC_CONFIG=/etc/mcc/mcc.conf +MCC_ETC_CONFIG="${MCC_ETC_FOLDER}/mcc.conf" # File in which is stored the user specific configuration MCC_ETC_USER="${HOME}/.mcc/mcc.conf" # Specific configuration in current folder @@ -137,6 +138,13 @@ done # If the dependencies are not met, we will exit check_dependencies || exit -1 +lxc profile show "$LXC_PROFILE" > /dev/null 2> /dev/null +if [ $? -ne 0 ]; then + p_error "profile $LXC_PROFILE does not exist in lxc (command failed: lxc profile show $LXC_PROFILE)" + exit 1 +fi +LXC_LAUNCH_OPTS="${LXC_LAUNCH_OPTS} -p $LXC_PROFILE" + # Finally execute the proper command if [ "$COMMAND" != "" ]; then $COMMAND "${ARR[@]:$n}" diff --git a/operations/addnode b/operations/addnode index 357e646..f5726b2 100644 --- a/operations/addnode +++ b/operations/addnode @@ -50,7 +50,7 @@ function generate_new_node_id() { function addnode() { local CLUSTERNAME= local NODECOUNT=1 - local WNIMAGE=local:alpine + local WNIMAGE="${MCC_DEFAULT_IMAGE_WN}" local CONTEXTFOLDERWN local ENTER=False local DEVICES= @@ -141,7 +141,7 @@ function addnode() { _MCC__devices_prepare "$NODENAME" "$DEVICES" || return 4 # Finally we will launch the container - if ! _MCC__launch_container "$NODENAME" "$WNIMAGE" "$CONTEXTFOLDERWN"; then + if ! _MCC__launch_container "$NODENAME" "$WNIMAGE" "$MCC_WN_CONTEXT" "$CONTEXTFOLDERWN"; then p_error "failed to launch node $NODENAME ($?)" return 5 fi diff --git a/operations/create b/operations/create index 01ce9e5..0339637 100644 --- a/operations/create +++ b/operations/create @@ -21,7 +21,7 @@ function create() { local NODECOUNT=0 - local FRONTENDIMAGE=local:alpine + local FRONTENDIMAGE="${MCC_DEFAULT_IMAGE_FRONTEND}" local WNIMAGE local CLUSTERNAME local NETWORKNAME diff --git a/package/deb/create.sh b/package/deb/create.sh index ec0526f..af401ec 100755 --- a/package/deb/create.sh +++ b/package/deb/create.sh @@ -61,6 +61,51 @@ Description: MCC - My Container Cluster It is very useful for cluster testing and prototyping. EOF +cat > "${FNAME}/DEBIAN/postinst" <<\EOF +#!/bin/sh +lxc profile show mcc-default > /dev/null 2> /dev/null +if [ $? -ne 0 ]; then + lxc profile create mcc-default + if [ $? -ne 0 ]; then + echo "could not create default profile in lxc" 2>&1 + exit 1 + fi + lxc profile edit mcc-default <<\EOT +config: + environment.http_proxy: "" + user.network_mode: "" +description: default profile for mcc +devices: + root: + path: / + pool: default + type: disk +EOT + if [ $? -ne 0 ]; then + echo "failed to update the default profile in lxc" 2>&1 + lxc profile delete mcc-default + exit 1 + fi +fi +exit 0 +EOF + +cat > "${FNAME}/DEBIAN/postrm" <<\EOF +#!/bin/sh +lxc profile show mcc-default > /dev/null 2> /dev/null +if [ $? -eq 0 ]; then + lxc profile delete mcc-default +fi +exit 0 +EOF + +chmod +x "${FNAME}/DEBIAN/postinst" +chmod +x "${FNAME}/DEBIAN/postrm" + +cat > "${FNAME}/DEBIAN/conffiles" <<\EOF +/etc/mcc/mcc.conf +EOF + cd "${FNAME}" find . -type f ! -regex '.*.hg.*' ! -regex '.*?debian-binary.*' ! -regex '.*?DEBIAN.*' -printf "%P " | xargs md5sum > "DEBIAN/md5sums" cd - diff --git a/platform/platform b/platform/platform index 80e6807..3163058 100755 --- a/platform/platform +++ b/platform/platform @@ -52,7 +52,7 @@ function _MCC__wait_ip_address() { local C_IP # * cannot use output_to_var_or_fail because of the blank parameters - C_IP=$(retry_while 10 1 "" _NETWORK__get_node_ip "$C_NAME" "$C_NETWORK") + C_IP=$(retry_while $MCC_RETRIES_WAIT_IP 1 "" _NETWORK__get_node_ip "$C_NAME" "$C_NETWORK") if (($?!=0)); then p_error "could not get IP address for container $C_NAME" if _NETWORK__node_has_ip "$C_NAME"; then @@ -265,7 +265,7 @@ function _CONTAINER__launch() { p_debug "container $C_NAME successfully launched" # As we are using ephemeral containers, we do not need to delete them _UNDO__add_undo_cmdline lxc stop "$C_NAME" - _UNDO__add_undo_cmdline lxc delete "$C_NAME" + _UNDO__add_undo_cmdline lxc delete --force "$C_NAME" return 0 else return 4 diff --git a/version b/version index f3564d5..9d2137f 100644 --- a/version +++ b/version @@ -1 +1 @@ -VERSION=1.0-beta.1 \ No newline at end of file +VERSION=1.0-beta.2 \ No newline at end of file