Skip to content

Commit

Permalink
Merge pull request #6 from grycap/repackage
Browse files Browse the repository at this point in the history
Repackage and extract some configuration variables
  • Loading branch information
dealfonso authored Apr 20, 2018
2 parents b9e62b9 + c566a13 commit 45644e5
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 30 deletions.
23 changes: 16 additions & 7 deletions INSTALL.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
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)
File renamed without changes.
File renamed without changes.
36 changes: 20 additions & 16 deletions mcc.conf → etc/mcc/mcc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,28 @@
# 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"
# * If it exists a folder named addnode.d inside the MCC_ETC_REMOTE_FOLDER, its contents will be executed AFTER adding the 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)
Expand All @@ -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
Expand All @@ -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=
10 changes: 10 additions & 0 deletions includes
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion mcc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
4 changes: 2 additions & 2 deletions operations/addnode
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion operations/create
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions package/deb/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
4 changes: 2 additions & 2 deletions platform/platform
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=1.0-beta.1
VERSION=1.0-beta.2

0 comments on commit 45644e5

Please sign in to comment.