diff --git a/generate.sh b/generate.sh index 1163e24..4c60f86 100755 --- a/generate.sh +++ b/generate.sh @@ -77,7 +77,7 @@ while IFS= read -r -d $'\0' SRC; do done fi - # file matches + # file matches DST=${SRC%##*} #strip tags mkdir -p "${BUILD_DIR}/$(dirname "${DST}")" cp "src/${SRC}" "${BUILD_DIR}/${DST}" @@ -113,6 +113,7 @@ else --rpm-summary "${SUMMARY}" \ ${DEPENDS:+ --depends ${DEPENDS// / --depends }} \ --replaces "${REPLACES}" \ + --conflicts "${REPLACES}" \ --package "${OUT}" fi diff --git a/postinstall.one b/postinstall.one index 70b69eb..7f9fe42 100755 --- a/postinstall.one +++ b/postinstall.one @@ -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 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 vmcontext + chkconfig --add one-context-local + chkconfig --add one-context 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 - systemctl enable one-context-local.service - systemctl enable one-context.service + 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 diff --git a/preuninstall.one b/preuninstall.one index 4bed584..a55d912 100755 --- a/preuninstall.one +++ b/preuninstall.one @@ -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 diff --git a/src/etc/init.d/vmcontext##deb b/src/etc/init.d/one-context##deb.sysv.one similarity index 70% rename from src/etc/init.d/vmcontext##deb rename to src/etc/init.d/one-context##deb.sysv.one index 1394f57..f8db569 100755 --- a/src/etc/init.d/vmcontext##deb +++ b/src/etc/init.d/one-context##deb.sysv.one @@ -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 - diff --git a/src/etc/init.d/one-context##rpm.sysv.one b/src/etc/init.d/one-context##rpm.sysv.one new file mode 100755 index 0000000..0b9d9bb --- /dev/null +++ b/src/etc/init.d/one-context##rpm.sysv.one @@ -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 $? diff --git a/src/etc/init.d/vmcontext##rpm.sysv.one b/src/etc/init.d/one-context-local##deb.sysv.one similarity index 68% rename from src/etc/init.d/vmcontext##rpm.sysv.one rename to src/etc/init.d/one-context-local##deb.sysv.one index 5e847c4..b27d34f 100755 --- a/src/etc/init.d/vmcontext##rpm.sysv.one +++ b/src/etc/init.d/one-context-local##deb.sysv.one @@ -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 - diff --git a/src/etc/init.d/one-context-local##rpm.sysv.one b/src/etc/init.d/one-context-local##rpm.sysv.one new file mode 100755 index 0000000..8b6c60d --- /dev/null +++ b/src/etc/init.d/one-context-local##rpm.sysv.one @@ -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 $? diff --git a/src/etc/init.d/one-context-reconfigure##deb.sysv.one b/src/etc/init.d/one-context-reconfigure##deb.sysv.one new file mode 100755 index 0000000..e61f687 --- /dev/null +++ b/src/etc/init.d/one-context-reconfigure##deb.sysv.one @@ -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 $? diff --git a/src/etc/init.d/one-context-reconfigure##rpm.sysv.one b/src/etc/init.d/one-context-reconfigure##rpm.sysv.one new file mode 100755 index 0000000..e0495f3 --- /dev/null +++ b/src/etc/init.d/one-context-reconfigure##rpm.sysv.one @@ -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 $? diff --git a/src/etc/init.d/one-context-reconfigure-delayed##deb.sysv.one b/src/etc/init.d/one-context-reconfigure-delayed##deb.sysv.one new file mode 100755 index 0000000..ff1e06f --- /dev/null +++ b/src/etc/init.d/one-context-reconfigure-delayed##deb.sysv.one @@ -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 diff --git a/src/etc/init.d/one-context-reconfigure-delayed##rpm.sysv.one b/src/etc/init.d/one-context-reconfigure-delayed##rpm.sysv.one new file mode 100755 index 0000000..d562466 --- /dev/null +++ b/src/etc/init.d/one-context-reconfigure-delayed##rpm.sysv.one @@ -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 $? diff --git a/src/etc/init/one-context-local.conf##deb.upstart.one b/src/etc/init/one-context-local.conf##deb.upstart.one new file mode 100644 index 0000000..d518e33 --- /dev/null +++ b/src/etc/init/one-context-local.conf##deb.upstart.one @@ -0,0 +1,8 @@ +description "OpenNebula pre-networking contextualization" +author "OpenNebula Systems " + +start on mounted MOUNTPOINT=/ + +task + +exec /usr/sbin/one-contextd local diff --git a/src/etc/init/one-context-reconfigure-delayed.conf##deb.upstart.one b/src/etc/init/one-context-reconfigure-delayed.conf##deb.upstart.one new file mode 100644 index 0000000..68751fc --- /dev/null +++ b/src/etc/init/one-context-reconfigure-delayed.conf##deb.upstart.one @@ -0,0 +1,6 @@ +description "OpenNebula delayed reconfiguration" +author "OpenNebula Systems " + +task + +exec /usr/sbin/one-context-reconfigure diff --git a/src/etc/init/one-context-reconfigure.conf##deb.upstart.one b/src/etc/init/one-context-reconfigure.conf##deb.upstart.one new file mode 100644 index 0000000..f30868d --- /dev/null +++ b/src/etc/init/one-context-reconfigure.conf##deb.upstart.one @@ -0,0 +1,9 @@ +description "OpenNebula reconfiguration" +author "OpenNebula Systems " + +task + +script + export TIMEOUT=0 + exec /usr/sbin/one-context-reconfigure +end script diff --git a/src/etc/init/one-context.conf##deb.upstart.one b/src/etc/init/one-context.conf##deb.upstart.one new file mode 100644 index 0000000..6f2b309 --- /dev/null +++ b/src/etc/init/one-context.conf##deb.upstart.one @@ -0,0 +1,8 @@ +description "OpenNebula contextualization" +author "OpenNebula Systems " + +start on (filesystem and started rsyslog) + +task + +exec /usr/sbin/one-contextd network diff --git a/src/etc/one-context.d/loc-10-network##deb.one b/src/etc/one-context.d/loc-10-network##deb.one index a116ef1..8e54dd6 100755 --- a/src/etc/one-context.d/loc-10-network##deb.one +++ b/src/etc/one-context.d/loc-10-network##deb.one @@ -255,19 +255,14 @@ configure_network() deactivate_network() { - . /etc/os-release - if [ $ID = "ubuntu" ]; then - IFACES=`/sbin/ifquery --list -a` - - for i in $IFACES; do - if [ $i != 'lo' ]; then - /sbin/ifdown $i - /sbin/ip addr flush dev $i - fi - done - else - service networking stop - fi + IFACES=`/sbin/ifquery --list -a` + + for i in $IFACES; do + if [ $i != 'lo' ]; then + /sbin/ifdown $i + /sbin/ip addr flush dev $i + fi + done } activate_network() diff --git a/src/etc/one-context.d/loc-10-network##rpm.one b/src/etc/one-context.d/loc-10-network##rpm.one index acbbea2..df472b9 100755 --- a/src/etc/one-context.d/loc-10-network##rpm.one +++ b/src/etc/one-context.d/loc-10-network##rpm.one @@ -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 diff --git a/src/lib/udev/rules.d/65-context.rules##deb.one b/src/lib/udev/rules.d/65-context.rules##deb.one new file mode 100644 index 0000000..7a2ad99 --- /dev/null +++ b/src/lib/udev/rules.d/65-context.rules##deb.one @@ -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" diff --git a/src/lib/udev/rules.d/65-context.rules##one.systemd b/src/lib/udev/rules.d/65-context.rules##one.systemd deleted file mode 100644 index de598fe..0000000 --- a/src/lib/udev/rules.d/65-context.rules##one.systemd +++ /dev/null @@ -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" diff --git a/src/lib/udev/rules.d/65-context.rules##one.sysv b/src/lib/udev/rules.d/65-context.rules##one.sysv deleted file mode 100644 index b3669c4..0000000 --- a/src/lib/udev/rules.d/65-context.rules##one.sysv +++ /dev/null @@ -1 +0,0 @@ -SUBSYSTEM=="net", ACTION=="add", RUN="/usr/sbin/one-context-reconfigure" diff --git a/src/lib/udev/rules.d/65-context.rules##rpm.systemd.one b/src/lib/udev/rules.d/65-context.rules##rpm.systemd.one new file mode 100644 index 0000000..a9511b1 --- /dev/null +++ b/src/lib/udev/rules.d/65-context.rules##rpm.systemd.one @@ -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" diff --git a/src/lib/udev/rules.d/65-context.rules##rpm.sysv.one b/src/lib/udev/rules.d/65-context.rules##rpm.sysv.one new file mode 100644 index 0000000..20091d0 --- /dev/null +++ b/src/lib/udev/rules.d/65-context.rules##rpm.sysv.one @@ -0,0 +1,3 @@ +# On NIC hogplug the delayed reconfiguration is triggered. +SUBSYSTEM=="net", ACTION=="add", \ + RUN+="/sbin/service one-context-reconfigure-delayed start" diff --git a/src/usr/lib/systemd/system/one-context-local.service##deb.systemd.one b/src/usr/lib/systemd/system/one-context-local.service##deb.systemd.one new file mode 100644 index 0000000..6ea4167 --- /dev/null +++ b/src/usr/lib/systemd/system/one-context-local.service##deb.systemd.one @@ -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 diff --git a/src/usr/lib/systemd/system/one-context-reconfigure-delayed.service##rpm.systemd.one b/src/usr/lib/systemd/system/one-context-reconfigure-delayed.service##systemd.one similarity index 91% rename from src/usr/lib/systemd/system/one-context-reconfigure-delayed.service##rpm.systemd.one rename to src/usr/lib/systemd/system/one-context-reconfigure-delayed.service##systemd.one index 4bacd98..95ee8bb 100644 --- a/src/usr/lib/systemd/system/one-context-reconfigure-delayed.service##rpm.systemd.one +++ b/src/usr/lib/systemd/system/one-context-reconfigure-delayed.service##systemd.one @@ -5,6 +5,7 @@ Requisite=one-context.service [Service] Type=oneshot +RemainAfterExit=yes ExecStart=/usr/sbin/one-context-reconfigure [Install] diff --git a/src/usr/lib/systemd/system/one-context-reconfigure.service##rpm.systemd.one b/src/usr/lib/systemd/system/one-context-reconfigure.service##systemd.one similarity index 100% rename from src/usr/lib/systemd/system/one-context-reconfigure.service##rpm.systemd.one rename to src/usr/lib/systemd/system/one-context-reconfigure.service##systemd.one diff --git a/src/usr/lib/systemd/system/one-context.service##rpm.systemd.one b/src/usr/lib/systemd/system/one-context.service##systemd.one similarity index 100% rename from src/usr/lib/systemd/system/one-context.service##rpm.systemd.one rename to src/usr/lib/systemd/system/one-context.service##systemd.one diff --git a/src/usr/sbin/one-context-reconfigure##one b/src/usr/sbin/one-context-reconfigure##one index 7ceff2c..41fb9df 100755 --- a/src/usr/sbin/one-context-reconfigure##one +++ b/src/usr/sbin/one-context-reconfigure##one @@ -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 diff --git a/src/usr/sbin/one-contextd b/src/usr/sbin/one-contextd index f43511e..b2cf0c5 100755 --- a/src/usr/sbin/one-contextd +++ b/src/usr/sbin/one-contextd @@ -52,9 +52,21 @@ function log echo "${2}" 2>/dev/null if [ "$?" != "0" ]; then - logger -t "${SYSLOG_TAG}" \ - -p "${SYSLOG_FACILITY}.${1}" \ - "${2}" 2>/dev/null + 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 } @@ -75,7 +87,7 @@ function execute_scripts { local _type=$1 local _command=$1 - # choose + # choose if [ "${_type}" = 'local' ]; then local _scripts=$(ls ${SCRIPTS_DIR}/loc-* 2>/dev/null) elif [ "${_type}" = 'network' ]; then @@ -84,7 +96,7 @@ function execute_scripts { fi export MOUNT_DIR - export RUNTIME_DIR + export RUNTIME_DIR log info "Processing ${_type} scripts" for _script in ${_scripts}; do diff --git a/targets.sh b/targets.sh index 770f238..59ae294 100644 --- a/targets.sh +++ b/targets.sh @@ -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}