Fix pre/post networking parts for SysV and Upstart

pull/74/head
Vlastimil Holer 8 years ago
parent 407b35c2e3
commit f5c28e896c
No known key found for this signature in database
GPG Key ID: EB549BADEFD07C53

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

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

@ -17,8 +17,17 @@
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
# Unregister service # Unregister service
if [ -d /run/systemd/system/ ]; then if [ -d /etc/system/ ]; then
/bin/systemctl --no-reload disable one-context-local.service one-context.service >/dev/null 2>&1 || : systemctl --no-reload disable one-context-local.service one-context.service >/dev/null 2>&1 || :
/bin/systemctl daemon-reload >/dev/null 2>&1 || : systemctl daemon-reload >/dev/null 2>&1 || :
fi 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 #!/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 # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -20,20 +17,27 @@
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
### BEGIN INIT INFO ### BEGIN INIT INFO
# Provides: vmcontext # Provides: one-context
# Required-Start: $all # Required-Start: $local_fs $network $syslog one-context-local
# Required-Stop: # Required-Stop:
# Should-Start: networking # Should-Start: $time
# Should-Stop: networking # Should-Stop:
# X-Start-Before: sshd
# X-Stop-After:
# Default-Start: 2 3 4 5 # Default-Start: 2 3 4 5
# Default-Stop: 0 1 6 # Default-Stop: 0 1 6
# Short-Description: OpenNebula contextualization script # Short-Description: OpenNebula contextualization
### END INIT INFO ### END INIT INFO
. /lib/lsb/init-functions
case "$1" in case "$1" in
"start") start)
/usr/sbin/one-contextd log_daemon_msg $"Starting OpenNebula contextualization"
/usr/sbin/one-contextd network
log_end_msg $?
;;
*)
log_action_msg $"Usage: $0 {start}"
exit 2
esac 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 #!/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 # # 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 # # not use this file except in compliance with the License. You may obtain #
@ -20,19 +17,27 @@
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
### BEGIN INIT INFO ### BEGIN INIT INFO
# Provides: vmcontext # Provides: one-context-local
# Required-Start: $all # Required-Start: $local_fs
# Required-Stop: # Required-Stop:
# Should-Start: networking # Should-Start: $time
# Should-Stop: networking # Should-Stop:
# Default-Start: 2 3 4 5 # X-Start-Before: $network
# X-Stop-After:
# Default-Start: S
# Default-Stop: 0 1 6 # Default-Stop: 0 1 6
# Short-Description: OpenNebula contextualization script # Short-Description: OpenNebula pre-networking contextualization
### END INIT INFO ### END INIT INFO
case "$1" in . /lib/lsb/init-functions
"start")
/usr/sbin/one-contextd
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 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,19 +255,14 @@ configure_network()
deactivate_network() deactivate_network()
{ {
. /etc/os-release IFACES=`/sbin/ifquery --list -a`
if [ $ID = "ubuntu" ]; then
IFACES=`/sbin/ifquery --list -a` for i in $IFACES; do
if [ $i != 'lo' ]; then
for i in $IFACES; do /sbin/ifdown $i
if [ $i != 'lo' ]; then /sbin/ip addr flush dev $i
/sbin/ifdown $i fi
/sbin/ip addr flush dev $i done
fi
done
else
service networking stop
fi
} }
activate_network() activate_network()

@ -200,7 +200,7 @@ configure_network()
{ {
gen_network_configuration gen_network_configuration
if ! [ -d /run/systemd/system/ ] || [ "${COMMAND}" = 'reconfigure' ]; then if [ "${COMMAND}" = 'reconfigure' ]; then
service network restart service network restart
fi 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] [Service]
Type=oneshot Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/one-context-reconfigure ExecStart=/usr/sbin/one-context-reconfigure
[Install] [Install]

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
# Copyright 2010-2017, OpenNebula Systems # # Copyright 2010-2017, OpenNebula Systems #
@ -23,8 +23,16 @@ TIMEOUT=${TIMEOUT:-60}
CONTEXT_BASE=${CONTEXT_BASE:-/var/run/one-context/context.sh} CONTEXT_BASE=${CONTEXT_BASE:-/var/run/one-context/context.sh}
if [ -f ${CONTEXT_BASE}.local ] && [ -f ${CONTEXT_BASE}.network ]; then 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 /usr/sbin/one-contextd all reconfigure
fi
else else
echo 'Contextualization must start first as a boot service' >&2 echo 'Contextualization must start first as a boot service' >&2
exit 1 exit 1

@ -52,9 +52,21 @@ function log
echo "${2}" 2>/dev/null echo "${2}" 2>/dev/null
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
logger -t "${SYSLOG_TAG}" \ if [ -S /dev/log ]; then
-p "${SYSLOG_FACILITY}.${1}" \ logger -t "${SYSLOG_TAG}" \
"${2}" 2>/dev/null -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 fi
} }
@ -84,7 +96,7 @@ function execute_scripts {
fi fi
export MOUNT_DIR export MOUNT_DIR
export RUNTIME_DIR export RUNTIME_DIR
log info "Processing ${_type} scripts" log info "Processing ${_type} scripts"
for _script in ${_scripts}; do for _script in ${_scripts}; do

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

Loading…
Cancel
Save