From 9e32b898ff4eae126b4d814bc9388db493445ccb Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 16 May 2019 14:51:34 +0200 Subject: [PATCH 1/6] Import network.service Import network.service from a random system. --- install.sh | 1 + misc_systemd_units/network.service | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 misc_systemd_units/network.service diff --git a/install.sh b/install.sh index 46e6a5e..7c65d3a 100755 --- a/install.sh +++ b/install.sh @@ -144,4 +144,5 @@ install_data misc_etc_files/systemd/logind.conf.d/disable_RemoveIPC.conf \ install_data logrotate/logrotate.conf "$DESTDIR$sysconfdir/logrotate.conf" install_data logrotate/logrotate.service "$DESTDIR$systemdunitdir/logrotate.service" install_data logrotate/logrotate.timer "$DESTDIR$systemdunitdir/logrotate.timer" +install_data misc_systemd_units/network.service "$DESTDIR$systemdunitdir/network.service" exit diff --git a/misc_systemd_units/network.service b/misc_systemd_units/network.service new file mode 100644 index 0000000..53895f0 --- /dev/null +++ b/misc_systemd_units/network.service @@ -0,0 +1,16 @@ +[Unit] +Description=Network Connectivity +DefaultDependencies=no + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/sbin/mxnetctl start +ExecStart=/sbin/ip addr add 141.14.31.7/20 broadcast 141.14.31.255 dev net00 +ExecStart=/sbin/ip link set up dev net00 +ExecStop=/sbin/ip addr del 141.14.31.7/20 dev net00 +StandardOutput=syslog + +[Install] +WantedBy=network.target + From f86ef2203f5260815d1ba38106570d7952a030fc Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 16 May 2019 14:53:56 +0200 Subject: [PATCH 2/6] network.service: Use environment file All systems now have a file /etc/local/mxhost.conf with the host specific IP address and network interface. Use that data in the unit file. Note, that this is not shell syntax. The difference between $VAR and ${VAR} is how the whitespaces inside VAR are handled. ${VAR} would be "$VAR" in shell syntax. We don't need the brackets, because the values are single words only. However, unlike the shell, systemd would parse $MX_IPADDR/20 as an environment variable named "MX_IPADDR/20". So we need the curlies at that point to terminate the variable name. Use it everywhere for readability and to avoid future errors. --- misc_systemd_units/network.service | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/misc_systemd_units/network.service b/misc_systemd_units/network.service index 53895f0..0de3e5d 100644 --- a/misc_systemd_units/network.service +++ b/misc_systemd_units/network.service @@ -3,12 +3,13 @@ Description=Network Connectivity DefaultDependencies=no [Service] +EnvironmentFile=/etc/local/mxhost.conf Type=oneshot RemainAfterExit=yes ExecStart=/usr/sbin/mxnetctl start -ExecStart=/sbin/ip addr add 141.14.31.7/20 broadcast 141.14.31.255 dev net00 -ExecStart=/sbin/ip link set up dev net00 -ExecStop=/sbin/ip addr del 141.14.31.7/20 dev net00 +ExecStart=/sbin/ip addr add ${MX_IPADDR}/20 broadcast 141.14.31.255 dev ${MX_NETDEV} +ExecStart=/sbin/ip link set up dev ${MX_NETDEV} +ExecStop=/sbin/ip addr del ${MX_IPADDR}/20 dev ${MX_NETDEV} StandardOutput=syslog [Install] From d8301a54b17c558b0af418afa680644e31615d43 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 16 May 2019 15:19:05 +0200 Subject: [PATCH 3/6] network.service: Remove blank line at eof --- misc_systemd_units/network.service | 1 - 1 file changed, 1 deletion(-) diff --git a/misc_systemd_units/network.service b/misc_systemd_units/network.service index 0de3e5d..710ce85 100644 --- a/misc_systemd_units/network.service +++ b/misc_systemd_units/network.service @@ -14,4 +14,3 @@ StandardOutput=syslog [Install] WantedBy=network.target - From 9db11c13bfbcd49d602f120542a26ccbcad12d93 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 16 May 2019 15:58:46 +0200 Subject: [PATCH 4/6] network.service: Add default route Add the setting of the default route into this service. This is supposed to replace gateway.service which should be removed, if this is merged. The problem with two different services is, that the system looses the route when network.service is stopped. Currently, gateway.service is also stopped, because of a Requires= dependency, but not restarted, when network.service is restarted. Downgrading the dependency to Wants= wouldn't resolve the problem, because the system looses the route anyway when the ip address is removed. If we make sure, that we add the route every time we set the ip address, we can restart network.service without loosing the default route. The services are not independent anyway, because the gateway ip address must be on a local network and thus match the ip address used by this unit. --- misc_systemd_units/network.service | 1 + 1 file changed, 1 insertion(+) diff --git a/misc_systemd_units/network.service b/misc_systemd_units/network.service index 710ce85..931a46e 100644 --- a/misc_systemd_units/network.service +++ b/misc_systemd_units/network.service @@ -9,6 +9,7 @@ RemainAfterExit=yes ExecStart=/usr/sbin/mxnetctl start ExecStart=/sbin/ip addr add ${MX_IPADDR}/20 broadcast 141.14.31.255 dev ${MX_NETDEV} ExecStart=/sbin/ip link set up dev ${MX_NETDEV} +ExecStart=/sbin/ip route add default via 141.14.16.128 ExecStop=/sbin/ip addr del ${MX_IPADDR}/20 dev ${MX_NETDEV} StandardOutput=syslog From 02775cdd142201ef528fbed2ef22a59cdd6796cf Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 16 May 2019 15:54:41 +0200 Subject: [PATCH 5/6] Import mxvlan.service --- install.sh | 1 + misc_systemd_units/mxvlan.service | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 misc_systemd_units/mxvlan.service diff --git a/install.sh b/install.sh index 7c65d3a..db302c3 100755 --- a/install.sh +++ b/install.sh @@ -145,4 +145,5 @@ install_data logrotate/logrotate.conf "$DESTDIR$sysconfdir/l install_data logrotate/logrotate.service "$DESTDIR$systemdunitdir/logrotate.service" install_data logrotate/logrotate.timer "$DESTDIR$systemdunitdir/logrotate.timer" install_data misc_systemd_units/network.service "$DESTDIR$systemdunitdir/network.service" +install_data misc_systemd_units/mxvlan.service "$DESTDIR$systemdunitdir/mxvlan.service" exit diff --git a/misc_systemd_units/mxvlan.service b/misc_systemd_units/mxvlan.service new file mode 100644 index 0000000..73b1fb7 --- /dev/null +++ b/misc_systemd_units/mxvlan.service @@ -0,0 +1,16 @@ +[Unit] +Description=MX VLAN Setup +Requires=network.service +After=network.service +Before=network.target + +[Service] +Type=oneshot +RemainAfterExit=yes +StandardOutput=syslog +ExecStart=/usr/sbin/mxvlanctl start +ExecStop=/usr/sbin/mxvlanctl stop + +[Install] +WantedBy=network.target + From 0ef998d6275e52dab1bff55eb91a6e5ccfbfa56d Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 16 May 2019 15:55:34 +0200 Subject: [PATCH 6/6] mxvlan.service: Do no require network.service When mxvlan has a Requires dependency on network.service, it is stopped, when network.service is stopped, but not started, when network.service is restarted. Downgrade this to a Wants dependency. --- misc_systemd_units/mxvlan.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc_systemd_units/mxvlan.service b/misc_systemd_units/mxvlan.service index 73b1fb7..684c78e 100644 --- a/misc_systemd_units/mxvlan.service +++ b/misc_systemd_units/mxvlan.service @@ -1,6 +1,6 @@ [Unit] Description=MX VLAN Setup -Requires=network.service +Wants=network.service After=network.service Before=network.target