Merge pull request #74 from vholer/master

Fix pre/post networking parts for SysV and Upstart
pull/76/head
Vlastimil Holer 8 years ago committed by GitHub
commit 3741bc7eb6

@ -113,6 +113,7 @@ else
--rpm-summary "${SUMMARY}" \
${DEPENDS:+ --depends ${DEPENDS// / --depends }} \
--replaces "${REPLACES}" \
--conflicts "${REPLACES}" \
--package "${OUT}"
fi

@ -23,19 +23,23 @@ rm -f /etc/udev/rules.d/70-persistent-net.rules
udevadm control --reload >/dev/null 2>&1 || :
# Register service
if [ -f /etc/init.d/vmcontext ]; then
if [ -d /etc/sysconfig/network-scripts ]; then
chkconfig --add vmcontext
elif [ -d /etc/network ]; then
update-rc.d vmcontext defaults 9 99
else
echo 'WARNING: Contextualization service not enabled' >&2
fi
elif [ -d /etc/systemd ]; then
if [ -f /usr/lib/systemd/system/one-context-local.service -a\
-f /usr/lib/systemd/system/one-context.service ]; then
if which systemctl >/dev/null 2>&1 && \
[ -d /etc/systemd ] && \
[ -f /usr/lib/systemd/system/one-context.service ];
then
systemctl enable one-context-local.service
systemctl enable one-context.service
fi
if [ -f /etc/init.d/one-context ]; then
if [ -d /etc/sysconfig/network-scripts ]; then
chkconfig --add one-context-local
chkconfig --add one-context
elif [ -d /etc/network ]; then
for S in one-context-local one-context; do
update-rc.d ${S} enable >/dev/null 2>&1
update-rc.d ${S} defaults >/dev/null 2>&1
done
else
echo 'WARNING: Contextualization service not enabled' >&2
fi
@ -53,19 +57,19 @@ EOT
rm -rf /etc/network/interfaces.d
# Do not reconfigure network interfaces on boot
if [ -f /etc/default/networking ]; then
if ! grep -q ^CONFIGURE_INTERFACES /etc/default/networking; then
echo 'CONFIGURE_INTERFACES=no' >> /etc/default/networking
fi
fi
# if [ -f /etc/default/networking ]; then
# if ! grep -q ^CONFIGURE_INTERFACES /etc/default/networking; then
# echo 'CONFIGURE_INTERFACES=no' >> /etc/default/networking
# fi
# fi
# Remove ttyS* from the grub
if [ -f /etc/default/grub ]; then
sed -i 's/console=ttyS0//g' /etc/default/grub
sed -i 's/console=ttyS[a-zA-Z0-9,]*//g' /etc/default/grub
fi
if [ -f /boot/grub/grub.cfg ]; then
sed -i 's/console=ttyS0//g' /boot/grub/grub.cfg
sed -i 's/console=ttyS[a-zA-Z0-9,]*//g' /boot/grub/grub.cfg
fi
fi

@ -17,8 +17,17 @@
#--------------------------------------------------------------------------- #
# 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 || :
if [ -d /etc/system/ ]; then
systemctl --no-reload disable one-context-local.service one-context.service >/dev/null 2>&1 || :
systemctl daemon-reload >/dev/null 2>&1 || :
fi
if [ -f /etc/init.d/one-context ]; then
if [ -d /etc/sysconfig/network-scripts ]; then
chkconfig --del one-context >/dev/null 2>&1 || :
chkconfig --del one-context-local >/dev/null 2>&1 || :
elif [ -d /etc/network ]; then
update-rc.d -f one-context remove >/dev/null 2>&1 || :
update-rc.d -f one-context-local remove >/dev/null 2>&1 || :
fi
fi

@ -1,10 +1,7 @@
#!/bin/bash
#
# chkconfig: 2345 9 99
# description: network reconfigure
#
# -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems #
# 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 #
@ -20,20 +17,27 @@
#--------------------------------------------------------------------------- #
### BEGIN INIT INFO
# Provides: vmcontext
# Required-Start: $all
# Provides: one-context
# Required-Start: $local_fs $network $syslog one-context-local
# Required-Stop:
# Should-Start: networking
# Should-Stop: networking
# Should-Start: $time
# Should-Stop:
# X-Start-Before: sshd
# X-Stop-After:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenNebula contextualization script
# Short-Description: OpenNebula contextualization
### END INIT INFO
. /lib/lsb/init-functions
case "$1" in
"start")
/usr/sbin/one-contextd
start)
log_daemon_msg $"Starting OpenNebula contextualization"
/usr/sbin/one-contextd network
log_end_msg $?
;;
*)
log_action_msg $"Usage: $0 {start}"
exit 2
esac

@ -0,0 +1,48 @@
#!/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. #
#--------------------------------------------------------------------------- #
# chkconfig: 2345 11 99
# description: OpenNebula contextualization
### BEGIN INIT INFO
# Provides: one-context
# Required-Start: $local_fs $network $syslog one-context-local
# Required-Stop:
# Should-Start: $time
# Should-Stop:
# X-Start-Before: sshd
# X-Stop-After:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenNebula contextualization
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
case "$1" in
start)
action $"Starting OpenNebula contextualization: " \
/usr/sbin/one-contextd network
;;
*)
echo $"Usage: $0 {start}"
exit 2
esac
exit $?

@ -1,10 +1,7 @@
#!/bin/bash
#
# chkconfig: 2345 9 99
# description: network reconfigure
#
# -------------------------------------------------------------------------- #
# Copyright 2010-2016, OpenNebula Systems #
# 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 #
@ -20,19 +17,27 @@
#--------------------------------------------------------------------------- #
### BEGIN INIT INFO
# Provides: vmcontext
# Required-Start: $all
# Provides: one-context-local
# Required-Start: $local_fs
# Required-Stop:
# Should-Start: networking
# Should-Stop: networking
# Default-Start: 2 3 4 5
# Should-Start: $time
# Should-Stop:
# X-Start-Before: $network
# X-Stop-After:
# Default-Start: S
# Default-Stop: 0 1 6
# Short-Description: OpenNebula contextualization script
# Short-Description: OpenNebula pre-networking contextualization
### END INIT INFO
case "$1" in
"start")
/usr/sbin/one-contextd
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg $"Starting OpenNebula pre-networking contextualization"
/usr/sbin/one-contextd local
log_end_msg $?
;;
*)
log_action_msg $"Usage: $0 {start}"
exit 2
esac

@ -0,0 +1,48 @@
#!/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. #
#--------------------------------------------------------------------------- #
# chkconfig: 2345 9 99
# description: OpenNebula pre-networking contextualization
### BEGIN INIT INFO
# Provides: one-context-local
# Required-Start: $local_fs
# Required-Stop:
# Should-Start: $time
# Should-Stop:
# X-Start-Before: $network
# X-Stop-After:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenNebula pre-networking contextualization
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
case "$1" in
start)
action $"Starting OpenNebula pre-networking contextualization: " \
/usr/sbin/one-contextd local
;;
*)
echo $"Usage: $0 {start}"
exit 2
esac
exit $?

@ -0,0 +1,44 @@
#!/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. #
#--------------------------------------------------------------------------- #
### BEGIN INIT INFO
# Provides: one-context-reconfigure
# Required-Start: one-context-local one-context
# Required-Stop:
# Should-Start: $time
# Should-Stop:
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: OpenNebula reconfiguration
### END INIT INFO
. /lib/lsb/init-functions
case "$1" in
start)
export TIMEOUT=0
log_daemon_msg $"Starting OpenNebula reconfiguration"
/usr/sbin/one-context-reconfigure
log_end_msg $?
;;
*)
log_action_msg $"Usage: $0 {start}"
exit 2
esac
exit $?

@ -0,0 +1,47 @@
#!/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. #
#--------------------------------------------------------------------------- #
# chkconfig: - 99 1
# description: OpenNebula reconfiguration
### BEGIN INIT INFO
# Provides: one-context-reconfigure
# Required-Start: one-context-local one-context
# Required-Stop:
# Should-Start: $time
# Should-Stop:
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: OpenNebula reconfiguration
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
case "$1" in
start)
export TIMEOUT=0
action $"Starting OpenNebula reconfiguration: " \
/usr/sbin/one-context-reconfigure
;;
*)
echo $"Usage: $0 {start}"
exit 2
esac
exit $?

@ -0,0 +1,41 @@
#!/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. #
#--------------------------------------------------------------------------- #
### BEGIN INIT INFO
# Provides: one-context-reconfigure-delayed
# Required-Start: one-context-local one-context
# Required-Stop:
# Should-Start: $time
# Should-Stop:
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: OpenNebula delayed reconfiguration
### END INIT INFO
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg $"Starting OpenNebula delayed reconfiguration"
/usr/sbin/one-context-reconfigure
log_end_msg $?
;;
*)
log_action_msg $"Usage: $0 {start}"
exit 2
esac

@ -0,0 +1,46 @@
#!/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. #
#--------------------------------------------------------------------------- #
# chkconfig: - 99 1
# description: OpenNebula delayed reconfiguration
### BEGIN INIT INFO
# Provides: one-context-reconfigure-delayed
# Required-Start: one-context-local one-context
# Required-Stop:
# Should-Start: $time
# Should-Stop:
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: OpenNebula delayed reconfiguration
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
case "$1" in
start)
action $"Starting OpenNebula reconfiguration: " \
/usr/sbin/one-context-reconfigure
;;
*)
echo $"Usage: $0 {start}"
exit 2
esac
exit $?

@ -0,0 +1,8 @@
description "OpenNebula pre-networking contextualization"
author "OpenNebula Systems <support@opennebula.systems>"
start on mounted MOUNTPOINT=/
task
exec /usr/sbin/one-contextd local

@ -0,0 +1,6 @@
description "OpenNebula delayed reconfiguration"
author "OpenNebula Systems <support@opennebula.systems>"
task
exec /usr/sbin/one-context-reconfigure

@ -0,0 +1,9 @@
description "OpenNebula reconfiguration"
author "OpenNebula Systems <support@opennebula.systems>"
task
script
export TIMEOUT=0
exec /usr/sbin/one-context-reconfigure
end script

@ -0,0 +1,8 @@
description "OpenNebula contextualization"
author "OpenNebula Systems <support@opennebula.systems>"
start on (filesystem and started rsyslog)
task
exec /usr/sbin/one-contextd network

@ -255,8 +255,6 @@ configure_network()
deactivate_network()
{
. /etc/os-release
if [ $ID = "ubuntu" ]; then
IFACES=`/sbin/ifquery --list -a`
for i in $IFACES; do
@ -265,9 +263,6 @@ deactivate_network()
/sbin/ip addr flush dev $i
fi
done
else
service networking stop
fi
}
activate_network()

@ -200,7 +200,7 @@ configure_network()
{
gen_network_configuration
if ! [ -d /run/systemd/system/ ] || [ "${COMMAND}" = 'reconfigure' ]; then
if [ "${COMMAND}" = 'reconfigure' ]; then
service network restart
fi

@ -0,0 +1,12 @@
# On NIC hogplug the delayed reconfiguration is triggered.
SUBSYSTEM=="net", ACTION=="add", \
TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service", \
RUN+="/usr/bin/timeout 5 /usr/sbin/service one-context-reconfigure-delayed start"
# When CONTEXT CD-ROM is changed, it generates 2 events. This rule takes
# every second event and triggers systemd service one-context-reconfigure.
# 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+="/usr/sbin/service one-context-reconfigure start"

@ -1,7 +0,0 @@
# 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 +0,0 @@
SUBSYSTEM=="net", ACTION=="add", RUN="/usr/sbin/one-context-reconfigure"

@ -0,0 +1,11 @@
# 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.
# 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"

@ -0,0 +1,3 @@
# On NIC hogplug the delayed reconfiguration is triggered.
SUBSYSTEM=="net", ACTION=="add", \
RUN+="/sbin/service one-context-reconfigure-delayed start"

@ -0,0 +1,15 @@
[Unit]
Description=OpenNebula pre-networking contextualization script
DefaultDependencies=no
Before=network-pre.target
Wants=network-pre.target local-fs.target dev-disk-by\x2dlabel-CONTEXT.device
After=local-fs.target 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

@ -5,6 +5,7 @@ Requisite=one-context.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/one-context-reconfigure
[Install]

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems #
@ -23,8 +23,16 @@ 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}" && \
if [ ${TIMEOUT} -gt 0 ]; then
(
set -e
sleep "${TIMEOUT}"
/usr/sbin/one-contextd all reconfigure
) &>/dev/null &
disown
else
/usr/sbin/one-contextd all reconfigure
fi
else
echo 'Contextualization must start first as a boot service' >&2
exit 1

@ -52,9 +52,21 @@ function log
echo "${2}" 2>/dev/null
if [ "$?" != "0" ]; then
if [ -S /dev/log ]; then
logger -t "${SYSLOG_TAG}" \
-p "${SYSLOG_FACILITY}.${1}" \
"${2}" 2>/dev/null
elif [ "${1}" != 'debug' ]; then
local _txt="$(date "+%b %d %T") $(hostname -s) ${SYSLOG_TAG}: ${2}"
local _log=/var/log/messages
if [ -f /var/log/syslog ]; then
_log=/var/log/syslog
fi
echo "${_txt}" >>"${_log}" 2>/dev/null
fi
fi
}

@ -48,7 +48,7 @@ case "${TARGET}" in
NAME=${NAME:-one-context}
RELSUFFIX=${RELSUFFIX:-}
TYPE=${TYPE:-deb}
TAGS=${TAGS:-deb one}
TAGS=${TAGS:-deb sysv systemd upstart one}
DEPENDS=${DEPENDS:-util-linux bind9-host cloud-utils ruby python}
REPLACES=${REPLACES:-cloud-init}
POSTIN=${POSTINST:-postinstall.one}

Loading…
Cancel
Save