diff mbox series

[meta-oe,3/3] linuxptp: add systemd services

Message ID 20231011163346.1856498-4-luca.fancellu@arm.com
State Under Review
Headers show
Series Update linuxptp version to 4.1 | expand

Commit Message

Luca Fancellu Oct. 11, 2023, 4:33 p.m. UTC
Add systemd services phc2sys@.service and ptp4l@.service,
these services are taken from the Ubuntu/Debian linuxptp
package.

Update the recipe to install them when needed using the
systemd bbclass, the services are disabled by default.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
 .../linuxptp/linuxptp/systemd/phc2sys@.service   | 13 +++++++++++++
 .../linuxptp/linuxptp/systemd/ptp4l@.service     | 11 +++++++++++
 .../linuxptp/linuxptp_4.1.bb                     | 16 ++++++++++++++++
 3 files changed, 40 insertions(+)
 create mode 100644 meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
 create mode 100644 meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service

Comments

Khem Raj Oct. 11, 2023, 5:22 p.m. UTC | #1
On Wed, Oct 11, 2023 at 9:34 AM luca fancellu <luca.fancellu@arm.com> wrote:
>
> Add systemd services phc2sys@.service and ptp4l@.service,
> these services are taken from the Ubuntu/Debian linuxptp
> package.
>
> Update the recipe to install them when needed using the
> systemd bbclass, the services are disabled by default.
>
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> ---
>  .../linuxptp/linuxptp/systemd/phc2sys@.service   | 13 +++++++++++++
>  .../linuxptp/linuxptp/systemd/ptp4l@.service     | 11 +++++++++++
>  .../linuxptp/linuxptp_4.1.bb                     | 16 ++++++++++++++++
>  3 files changed, 40 insertions(+)
>  create mode 100644 meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
>  create mode 100644 meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
>
> diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
> new file mode 100644
> index 000000000000..dd2512bdca11
> --- /dev/null
> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
> @@ -0,0 +1,13 @@
> +[Unit]
> +Description=Synchronize system clock or PTP hardware clock (PHC)
> +Documentation=man:phc2sys
> +Requires=ptp4l.service
> +After=ptp4l.service
> +Before=time-sync.target
> +
> +[Service]
> +Type=simple
> +ExecStart=/usr/sbin/phc2sys -w -s %I

Can these paths be derived from ${sbindir} during do_install.


> +
> +[Install]
> +WantedBy=multi-user.target
> diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
> new file mode 100644
> index 000000000000..1bad2d72df6b
> --- /dev/null
> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
> @@ -0,0 +1,11 @@
> +[Unit]
> +Description=Precision Time Protocol (PTP) service for %I
> +Documentation=man:ptp4l
> +After=sys-subsystem-net-devices-%i.device
> +
> +[Service]
> +Type=simple
> +ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf -i %I

Can these paths be derived from ${sbindir} and ${sysconfdir} bitbake variables
during do_install ? This should make them more portable

> +
> +[Install]
> +WantedBy=multi-user.target
> diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp_4.1.bb b/meta-oe/recipes-connectivity/linuxptp/linuxptp_4.1.bb
> index 3c7efbdeca72..95ed76e621e6 100644
> --- a/meta-oe/recipes-connectivity/linuxptp/linuxptp_4.1.bb
> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp_4.1.bb
> @@ -11,11 +11,15 @@ SRC_URI = "${LINUXPTP_SRC_URI}/files/v4.1/linuxptp-${PV}.tgz \
>             file://build-Allow-CC-and-prefix-to-be-overriden.patch \
>             file://Use-cross-cpp-in-incdefs.patch \
>             file://0001-include-string.h-for-strncpy.patch \
> +           file://systemd/phc2sys@.service \
> +           file://systemd/ptp4l@.service \
>             "
>
>  SRC_URI[md5sum] = "1db8699fc155965341759be5e5aad938"
>  SRC_URI[sha256sum] = "e1743d44f8208897e30895da3579e670ff919b914feb4b5a949f3e421ddde535"
>
> +inherit systemd
> +
>  UPSTREAM_CHECK_URI = "${LINUXPTP_SRC_URI}/files/"
>  UPSTREAM_CHECK_REGEX = "(?P<pver>\d+(\.\d+)+)/"
>
> @@ -23,6 +27,8 @@ EXTRA_OEMAKE = "ARCH=${TARGET_ARCH} EXTRA_CFLAGS='${CFLAGS}' mandir=${mandir}"
>
>  export KBUILD_OUTPUT="${RECIPE_SYSROOT}"
>
> +LINUXPTP_SYSTEMD_SERVICES = "phc2sys@.service ptp4l@.service"
> +
>  do_install() {
>      oe_runmake install DESTDIR=${D} prefix=${prefix}
>
> @@ -35,8 +41,18 @@ do_install() {
>      install -d ${D}/${sysconfdir}/linuxptp/
>      install -m 644 ${S}/configs/default.cfg \
>          ${D}${sysconfdir}/linuxptp/ptp4l.conf
> +
> +    # Install systemd services
> +    install -d ${D}/${systemd_unitdir}/system/
> +    for service in ${LINUXPTP_SYSTEMD_SERVICES}; do
> +        install -m 644 ${WORKDIR}/systemd/$service \
> +            ${D}/${systemd_unitdir}/system/$service
> +    done
>  }
>
> +SYSTEMD_SERVICE:${PN} = "${LINUXPTP_SYSTEMD_SERVICES}"
> +SYSTEMD_AUTO_ENABLE:${PN} = "disable"
> +
>  PACKAGES =+ "${PN}-configs"
>
>  FILES:${PN}-configs += "${docdir}"
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#105429): https://lists.openembedded.org/g/openembedded-devel/message/105429
> Mute This Topic: https://lists.openembedded.org/mt/101900484/1997914
> Group Owner: openembedded-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Luca Fancellu Oct. 12, 2023, 9:56 a.m. UTC | #2
Hi Khem,

>> 
>> diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
>> new file mode 100644
>> index 000000000000..dd2512bdca11
>> --- /dev/null
>> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
>> @@ -0,0 +1,13 @@
>> +[Unit]
>> +Description=Synchronize system clock or PTP hardware clock (PHC)
>> +Documentation=man:phc2sys
>> +Requires=ptp4l.service
>> +After=ptp4l.service
>> +Before=time-sync.target
>> +
>> +[Service]
>> +Type=simple
>> +ExecStart=/usr/sbin/phc2sys -w -s %I
> 
> Can these paths be derived from ${sbindir} during do_install.
> 
> 
>> +
>> +[Install]
>> +WantedBy=multi-user.target
>> diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
>> new file mode 100644
>> index 000000000000..1bad2d72df6b
>> --- /dev/null
>> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
>> @@ -0,0 +1,11 @@
>> +[Unit]
>> +Description=Precision Time Protocol (PTP) service for %I
>> +Documentation=man:ptp4l
>> +After=sys-subsystem-net-devices-%i.device
>> +
>> +[Service]
>> +Type=simple
>> +ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf -i %I
> 
> Can these paths be derived from ${sbindir} and ${sysconfdir} bitbake variables
> during do_install ? This should make them more portable

Yes I can do that, for both ${sbindir} and ${sysconfdir}, I see the makefile sets
sbindir = $(prefix)/sbin, we already pass ${prefix} in the make command line,
do you think we should pass also sbindir= to ensure consistency?
Khem Raj Oct. 12, 2023, 2:22 p.m. UTC | #3
On Thu, Oct 12, 2023 at 2:56 AM Luca Fancellu <Luca.Fancellu@arm.com> wrote:

> Hi Khem,
>
> >>
> >> diff --git
> a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
> b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
> >> new file mode 100644
> >> index 000000000000..dd2512bdca11
> >> --- /dev/null
> >> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@
> .service
> >> @@ -0,0 +1,13 @@
> >> +[Unit]
> >> +Description=Synchronize system clock or PTP hardware clock (PHC)
> >> +Documentation=man:phc2sys
> >> +Requires=ptp4l.service
> >> +After=ptp4l.service
> >> +Before=time-sync.target
> >> +
> >> +[Service]
> >> +Type=simple
> >> +ExecStart=/usr/sbin/phc2sys -w -s %I
> >
> > Can these paths be derived from ${sbindir} during do_install.
> >
> >
> >> +
> >> +[Install]
> >> +WantedBy=multi-user.target
> >> diff --git
> a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
> b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
> >> new file mode 100644
> >> index 000000000000..1bad2d72df6b
> >> --- /dev/null
> >> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@
> .service
> >> @@ -0,0 +1,11 @@
> >> +[Unit]
> >> +Description=Precision Time Protocol (PTP) service for %I
> >> +Documentation=man:ptp4l
> >> +After=sys-subsystem-net-devices-%i.device
> >> +
> >> +[Service]
> >> +Type=simple
> >> +ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf -i %I
> >
> > Can these paths be derived from ${sbindir} and ${sysconfdir} bitbake
> variables
> > during do_install ? This should make them more portable
>
> Yes I can do that, for both ${sbindir} and ${sysconfdir}, I see the
> makefile sets
> sbindir = $(prefix)/sbin, we already pass ${prefix} in the make command
> line,
> do you think we should pass also sbindir= to ensure consistency?


I think it is that we store the origin service file as a template like
service.in and then when installing it during do_install substitute the
paths with original value of these variables there are many examples of
this in metadata

>
>
>
Luca Fancellu Oct. 12, 2023, 2:39 p.m. UTC | #4
> On 12 Oct 2023, at 15:22, Khem Raj <raj.khem@gmail.com> wrote:
> 
> 
> 
> On Thu, Oct 12, 2023 at 2:56 AM Luca Fancellu <Luca.Fancellu@arm.com> wrote:
> Hi Khem,
> 
> >> 
> >> diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
> >> new file mode 100644
> >> index 000000000000..dd2512bdca11
> >> --- /dev/null
> >> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
> >> @@ -0,0 +1,13 @@
> >> +[Unit]
> >> +Description=Synchronize system clock or PTP hardware clock (PHC)
> >> +Documentation=man:phc2sys
> >> +Requires=ptp4l.service
> >> +After=ptp4l.service
> >> +Before=time-sync.target
> >> +
> >> +[Service]
> >> +Type=simple
> >> +ExecStart=/usr/sbin/phc2sys -w -s %I
> > 
> > Can these paths be derived from ${sbindir} during do_install.
> > 
> > 
> >> +
> >> +[Install]
> >> +WantedBy=multi-user.target
> >> diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
> >> new file mode 100644
> >> index 000000000000..1bad2d72df6b
> >> --- /dev/null
> >> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
> >> @@ -0,0 +1,11 @@
> >> +[Unit]
> >> +Description=Precision Time Protocol (PTP) service for %I
> >> +Documentation=man:ptp4l
> >> +After=sys-subsystem-net-devices-%i.device
> >> +
> >> +[Service]
> >> +Type=simple
> >> +ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf -i %I
> > 
> > Can these paths be derived from ${sbindir} and ${sysconfdir} bitbake variables
> > during do_install ? This should make them more portable
> 
> Yes I can do that, for both ${sbindir} and ${sysconfdir}, I see the makefile sets
> sbindir = $(prefix)/sbin, we already pass ${prefix} in the make command line,
> do you think we should pass also sbindir= to ensure consistency?
> 
> I think it is that we store the origin service file as a template like service.in and then when installing it during do_install substitute the paths with original value of these variables there are many examples of this in metadata 
> 
> 

Yes of course, that part is very clear, what I’m asking is:

Since the Makefile hardcode sbindir, is it enough if I replace ${prefix} and ${sysconfdir} in the service?

For example here:
> >> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
> >> @@ -0,0 +1,11 @@
> >> +[Unit]
> >> +Description=Precision Time Protocol (PTP) service for %I
> >> +Documentation=man:ptp4l
> >> +After=sys-subsystem-net-devices-%i.device
> >> +
> >> +[Service]
> >> +Type=simple
> >> +ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf -i %I

It will be: ExecStart=@PREFIX@/sbin/ptp4l -f @SYSCONFDIR@/linuxptp/ptp4l.conf -i %I

So that in do_install I can do the sed substitution using ${prefix} and ${sysconfdir}
Khem Raj Oct. 12, 2023, 3:08 p.m. UTC | #5
On Thu, Oct 12, 2023 at 7:39 AM Luca Fancellu <Luca.Fancellu@arm.com> wrote:
>
>
>
> > On 12 Oct 2023, at 15:22, Khem Raj <raj.khem@gmail.com> wrote:
> >
> >
> >
> > On Thu, Oct 12, 2023 at 2:56 AM Luca Fancellu <Luca.Fancellu@arm.com> wrote:
> > Hi Khem,
> >
> > >>
> > >> diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
> > >> new file mode 100644
> > >> index 000000000000..dd2512bdca11
> > >> --- /dev/null
> > >> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
> > >> @@ -0,0 +1,13 @@
> > >> +[Unit]
> > >> +Description=Synchronize system clock or PTP hardware clock (PHC)
> > >> +Documentation=man:phc2sys
> > >> +Requires=ptp4l.service
> > >> +After=ptp4l.service
> > >> +Before=time-sync.target
> > >> +
> > >> +[Service]
> > >> +Type=simple
> > >> +ExecStart=/usr/sbin/phc2sys -w -s %I
> > >
> > > Can these paths be derived from ${sbindir} during do_install.
> > >
> > >
> > >> +
> > >> +[Install]
> > >> +WantedBy=multi-user.target
> > >> diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
> > >> new file mode 100644
> > >> index 000000000000..1bad2d72df6b
> > >> --- /dev/null
> > >> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
> > >> @@ -0,0 +1,11 @@
> > >> +[Unit]
> > >> +Description=Precision Time Protocol (PTP) service for %I
> > >> +Documentation=man:ptp4l
> > >> +After=sys-subsystem-net-devices-%i.device
> > >> +
> > >> +[Service]
> > >> +Type=simple
> > >> +ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf -i %I
> > >
> > > Can these paths be derived from ${sbindir} and ${sysconfdir} bitbake variables
> > > during do_install ? This should make them more portable
> >
> > Yes I can do that, for both ${sbindir} and ${sysconfdir}, I see the makefile sets
> > sbindir = $(prefix)/sbin, we already pass ${prefix} in the make command line,
> > do you think we should pass also sbindir= to ensure consistency?
> >
> > I think it is that we store the origin service file as a template like service.in and then when installing it during do_install substitute the paths with original value of these variables there are many examples of this in metadata
> >
> >
>
> Yes of course, that part is very clear, what I’m asking is:
>
> Since the Makefile hardcode sbindir, is it enough if I replace ${prefix} and ${sysconfdir} in the service?
>
> For example here:
> > >> +++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
> > >> @@ -0,0 +1,11 @@
> > >> +[Unit]
> > >> +Description=Precision Time Protocol (PTP) service for %I
> > >> +Documentation=man:ptp4l
> > >> +After=sys-subsystem-net-devices-%i.device
> > >> +
> > >> +[Service]
> > >> +Type=simple
> > >> +ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf -i %I
>
> It will be: ExecStart=@PREFIX@/sbin/ptp4l -f @SYSCONFDIR@/linuxptp/ptp4l.conf -i %I

just ensure it keeps working for usrmerge DISTRO_FEATURE as well.

>
> So that in do_install I can do the sed substitution using ${prefix} and ${sysconfdir}
>
>
diff mbox series

Patch

diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
new file mode 100644
index 000000000000..dd2512bdca11
--- /dev/null
+++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/phc2sys@.service
@@ -0,0 +1,13 @@ 
+[Unit]
+Description=Synchronize system clock or PTP hardware clock (PHC)
+Documentation=man:phc2sys
+Requires=ptp4l.service
+After=ptp4l.service
+Before=time-sync.target
+
+[Service]
+Type=simple
+ExecStart=/usr/sbin/phc2sys -w -s %I
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
new file mode 100644
index 000000000000..1bad2d72df6b
--- /dev/null
+++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp/systemd/ptp4l@.service
@@ -0,0 +1,11 @@ 
+[Unit]
+Description=Precision Time Protocol (PTP) service for %I
+Documentation=man:ptp4l
+After=sys-subsystem-net-devices-%i.device
+
+[Service]
+Type=simple
+ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf -i %I
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-oe/recipes-connectivity/linuxptp/linuxptp_4.1.bb b/meta-oe/recipes-connectivity/linuxptp/linuxptp_4.1.bb
index 3c7efbdeca72..95ed76e621e6 100644
--- a/meta-oe/recipes-connectivity/linuxptp/linuxptp_4.1.bb
+++ b/meta-oe/recipes-connectivity/linuxptp/linuxptp_4.1.bb
@@ -11,11 +11,15 @@  SRC_URI = "${LINUXPTP_SRC_URI}/files/v4.1/linuxptp-${PV}.tgz \
            file://build-Allow-CC-and-prefix-to-be-overriden.patch \
            file://Use-cross-cpp-in-incdefs.patch \
            file://0001-include-string.h-for-strncpy.patch \
+           file://systemd/phc2sys@.service \
+           file://systemd/ptp4l@.service \
            "
 
 SRC_URI[md5sum] = "1db8699fc155965341759be5e5aad938"
 SRC_URI[sha256sum] = "e1743d44f8208897e30895da3579e670ff919b914feb4b5a949f3e421ddde535"
 
+inherit systemd
+
 UPSTREAM_CHECK_URI = "${LINUXPTP_SRC_URI}/files/"
 UPSTREAM_CHECK_REGEX = "(?P<pver>\d+(\.\d+)+)/"
 
@@ -23,6 +27,8 @@  EXTRA_OEMAKE = "ARCH=${TARGET_ARCH} EXTRA_CFLAGS='${CFLAGS}' mandir=${mandir}"
 
 export KBUILD_OUTPUT="${RECIPE_SYSROOT}"
 
+LINUXPTP_SYSTEMD_SERVICES = "phc2sys@.service ptp4l@.service"
+
 do_install() {
     oe_runmake install DESTDIR=${D} prefix=${prefix}
 
@@ -35,8 +41,18 @@  do_install() {
     install -d ${D}/${sysconfdir}/linuxptp/
     install -m 644 ${S}/configs/default.cfg \
         ${D}${sysconfdir}/linuxptp/ptp4l.conf
+
+    # Install systemd services
+    install -d ${D}/${systemd_unitdir}/system/
+    for service in ${LINUXPTP_SYSTEMD_SERVICES}; do
+        install -m 644 ${WORKDIR}/systemd/$service \
+            ${D}/${systemd_unitdir}/system/$service
+    done
 }
 
+SYSTEMD_SERVICE:${PN} = "${LINUXPTP_SYSTEMD_SERVICES}"
+SYSTEMD_AUTO_ENABLE:${PN} = "disable"
+
 PACKAGES =+ "${PN}-configs"
 
 FILES:${PN}-configs += "${docdir}"