From: Gavin Schenk <g.schenk@eckelmann.de>
To: ptxdist@pengutronix.de
Cc: Gavin Schenk <g.schenk@eckelmann.de>
Subject: [ptxdist] [PATCH] hostapd: Add systemd service unit
Date: Mon, 26 Aug 2024 07:43:05 +0200 [thread overview]
Message-ID: <20240826054325.1426208-1-g.schenk@eckelmann.de> (raw)
If selected, start hostapd as a systemd service in multi-user.target.
Make it possible to rename the configuration file, if needed.
Signed-off-by: Gavin Schenk <g.schenk@eckelmann.de>
---
Notes:
I based the service file on the one that is shipped with debian, but
removed the Documentation node. I removed (for me) unneeded
EnvironmentFile=-/etc/default/hostapd and $DAEMON_OPTS as well, RFC.
My system is shipped with template /etc/hostapd/hostapd.conf that contains
@SSID@ as placeholder. The customer API, configuring WLAN, is to edit this
file and place it as /etc/hostapd-device.conf before restarting the
machine. This is the reason for HOSTAPD_SYSTEMD_UNIT_CONFIG.
.../usr/lib/systemd/system/hostapd.service | 15 ++++++++++++++
rules/hostapd.in | 20 +++++++++++++++++++
rules/hostapd.make | 11 ++++++++++
3 files changed, 46 insertions(+)
create mode 100644 projectroot/usr/lib/systemd/system/hostapd.service
diff --git a/projectroot/usr/lib/systemd/system/hostapd.service b/projectroot/usr/lib/systemd/system/hostapd.service
new file mode 100644
index 000000000..5e715b60d
--- /dev/null
+++ b/projectroot/usr/lib/systemd/system/hostapd.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=Access point and authentication server for Wi-Fi and Ethernet
+After=network.target
+ConditionFileNotEmpty=@HOSTAPD_CONFIG_FILEPATH@
+
+[Service]
+Type=forking
+PIDFile=/run/hostapd.pid
+Restart=on-failure
+RestartSec=2
+Environment=DAEMON_CONF=@HOSTAPD_CONFIG_FILEPATH@
+ExecStart=/usr/sbin/hostapd -B -P /run/hostapd.pid ${DAEMON_CONF}
+
+[Install]
+WantedBy=multi-user.target
diff --git a/rules/hostapd.in b/rules/hostapd.in
index 6ac6be52c..74a0dd45f 100644
--- a/rules/hostapd.in
+++ b/rules/hostapd.in
@@ -21,3 +21,23 @@ config HOSTAPD
authentication without requiring an external RADIUS
authentication server), and RADIUS authentication server for
EAP authentication.
+
+if HOSTAPD
+
+config HOSTAPD_SYSTEMD
+ prompt "Enable systemd support"
+ default false
+ bool
+
+config HOSTAPD_SYSTEMD_UNIT
+ default HOSTAPD_SYSTEMD
+ bool
+
+config HOSTAPD_SYSTEMD_UNIT_CONFIG
+ prompt "Configuration file used by unit"
+ default "/etc/hostapd/hostapd.conf"
+ string
+ help
+ Configuration used, when starting hostapd"
+
+endif
diff --git a/rules/hostapd.make b/rules/hostapd.make
index 2d061b5d4..7d3d4ec62 100644
--- a/rules/hostapd.make
+++ b/rules/hostapd.make
@@ -74,6 +74,17 @@ $(STATEDIR)/hostapd.targetinstall:
@$(call install_copy, hostapd, 0, 0, 0755, -, /usr/sbin/hostapd)
@$(call install_alternative, hostapd, 0, 0, 0644, /etc/hostapd/hostapd.conf)
+ifdef PTXCONF_HOSTAPD_SYSTEMD_UNIT
+ @$(call install_alternative, hostapd, 0, 0, 0644, \
+ /usr/lib/systemd/system/hostapd.service)
+ @$(call install_replace, hostapd, /usr/lib/systemd/system/hostapd.service, \
+ @HOSTAPD_CONFIG_FILEPATH@, \
+ "$(call remove_quotes,$(PTXCONF_HOSTAPD_SYSTEMD_UNIT_CONFIG))")
+
+ @$(call install_link, hostapd, ../hostapd.service, \
+ /lib/systemd/system/multi-user.target.wants/hostapd.service)
+endif
+
@$(call install_finish, hostapd)
@$(call touch)
--
2.39.2
next reply other threads:[~2024-08-26 5:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-26 5:43 Gavin Schenk [this message]
2024-09-06 13:59 ` Michael Olbrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240826054325.1426208-1-g.schenk@eckelmann.de \
--to=g.schenk@eckelmann.de \
--cc=ptxdist@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox