From patchwork Fri Jun 13 15:35:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Le Bihan X-Patchwork-Id: 359561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from fraxinus.osuosl.org (fraxinus.osuosl.org [140.211.166.137]) by ozlabs.org (Postfix) with ESMTP id 429121400A4 for ; Sat, 14 Jun 2014 01:35:22 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 5296589306; Fri, 13 Jun 2014 15:35:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id trjp8uDuKuUj; Fri, 13 Jun 2014 15:35:19 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id EE0C888FE2; Fri, 13 Jun 2014 15:35:18 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 54B711C1654 for ; Fri, 13 Jun 2014 15:35:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 4E2D130BC4 for ; Fri, 13 Jun 2014 15:35:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ecOGuXpbOMVE for ; Fri, 13 Jun 2014 15:35:16 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from smtp6-g21.free.fr (smtp6-g21.free.fr [212.27.42.6]) by silver.osuosl.org (Postfix) with ESMTP id EF38C304E0 for ; Fri, 13 Jun 2014 15:35:15 +0000 (UTC) Received: from rmm-p1267483.femto.urd666.local (unknown [217.128.73.13]) (Authenticated sender: eric.le.bihan.dev@free.fr) by smtp6-g21.free.fr (Postfix) with ESMTPSA id 6132B82285; Fri, 13 Jun 2014 17:35:12 +0200 (CEST) From: Eric Le Bihan To: buildroot@buildroot.org Date: Fri, 13 Jun 2014 17:35:35 +0200 Message-Id: <1402673735-14109-1-git-send-email-eric.le.bihan.dev@free.fr> X-Mailer: git-send-email 1.7.10.4 Subject: [Buildroot] [PATCH] systemd: add network unit file X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: buildroot-bounces@busybox.net From: Ivan Sergeev Add and enable a systemd unit file to bring up or down network with ifup / ifdown, analogous to the skeleton/etc/init.d/S40network init script. Signed-off-by: Ivan Sergeev [eric.le.bihan.dev@free.fr: - rebase - install service only if systemd-networkd is not selected] Signed-off-by: Eric Le Bihan --- package/systemd/network.service | 21 +++++++++++++++++++++ package/systemd/systemd.mk | 12 ++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 package/systemd/network.service diff --git a/package/systemd/network.service b/package/systemd/network.service new file mode 100644 index 0000000..0d77bb8 --- /dev/null +++ b/package/systemd/network.service @@ -0,0 +1,21 @@ +[Unit] +Description=Network Connectivity +Wants=network.target +Before=network.target + +[Service] +Type=oneshot +RemainAfterExit=yes + +# lo is brought up earlier, which will cause the upcoming "ifup -a" to fail +# with exit code 1, due to an "ip: RTNETLINK answers: File exists" error during +# its "ip addr add ..." command, subsequently causing this unit to fail even +# though it is a benign error. Flushing the lo address with the command below +# before ifup prevents this failure. +ExecStart=/sbin/ip addr flush dev lo + +ExecStart=/sbin/ifup -a +ExecStop=/sbin/ifdown -a + +[Install] +WantedBy=multi-user.target diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk index 6de7887..f3874db 100644 --- a/package/systemd/systemd.mk +++ b/package/systemd/systemd.mk @@ -145,12 +145,24 @@ define SYSTEMD_SANITIZE_PATH_IN_UNITS -exec $(SED) 's,$(HOST_DIR),,g' {} \; endef +define SYSTEMD_INSTALL_NETWORK_HOOK + $(INSTALL) -D -m 644 package/systemd/network.service \ + $(TARGET_DIR)/etc/systemd/system/network.service + mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants + ln -fs ../network.service \ + $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/network.service +endef + SYSTEMD_POST_INSTALL_TARGET_HOOKS += \ SYSTEMD_INSTALL_INIT_HOOK \ SYSTEMD_INSTALL_TTY_HOOK \ SYSTEMD_INSTALL_MACHINEID_HOOK \ SYSTEMD_SANITIZE_PATH_IN_UNITS +ifeq ($(BR2_PACKAGE_SYSTEMD_NETWORKD),) +SYSTEMD_POST_INSTALL_TARGET_HOOKS += SYSTEMD_INSTALL_NETWORK_HOOK +endif + define SYSTEMD_USERS systemd-journal -1 systemd-journal -1 * /var/log/journal - - Journal systemd-journal-gateway -1 systemd-journal-gateway -1 * /var/log/journal - - Journal Gateway