All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] openssh: Add SSHD_SERVICE_TYPE variable
@ 2023-12-04  8:54 mingli.yu
  2023-12-04 11:07 ` [OE-core] " Richard Purdie
  0 siblings, 1 reply; 14+ messages in thread
From: mingli.yu @ 2023-12-04  8:54 UTC (permalink / raw)
  To: openembedded-core

From: Mingli Yu <mingli.yu@windriver.com>

There are two types of sshd server now, one is based on socket
activation(sshd.socket) and another is service activation(sshd.service).
And the default sshd service type is based on socket by default as below.
============================================
 # systemctl status sshd.socket
* sshd.socket
     Loaded: loaded (/lib/systemd/system/sshd.socket; enabled; preset: enabled)
     Active: active (listening) since Mon 2023-12-04 08:34:33 UTC; 22s ago
     Listen: [::]:22 (Stream)
   Accepted: 0; Connected: 0;
    Process: 228 ExecStartPre=/bin/mkdir -p /var/run/sshd (code=exited, status=0/SUCCESS)
      Tasks: 0 (limit: 263)
     Memory: 84.0K
     CGroup: /system.slice/sshd.socket

Dec 04 08:34:33 qemux86-64 systemd[1]: Starting sshd.socket...
Dec 04 08:34:33 qemux86-64 systemd[1]: Listening on sshd.socket.
============================================

And use can switch to service activation if they want as below after
the device boot up.
============================================
 # systemctl disable sshd.socket
Removed "/etc/systemd/system/sockets.target.wants/sshd.socket".
 # systemctl stop sshd.socket
 # systemctl start sshd.service
 # systemctl status sshd.service
* sshd.service - OpenSSH server daemon
     Loaded: loaded (/lib/systemd/system/sshd.service; enabled; preset: enabled)
     Active: active (running) since Mon 2023-12-04 08:48:14 UTC; 53s ago
    Process: 390 ExecStartPre=/bin/mkdir -p /var/run/sshd (code=exited, status=0/SUCCESS)
   Main PID: 391 (sshd)
      Tasks: 1 (limit: 263)
     Memory: 2.1M
     CGroup: /system.slice/sshd.service
             `-391 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Dec 04 08:48:14 qemux86-64 systemd[1]: Starting OpenSSH server daemon...
Dec 04 08:48:14 qemux86-64 systemd[1]: Started OpenSSH server daemon.
Dec 04 08:48:14 qemux86-64 sshd[391]: Server listening on 0.0.0.0 port 22.
Dec 04 08:48:14 qemux86-64 sshd[391]: Server listening on :: port 22.
============================================

But it's more convenient to determine the service type at build time
if there are so many devices.

So add SSHD_SERVICE_TYPE variable to enable sshd.socket or sshd.service
at build time and we still enable sshd.socket by default now.

Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
---
 .../openssh/openssh_9.5p1.bb                   | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/meta/recipes-connectivity/openssh/openssh_9.5p1.bb b/meta/recipes-connectivity/openssh/openssh_9.5p1.bb
index bbb8fb091a..6a603cd12d 100644
--- a/meta/recipes-connectivity/openssh/openssh_9.5p1.bb
+++ b/meta/recipes-connectivity/openssh/openssh_9.5p1.bb
@@ -50,7 +50,7 @@ INITSCRIPT_NAME:${PN}-sshd = "sshd"
 INITSCRIPT_PARAMS:${PN}-sshd = "defaults 9"
 
 SYSTEMD_PACKAGES = "${PN}-sshd"
-SYSTEMD_SERVICE:${PN}-sshd = "sshd.socket sshd.service"
+SYSTEMD_SERVICE:${PN}-sshd = "${@bb.utils.contains('SSHD_SERVICE_TYPE', '1', 'sshd.service', 'sshd.socket', d)}"
 
 inherit autotools-brokensep ptest pkgconfig
 DEPENDS += "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'systemd', '', d)}"
@@ -125,15 +125,23 @@ do_install:append () {
 	echo "HostKey /var/run/ssh/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
 
 	install -d ${D}${systemd_system_unitdir}
-	install -c -m 0644 ${WORKDIR}/sshd.socket ${D}${systemd_system_unitdir}
-	install -c -m 0644 ${WORKDIR}/sshd.service ${D}${systemd_system_unitdir}
-	install -c -m 0644 ${WORKDIR}/sshd@.service ${D}${systemd_system_unitdir}
+	if ${@bb.utils.contains('SSHD_SERVICE_TYPE','1','true','false',d)}; then
+	    install -c -m 0644 ${WORKDIR}/sshd.service ${D}${systemd_system_unitdir}
+	else
+	    install -c -m 0644 ${WORKDIR}/sshd.socket ${D}${systemd_system_unitdir}
+	    install -c -m 0644 ${WORKDIR}/sshd@.service ${D}${systemd_system_unitdir}
+	    sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \
+		    -e 's,@SBINDIR@,${sbindir},g' \
+		    -e 's,@BINDIR@,${bindir},g' \
+		    -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \
+            ${D}${systemd_system_unitdir}/sshd.socket
+	fi
 	install -c -m 0644 ${WORKDIR}/sshdgenkeys.service ${D}${systemd_system_unitdir}
 	sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \
 		-e 's,@SBINDIR@,${sbindir},g' \
 		-e 's,@BINDIR@,${bindir},g' \
 		-e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \
-		${D}${systemd_system_unitdir}/sshd.socket ${D}${systemd_system_unitdir}/*.service
+		${D}${systemd_system_unitdir}/*.service
 
 	sed -i -e 's,@LIBEXECDIR@,${libexecdir}/${BPN},g' \
 		${D}${sysconfdir}/init.d/sshd
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-12-18  6:17 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-04  8:54 [PATCH] openssh: Add SSHD_SERVICE_TYPE variable mingli.yu
2023-12-04 11:07 ` [OE-core] " Richard Purdie
2023-12-05  2:51   ` Yu, Mingli
2023-12-05  5:52     ` [PATCH v2] openssh: Add PACKAGECONFIG option to customize sshd mode mingli.yu
2023-12-05  7:43       ` [OE-core] " Alexandre Belloni
2023-12-06  5:44         ` [PATCH v3] " mingli.yu
2023-12-06  8:56         ` [PATCH v4] " mingli.yu
2023-12-06 10:37           ` [OE-core] " Alex Kiernan
2023-12-07  2:10             ` Yu, Mingli
2023-12-07 12:11               ` Alex Kiernan
2023-12-13  3:37                 ` Yu, Mingli
     [not found]         ` <179E3241B25BBB7C.1352@lists.openembedded.org>
2023-12-18  6:16           ` Yu, Mingli
2023-12-06 22:34       ` [OE-core] [PATCH v2] " Peter Kjellerstedt
2023-12-07  1:53         ` Yu, Mingli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.