parent
5d68b86ffe
commit
93cb488ffd
@ -1,2 +1,3 @@
|
|||||||
|
out/
|
||||||
*.rpm
|
*.rpm
|
||||||
*.deb
|
*.deb
|
||||||
|
@ -1,120 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# -------------------------------------------------------------------------- #
|
|
||||||
# Copyright 2010-2016, OpenNebula Systems #
|
|
||||||
# #
|
|
||||||
# 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. #
|
|
||||||
#--------------------------------------------------------------------------- #
|
|
||||||
|
|
||||||
LOCK_FILE="/var/run/one-context.lock"
|
|
||||||
CONTEXT_FILE="/tmp/context.sh"
|
|
||||||
CONTEXT_NEW="${CONTEXT_FILE}.new"
|
|
||||||
END_CONTEXT="/tmp/context.end"
|
|
||||||
|
|
||||||
function export_rc_vars
|
|
||||||
{
|
|
||||||
if [ -f $1 ] ; then
|
|
||||||
ONE_VARS=`cat $1 | egrep -e '^[a-zA-Z\-\_0-9]*=' | sed 's/=.*$//'`
|
|
||||||
|
|
||||||
. $1
|
|
||||||
|
|
||||||
for v in $ONE_VARS; do
|
|
||||||
export $v
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function execute_scripts {
|
|
||||||
SCRIPTS_DIR="/etc/one-context.d"
|
|
||||||
for script in $SCRIPTS_DIR/*; do
|
|
||||||
"$script" "$1"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function vmware_context {
|
|
||||||
if type vmtoolsd ; then
|
|
||||||
if vmtoolsd --cmd 'info-get guestinfo.opennebula.context' >/dev/null 2>&1 ; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_new_context {
|
|
||||||
CONTEXT_DEV=`blkid -l -t LABEL="CONTEXT" -o device`
|
|
||||||
if [ -e "$CONTEXT_DEV" ]; then
|
|
||||||
mount -t iso9660 -L CONTEXT -o ro /mnt
|
|
||||||
if [ -f /mnt/context.sh ]; then
|
|
||||||
cp /mnt/context.sh ${CONTEXT_NEW}
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "umount /mnt" > ${END_CONTEXT}
|
|
||||||
elif vmware_context ; then
|
|
||||||
vmtoolsd --cmd 'info-get guestinfo.opennebula.context' | \
|
|
||||||
openssl base64 -d > ${CONTEXT_NEW}
|
|
||||||
elif curl -o ${CONTEXT_NEW} http://169.254.169.254/latest/user-data ; then
|
|
||||||
echo -n ""
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_context {
|
|
||||||
if [ -s "${CONTEXT_NEW}" ]; then
|
|
||||||
diff ${CONTEXT_FILE} ${CONTEXT_NEW} >/dev/null 2>&1 && return 1
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_context {
|
|
||||||
cp ${CONTEXT_NEW} ${CONTEXT_FILE}
|
|
||||||
|
|
||||||
export_rc_vars ${CONTEXT_FILE}
|
|
||||||
execute_scripts "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
function end_context {
|
|
||||||
if [ -e "${END_CONTEXT}" ]; then
|
|
||||||
sh "${END_CONTEXT}"
|
|
||||||
rm "${END_CONTEXT}"
|
|
||||||
fi
|
|
||||||
[ -e "${CONTEXT_NEW}" ] && rm "${CONTEXT_NEW}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function acquire_lock {
|
|
||||||
while true; do
|
|
||||||
if mkdir "${LOCK_FILE}" 2>/dev/null; then
|
|
||||||
trap 'cleanup' EXIT
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function release_lock {
|
|
||||||
rm -rf "${LOCK_FILE}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanup {
|
|
||||||
end_context
|
|
||||||
release_lock
|
|
||||||
}
|
|
||||||
|
|
||||||
COMMAND="$1"
|
|
||||||
|
|
||||||
acquire_lock
|
|
||||||
|
|
||||||
get_new_context
|
|
||||||
check_context && run_context "$COMMAND"
|
|
@ -1,112 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
function set_hostname() {
|
|
||||||
hostname=$1
|
|
||||||
|
|
||||||
if [ -d /run/systemd/system/ ]; then
|
|
||||||
hostnamectl set-hostname --static "${hostname}"
|
|
||||||
else
|
|
||||||
if [ -f /etc/sysconfig/network ]; then
|
|
||||||
sed -i '/^HOSTNAME=.*$/d' /etc/sysconfig/network
|
|
||||||
echo "HOSTNAME=${hostname}" >>/etc/sysconfig/network
|
|
||||||
else
|
|
||||||
echo "${hostname}" >/etc/hostname
|
|
||||||
fi
|
|
||||||
|
|
||||||
hostname "${hostname}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_domainname() {
|
|
||||||
domain=$1
|
|
||||||
sed -i '/^domain .*/d' /etc/resolv.conf
|
|
||||||
echo "domain ${domain}" >>/etc/resolv.conf
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_first_ip() {
|
|
||||||
hostname -I | cut -d' ' -f1
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_dns_name() {
|
|
||||||
text=$(LC_ALL=C host "$1" 2>/dev/null)
|
|
||||||
[ $? = 0 ] || exit 0
|
|
||||||
[[ $text == *"has no PTR record" ]] && exit 0
|
|
||||||
name=$(echo "$text" | awk '/(has address|name pointer)/ {print $(NF)}' | sed 's/\.$//')
|
|
||||||
echo $name
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_hosts() {
|
|
||||||
ip=$1
|
|
||||||
name=$2
|
|
||||||
hostname=$3
|
|
||||||
|
|
||||||
if [ "x${hostname}" = "x${name}" ]; then
|
|
||||||
hosts="${name}"
|
|
||||||
else
|
|
||||||
hosts="${name} ${hostname}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
note='# one-contextd'
|
|
||||||
entry="${ip}\t${hosts}\t\t${note}"
|
|
||||||
|
|
||||||
# update our old entry
|
|
||||||
if grep -qi "${note}" /etc/hosts; then
|
|
||||||
sed -i -e "s/^.*${note}\$/${entry}/" /etc/hosts
|
|
||||||
# update entry with same IP (but not localhost)
|
|
||||||
elif grep -E "^${ip}\s" /etc/hosts | grep -qv localhost; then
|
|
||||||
sed -i -e "/localhost/! s/^${ip}\s.*\$/${entry}/" /etc/hosts
|
|
||||||
# update entry with same name
|
|
||||||
elif grep -qE "\s${name}(\s|#|\$)" /etc/hosts; then
|
|
||||||
sed -i -re "s/^.*\s${name}([ #\t].*|$)/${entry}/" /etc/hosts
|
|
||||||
# create new entry
|
|
||||||
elif [ -f /etc/hosts ]; then
|
|
||||||
sed -i -e "1s/^/${entry}\n/" /etc/hosts
|
|
||||||
else
|
|
||||||
echo -e "${entry}" >>/etc/hosts
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#####
|
|
||||||
|
|
||||||
first_ip=$(get_first_ip)
|
|
||||||
|
|
||||||
if [ -n "$SET_HOSTNAME" ]; then
|
|
||||||
name=$(echo "$SET_HOSTNAME" | \
|
|
||||||
sed -e 's/[^-a-zA-Z0-9\.]/-/g' -e 's/^-*//g' -e 's/-*$//g')
|
|
||||||
elif [ -n "$DNS_HOSTNAME" ]; then
|
|
||||||
name=$(get_dns_name "${first_ip}")
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${name}" ]; then
|
|
||||||
# split host and domain names
|
|
||||||
hostname=${name%%.*}
|
|
||||||
domain=${name#*.}
|
|
||||||
if [ "x${domain}" = "x${hostname}" ]; then
|
|
||||||
domain=''
|
|
||||||
fi
|
|
||||||
|
|
||||||
set_hostname "${hostname}"
|
|
||||||
if [ -n "${domain}" ]; then
|
|
||||||
set_domainname "${domain}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${DNS_HOSTNAME}" ]; then
|
|
||||||
host_ip=$first_ip
|
|
||||||
else
|
|
||||||
# If selected hostname resolves on first IP,
|
|
||||||
# use first IP for local hostname in /etc/hosts.
|
|
||||||
# Otherwise use loopback IP.
|
|
||||||
name_ip=$(get_dns_name "${name}")
|
|
||||||
if [ "x${first_ip}" = "x${name_ip}" ]; then
|
|
||||||
host_ip=$first_ip
|
|
||||||
elif [ -f /etc/debian_version ]; then
|
|
||||||
host_ip='127.0.1.1'
|
|
||||||
else
|
|
||||||
host_ip='127.0.0.1'
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${host_ip}" ]; then
|
|
||||||
update_hosts "${host_ip}" "${name}" "${hostname}"
|
|
||||||
fi
|
|
||||||
fi
|
|
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------- #
|
||||||
|
# Copyright 2010-2017, OpenNebula Systems #
|
||||||
|
# #
|
||||||
|
# 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. #
|
||||||
|
#--------------------------------------------------------------------------- #
|
||||||
|
|
||||||
|
# Unregister service
|
||||||
|
if [ -d /run/systemd/system/ ]; then
|
||||||
|
/bin/systemctl --no-reload disable one-context-local.service one-context.service >/dev/null 2>&1 || :
|
||||||
|
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
|
||||||
|
fi
|
||||||
|
|
@ -0,0 +1,7 @@
|
|||||||
|
# On NIC hogplug the delayed reconfiguration is triggered.
|
||||||
|
SUBSYSTEM=="net", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service"
|
||||||
|
|
||||||
|
# When CONTEXT CD-ROM is changed, it generates 2 events. This rule takes
|
||||||
|
# every second event and triggers systemd service one-context-reconfigure-now.
|
||||||
|
# This service also stops any existing delayed reconfiguration.
|
||||||
|
SUBSYSTEM=="block", ACTION=="change", ENV{ID_FS_TYPE}=="iso9660" ENV{ID_FS_LABEL_ENC}=="CONTEXT", ENV{SEQNUM}=="*[02468]" RUN+="/bin/systemctl start one-context-reconfigure.service"
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
ENV_FILE=/tmp/one_env
|
ENV_FILE=/var/run/one-context/one_env
|
||||||
|
|
||||||
if [ -f $ENV_FILE ]; then
|
if [ -f $ENV_FILE ]; then
|
||||||
. $ENV_FILE
|
. $ENV_FILE
|
@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenNebula pre-networking contextualization script
|
||||||
|
Before=network-pre.target
|
||||||
|
Wants=network-pre.target dev-disk-by\x2dlabel-CONTEXT.device
|
||||||
|
After=dev-disk-by\x2dlabel-CONTEXT.device
|
||||||
|
ConditionPathExists=!/var/run/one-context/context.sh.local
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
|
ExecStart=/usr/sbin/one-contextd local
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenNebula delayed reconfiguration script
|
||||||
|
After=one-context.service
|
||||||
|
Requisite=one-context.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/sbin/one-context-reconfigure
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenNebula reconfiguration script
|
||||||
|
After=one-context.service
|
||||||
|
Requisite=one-context.service
|
||||||
|
Conflicts=one-context-reconfigure-delayed.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
Environment=TIMEOUT=0
|
||||||
|
ExecStart=/usr/sbin/one-context-reconfigure
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenNebula contextualization script
|
||||||
|
Requires=one-context-local.service
|
||||||
|
After=multi-user.target one-context-local.service
|
||||||
|
ConditionPathExists=!/var/run/one-context/context.sh.network
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
|
ExecStart=/usr/sbin/one-contextd network
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------- #
|
||||||
|
# Copyright 2010-2017, OpenNebula Systems #
|
||||||
|
# #
|
||||||
|
# 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. #
|
||||||
|
#--------------------------------------------------------------------------- #
|
||||||
|
|
||||||
|
# Set PATH
|
||||||
|
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
||||||
|
|
||||||
|
TIMEOUT=${TIMEOUT:-60}
|
||||||
|
CONTEXT_BASE=${CONTEXT_BASE:-/var/run/one-context/context.sh}
|
||||||
|
|
||||||
|
if [ -f ${CONTEXT_BASE}.local ] && [ -f ${CONTEXT_BASE}.network ]; then
|
||||||
|
sleep "${TIMEOUT}" && \
|
||||||
|
/usr/sbin/one-contextd all reconfigure
|
||||||
|
else
|
||||||
|
echo 'Contextualization must start first as a boot service' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
@ -0,0 +1,242 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------- #
|
||||||
|
# Copyright 2010-2017, OpenNebula Systems #
|
||||||
|
# #
|
||||||
|
# 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. #
|
||||||
|
#--------------------------------------------------------------------------- #
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
TYPE="${1:-all}" # local, network, all
|
||||||
|
COMMAND="${2}" # reconfigure?
|
||||||
|
|
||||||
|
SCRIPTS_DIR=${SCRIPTS_DIR:-/etc/one-context.d}
|
||||||
|
RUNTIME_DIR=${RUNTIME_DIR:-/var/run/one-context}
|
||||||
|
LOCK_FILE="${RUNTIME_DIR}/one-context.lock"
|
||||||
|
CONTEXT_BASE="${RUNTIME_DIR}/context.sh"
|
||||||
|
SYSLOG_TAG="$(basename $0)"
|
||||||
|
|
||||||
|
[ -d "${RUNTIME_DIR}" ] || mkdir -m 0700 -p "${RUNTIME_DIR}"
|
||||||
|
CONTEXT_NEW=$(mktemp "${CONTEXT_BASE}.XXXX" 2>/dev/null)
|
||||||
|
SYSLOG_FACILITY="${SYSLOG_FACILITY:-local3}"
|
||||||
|
|
||||||
|
shopt -s extglob
|
||||||
|
set +e
|
||||||
|
|
||||||
|
|
||||||
|
function log
|
||||||
|
{
|
||||||
|
# display on stdout/err?, force if DEBUG
|
||||||
|
local _echo_fd=$3
|
||||||
|
if [ -n "${DEBUG}" ] && [ "${_echo_fd}" = '' ]; then
|
||||||
|
_echo_fd=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${_echo_fd}" = '1' ] || [ "${_echo_fd}" = '2' ]; then
|
||||||
|
echo "${2}" >&${_echo_fd}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# try systemd/journald with fallback to logger
|
||||||
|
systemd-cat -t "${SYSLOG_TAG}" -p "${1}" \
|
||||||
|
echo "${2}" 2>/dev/null
|
||||||
|
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
logger -t "${SYSLOG_TAG}" \
|
||||||
|
-p "${SYSLOG_FACILITY}.${1}" \
|
||||||
|
"${2}" 2>/dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function export_rc_vars
|
||||||
|
{
|
||||||
|
if [ -f $1 ] ; then
|
||||||
|
ONE_VARS=$(cat $1 | egrep -e '^[a-zA-Z\-\_0-9]*=' | sed 's/=.*$//')
|
||||||
|
|
||||||
|
. $1
|
||||||
|
|
||||||
|
for v in $ONE_VARS; do
|
||||||
|
export $v
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function execute_scripts {
|
||||||
|
local _type=$1
|
||||||
|
local _command=$1
|
||||||
|
|
||||||
|
# choose
|
||||||
|
if [ "${_type}" = 'local' ]; then
|
||||||
|
local _scripts=$(ls ${SCRIPTS_DIR}/loc-* 2>/dev/null)
|
||||||
|
elif [ "${_type}" = 'network' ]; then
|
||||||
|
local _scripts=$(ls ${SCRIPTS_DIR}/!(net-*|loc-*) 2>/dev/null; \
|
||||||
|
ls ${SCRIPTS_DIR}/net-* 2>/dev/null)
|
||||||
|
fi
|
||||||
|
|
||||||
|
export MOUNT_DIR
|
||||||
|
export RUNTIME_DIR
|
||||||
|
|
||||||
|
log info "Processing ${_type} scripts"
|
||||||
|
for _script in ${_scripts}; do
|
||||||
|
local _name=$(basename "${_script}")
|
||||||
|
|
||||||
|
# run script and catch output and exit code
|
||||||
|
log debug "Script ${_name}: Starting ..."
|
||||||
|
_out=$("${_script}" "${_command}" 2>&1)
|
||||||
|
local _rtn=$?
|
||||||
|
|
||||||
|
# log on any output
|
||||||
|
if [ -n "${_out}" ]; then
|
||||||
|
log info "Script ${_name} output: ${_out}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# set log level to error if script failed
|
||||||
|
if [ ${_rtn} -eq 0 ]; then
|
||||||
|
local _level=debug
|
||||||
|
else
|
||||||
|
local _level=err
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "${_level}" "Script ${_name}: Finished with exit code ${_rtn}"
|
||||||
|
done
|
||||||
|
log debug 'Finished scripts processing'
|
||||||
|
}
|
||||||
|
|
||||||
|
function vmware_context {
|
||||||
|
if type vmtoolsd >/dev/null 2>&1; then
|
||||||
|
if vmtoolsd --cmd 'info-get guestinfo.opennebula.context' >/dev/null 2>&1 ; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
log debug "VMware ONE context not found"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
log debug "Command vmtoolsd not found"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_new_context {
|
||||||
|
local dev_context=$(blkid -l -t LABEL="CONTEXT" -o device)
|
||||||
|
if [ -e "${dev_context}" ]; then
|
||||||
|
MOUNT_DIR=$(mktemp -d "${RUNTIME_DIR}/mount.XXXX" 2>/dev/null)
|
||||||
|
if ! [ -d "${MOUNT_DIR}" ]; then
|
||||||
|
log err 'Error: Failed to create mountpoint' 2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log debug "Mounting CD-ROM ${dev_context} on ${MOUNT_DIR}"
|
||||||
|
mount -t iso9660 -o ro ${dev_context} ${MOUNT_DIR} 2>/dev/null
|
||||||
|
if [ "$?" != '0' ]; then
|
||||||
|
log err "Error: Failed to mount ${dev_context}" 2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local fn_mnt_context="${MOUNT_DIR}/context.sh"
|
||||||
|
if [ -f "${fn_mnt_context}" ]; then
|
||||||
|
log debug "Found context ${fn_mnt_context}"
|
||||||
|
cp "${fn_mnt_context}" "${CONTEXT_NEW}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif vmware_context ; then
|
||||||
|
log debug "Reading context via vmtoolsd"
|
||||||
|
vmtoolsd --cmd 'info-get guestinfo.opennebula.context' | \
|
||||||
|
openssl base64 -d > ${CONTEXT_NEW}
|
||||||
|
|
||||||
|
elif curl -s -o ${CONTEXT_NEW} http://169.254.169.254/latest/user-data; then
|
||||||
|
log debug "Reading EC2 user-data"
|
||||||
|
echo -n ""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_context {
|
||||||
|
local _f_new=$1
|
||||||
|
local _f_old=$2
|
||||||
|
local _rtn=1
|
||||||
|
|
||||||
|
log debug "Comparing ${_f_new} and ${_f_old} for changes"
|
||||||
|
if [ -s "${_f_new}" ]; then
|
||||||
|
diff "${_f_old}" "${_f_new}" >/dev/null 2>&1 || _rtn=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${_rtn} -eq 0 ]; then
|
||||||
|
log debug "New context with changes"
|
||||||
|
else
|
||||||
|
log info "No changes in context, skipping"
|
||||||
|
fi
|
||||||
|
|
||||||
|
return ${_rtn}
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_context {
|
||||||
|
local _type=$1
|
||||||
|
local _command=$2
|
||||||
|
|
||||||
|
export CONTEXT_FILE="${CONTEXT_BASE}.${_type}"
|
||||||
|
if check_context "${CONTEXT_NEW}" "${CONTEXT_FILE}"; then
|
||||||
|
cp -f "${CONTEXT_NEW}" "${CONTEXT_FILE}"
|
||||||
|
export_rc_vars "${CONTEXT_FILE}"
|
||||||
|
execute_scripts "${_type}" "${_command}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function acquire_lock {
|
||||||
|
# acquire for execution lock
|
||||||
|
log debug "Acquiring lock ${LOCK_FILE}"
|
||||||
|
while true; do
|
||||||
|
if mkdir "${LOCK_FILE}" 2>/dev/null; then
|
||||||
|
trap 'cleanup' EXIT
|
||||||
|
log debug "Acquired lock ${LOCK_FILE}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanup {
|
||||||
|
# unmount context
|
||||||
|
if [ -d "${MOUNT_DIR}" ]; then
|
||||||
|
log debug "Unmounting ${MOUNT_DIR}"
|
||||||
|
umount -l "${MOUNT_DIR}"
|
||||||
|
rmdir "${MOUNT_DIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# remove remporary files
|
||||||
|
if [ -f "${CONTEXT_NEW}" ]; then
|
||||||
|
unlink "${CONTEXT_NEW}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# remove lock
|
||||||
|
log debug "Releasing lock ${LOCK_FILE}"
|
||||||
|
rm -rf "${LOCK_FILE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
#####
|
||||||
|
|
||||||
|
if ! [[ ${TYPE} =~ ^(local|network|all)$ ]]; then
|
||||||
|
log err "Error: Invalid or missing execution type ${TYPE}" 2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log info "Started ${TYPE:+for type $TYPE} ${COMMAND:+to $COMMAND}"
|
||||||
|
acquire_lock
|
||||||
|
get_new_context
|
||||||
|
|
||||||
|
if [ "${TYPE}" = 'all' ]; then
|
||||||
|
run_context 'local' "${COMMAND}"
|
||||||
|
run_context 'network' "${COMMAND}"
|
||||||
|
else
|
||||||
|
run_context "${TYPE}" "${COMMAND}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
log info "Done"
|
@ -0,0 +1,78 @@
|
|||||||
|
case "${TARGET}" in
|
||||||
|
'el6')
|
||||||
|
NAME=${NAME:-one-context}
|
||||||
|
RELSUFFIX=${RELSUFFIX:-.el6}
|
||||||
|
TYPE=${TYPE:-rpm}
|
||||||
|
TAGS=${TAGS:-rpm sysv one}
|
||||||
|
DEPENDS=${DEPENDS:-util-linux-ng bind-utils cloud-utils-growpart ruby rubygem-json}
|
||||||
|
REPLACES=${REPLACES:-cloud-init}
|
||||||
|
POSTIN=${POSTINST:-postinstall.one}
|
||||||
|
PREUN=${PREUN:-preuninstall.one}
|
||||||
|
;;
|
||||||
|
|
||||||
|
|
||||||
|
'el6_ec2')
|
||||||
|
NAME=${NAME:-one-context-ec2}
|
||||||
|
RELSUFFIX=${RELSUFFIX:-.el6}
|
||||||
|
TYPE=${TYPE:-rpm}
|
||||||
|
TAGS=${TAGS:-rpm sysv ec2}
|
||||||
|
DEPENDS=${DEPENDS:-util-linux-ng bind-utils cloud-utils-growpart ruby rubygem-json}
|
||||||
|
REPLACES=${REPLACES:-cloud-init}
|
||||||
|
POSTIN=${POSTINST:-postinstall.ec2}
|
||||||
|
PREUN=${PREUN:-preuninstall.ec2}
|
||||||
|
;;
|
||||||
|
|
||||||
|
'el7')
|
||||||
|
NAME=${NAME:-one-context}
|
||||||
|
RELSUFFIX=${RELSUFFIX:-.el7}
|
||||||
|
TYPE=${TYPE:-rpm}
|
||||||
|
TAGS=${TAGS:-rpm systemd one}
|
||||||
|
DEPENDS=${DEPENDS:-util-linux bind-utils cloud-utils-growpart ruby rubygem-json}
|
||||||
|
REPLACES=${REPLACES:-cloud-init}
|
||||||
|
POSTIN=${POSTINST:-postinstall.one}
|
||||||
|
PREUN=${PREUN:-preuninstall.one}
|
||||||
|
;;
|
||||||
|
|
||||||
|
'el7_ec2')
|
||||||
|
NAME=${NAME:-one-context-ec2}
|
||||||
|
RELSUFFIX=${RELSUFFIX:-.el7}
|
||||||
|
TYPE=${TYPE:-rpm}
|
||||||
|
TAGS=${TAGS:-rpm sysv ec2}
|
||||||
|
DEPENDS=${DEPENDS:-util-linux bind-utils cloud-utils-growpart ruby rubygem-json}
|
||||||
|
REPLACES=${REPLACES:-cloud-init}
|
||||||
|
POSTIN=${POSTINST:-postinstall.ec2}
|
||||||
|
PREUN=${PREUN:-preuninstall.ec2}
|
||||||
|
;;
|
||||||
|
|
||||||
|
'deb')
|
||||||
|
NAME=${NAME:-one-context}
|
||||||
|
RELSUFFIX=${RELSUFFIX:-}
|
||||||
|
TYPE=${TYPE:-deb}
|
||||||
|
TAGS=${TAGS:-deb one}
|
||||||
|
DEPENDS=${DEPENDS:-util-linux bind9-host cloud-utils ruby python}
|
||||||
|
REPLACES=${REPLACES:-cloud-init}
|
||||||
|
POSTIN=${POSTINST:-postinstall.one}
|
||||||
|
PREUN=${PREUN:-preuninstall.one}
|
||||||
|
;;
|
||||||
|
|
||||||
|
'deb_ec2')
|
||||||
|
NAME=${NAME:-one-context-ec2}
|
||||||
|
RELSUFFIX=${RELSUFFIX:-}
|
||||||
|
TYPE=${TYPE:-deb}
|
||||||
|
TAGS=${TAGS:-deb ec2}
|
||||||
|
DEPENDS=${DEPENDS:-util-linux bind9-host cloud-utils ruby python}
|
||||||
|
REPLACES=${REPLACES:-cloud-init}
|
||||||
|
POSTIN=${POSTINST:-postinstall.ec2}
|
||||||
|
PREUN=${PREUN:-preuninstall.ec2}
|
||||||
|
;;
|
||||||
|
|
||||||
|
'arch')
|
||||||
|
NAME=${NAME:-one-context}
|
||||||
|
TYPE=${TYPE:-dir}
|
||||||
|
TAGS=${TAGS:-arch one}
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Invalid target ${TARGET}"
|
||||||
|
exit 1
|
||||||
|
esac
|
Loading…
Reference in new issue