In the past all network zones have been started during the boot processs of the system,
even if they cannot be started because for example the required device is missing.
From now it will be possible to enable or disable network zones for startup. We use the systemd
network.target to set which zones should be started.
return $?
}
+# This function calls the "enable" command from systemd,
+# to mark services to be automatically started during
+# boot up.
+function service_enable() {
+ local name=${1}
+ assert isset name
+
+ systemctl enable "${name}" >/dev/null 2>&1
+}
+
+# This function calls the "disable" command of systemd,
+# to drop the autostart ability of the service during the
+# boot up.
+function service_disable() {
+ local name=${1}
+ assert isset name
+
+ systemctl disable "${name}" >/dev/null 2>&1
+}
+
+# This function uses the systemd command "is-enabled" to check,
+# if a service has been enabled or not.
+function service_is_enabled() {
+ local name="${1}"
+ assert isset name
+
+ systemctl is-enabled "${name}" >/dev/null 2>&1
+ return $?
+}
+
function service_is_active() {
local name=${1}
assert isset name
service_stop "network@${zone}.service"
}
+function zone_enable() {
+ # This function will enable the zone
+ # with help of systemd.
+
+ local zone="${1}"
+ assert zone_exists "${zone}"
+
+ # Enable service for the zone
+ service_enable "network@${zone}.service"
+ local ret=$?
+
+ if [ ${ret} -eq ${EXIT_OK} ]; then
+ log INFO "Auto-start enabled for zone ${zone}"
+ return ${EXIT_OK}
+ fi
+
+ log ERROR "Could not enable zone ${zone}: ${ret}"
+ return ${ret}
+}
+
+function zone_disable() {
+ # This function will disable the zone
+ # with help of systemd.
+
+ local zone="${1}"
+ assert zone_exists "${zone}"
+
+ # Disable service for the zone
+ service_disable "network@${zone}.service"
+ local ret=$?
+
+ if [ ${ret} -eq ${EXIT_OK} ]; then
+ log INFO "Auto-start disabled for zone ${zone}"
+ return ${EXIT_OK}
+ fi
+
+ log ERROR "Could not disable zone ${zone}: ${ret}"
+ return ${ret}
+}
+
+function zone_is_enabled() {
+ local zone="${1}"
+ assert isset zone
+
+ # Ask systemd if the zone is enabled.
+ if service_is_enabled "network@${zone}.service"; then
+ return ${EXIT_TRUE}
+ fi
+
+ return ${EXIT_FALSE}
+}
+
function zone_create() {
local zone=${1}
local hook=${2}
# If this is the case we remove the created zone immediately.
if [ "${ret}" = "${EXIT_ERROR}" ]; then
zone_remove_now ${zone}
+ return ${EXIT_ERROR}
fi
+
+ # Automatically enable zone.
+ zone_enable "${zone}"
}
function zone_edit() {
# Force the zone down.
zone_is_up ${zone} && zone_set_down ${zone}
+ # Disable zone.
+ zone_disable "${zone}"
+
rm -rf $(zone_dir ${zone})
}
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <command><replaceable>ZONE</replaceable> [enable|disable]</command>
+ </term>
+
+ <listitem>
+ <para>
+ These commands will enable or disable the zone. An enabled
+ zone will automatically be started either during the boot process
+ or a hotplug event of an associated port or other device.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term>
<command><replaceable>ZONE</replaceable> status</command>
esac
case "${action}" in
- config|down|edit|port|status|up)
+ config|disable|down|edit|enable|port|status|up)
zone_${action} ${zone} $@
;;
*)
--- /dev/null
+[Unit]
+Description=Basic Initialization for Network Connectivity.
+After=firewall-init.service
+Before=network.target
+Wants=network.target
+Requires=firewall-init.service
+
+[Service]
+Type=oneshot
+ExecStart=/usr/sbin/network init
+
+[Install]
+WantedBy=multi-user.target
+++ /dev/null
-[Unit]
-Description=Network Connectivity
-After=firewall-init.service
-Before=network.target
-Requires=firewall-init.service
-
-[Service]
-Type=oneshot
-RemainAfterExit=yes
-ExecStartPre=/usr/sbin/network init
-ExecStart=/usr/sbin/network start
-ExecStop=/usr/sbin/network stop
-
-[Install]
-WantedBy=multi-user.target
[Unit]
Description=Network Connectivity for zone %I
-After=firewall-init.service
-Requires=firewall-init.service
+After=firewall-init.service network-init.service
+Requires=firewall-init.service network-init.service
+Wants=network.target
+Before=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/network zone %I up
ExecStop=/usr/sbin/network zone %I down
+
+[Install]
+WantedBy=network.target
+Alias=network.target.wants/network@%i.service