All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] logrotate: Add systemd support
@ 2017-03-23 14:52 Romain Perier
  2017-03-23 15:52 ` Romain Perier
  0 siblings, 1 reply; 2+ messages in thread
From: Romain Perier @ 2017-03-23 14:52 UTC (permalink / raw)
  To: liezhi.yang; +Cc: yocto, openembedded-core

Currently, this recipe only supports daily scheduling via a cron job.
This commit adds support for systemd, including systemd service and
systemd timer. When the corresponding distro feature is enabled the
systemd timer will be used instead of the cron job.

Signed-off-by: Romain Perier <romain.perier@collabora.com>
---

Note: I was not registered on the yocto and oe ML, I subscribed. So
I resend for this reason (my bad).

 .../logrotate/logrotate/logrotate.service          |  9 +++++++++
 .../logrotate/logrotate/logrotate.timer            |  7 +++++++
 meta/recipes-extended/logrotate/logrotate_3.9.1.bb | 22 ++++++++++++++++++++--
 3 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 meta/recipes-extended/logrotate/logrotate/logrotate.service
 create mode 100644 meta/recipes-extended/logrotate/logrotate/logrotate.timer

diff --git a/meta/recipes-extended/logrotate/logrotate/logrotate.service b/meta/recipes-extended/logrotate/logrotate/logrotate.service
new file mode 100644
index 0000000..3edb8ef
--- /dev/null
+++ b/meta/recipes-extended/logrotate/logrotate/logrotate.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Rotate log files
+
+[Service]
+Type=oneshot
+ExecStart=/usr/sbin/logrotate /etc/logrotate.conf
+Nice=19
+IOSchedulingClass=best-effort
+IOSchedulingPriority=7
diff --git a/meta/recipes-extended/logrotate/logrotate/logrotate.timer b/meta/recipes-extended/logrotate/logrotate/logrotate.timer
new file mode 100644
index 0000000..a92ba1e
--- /dev/null
+++ b/meta/recipes-extended/logrotate/logrotate/logrotate.timer
@@ -0,0 +1,7 @@
+[Unit]
+Description=Daily rotation of log files
+
+[Timer]
+OnCalendar=daily
+AccuracySec=12h
+Persistent=true
diff --git a/meta/recipes-extended/logrotate/logrotate_3.9.1.bb b/meta/recipes-extended/logrotate/logrotate_3.9.1.bb
index 5f1a601..734d661 100644
--- a/meta/recipes-extended/logrotate/logrotate_3.9.1.bb
+++ b/meta/recipes-extended/logrotate/logrotate_3.9.1.bb
@@ -14,6 +14,8 @@ SRC_URI = "https://fedorahosted.org/releases/l/o/logrotate/logrotate-${PV}.tar.g
            file://act-as-mv-when-rotate.patch \
            file://update-the-manual.patch \
            file://disable-check-different-filesystems.patch \
+           ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'file://logrotate.service', '', d)} \
+           ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'file://logrotate.timer', '', d)} \
             "
 
 SRC_URI[md5sum] = "4492b145b6d542e4a2f41e77fa199ab0"
@@ -47,6 +49,14 @@ EXTRA_OEMAKE = "\
 # INSTALL=install and BASEDIR=/usr.
 OS_NAME = "Linux"
 
+inherit systemd
+
+SYSTEMD_AUTO_ENABLE = "disable"
+SYSTEMD_SERVICE_${PN} = "\
+    ${PN}.service \
+    ${PN}.timer \
+"
+
 do_compile_prepend() {
     # Make sure the recompile is OK
     rm -f ${B}/.depend
@@ -55,9 +65,17 @@ do_compile_prepend() {
 do_install(){
     oe_runmake install DESTDIR=${D} PREFIX=${D} MANDIR=${mandir}
     mkdir -p ${D}${sysconfdir}/logrotate.d
-    mkdir -p ${D}${sysconfdir}/cron.daily
     mkdir -p ${D}${localstatedir}/lib
     install -p -m 644 examples/logrotate-default ${D}${sysconfdir}/logrotate.conf
-    install -p -m 755 examples/logrotate.cron ${D}${sysconfdir}/cron.daily/logrotate
     touch ${D}${localstatedir}/lib/logrotate.status
+
+    # Install systemd unit files
+    if [ "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'systemd', '', d)}" = "systemd" ]; then
+        install -d ${D}/${systemd_system_unitdir}
+        install -m 0644 ${WORKDIR}/logrotate.service ${D}/${systemd_system_unitdir}/logrotate.service
+        install -m 0644 ${WORKDIR}/logrotate.timer ${D}/${systemd_system_unitdir}/logrotate.timer
+    else
+        mkdir -p ${D}${sysconfdir}/cron.daily
+        install -p -m 0755 examples/logrotate.cron ${D}${sysconfdir}/cron.daily/logrotate
+    fi
 }
-- 
1.8.3.1



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

* Re: [PATCH RESEND] logrotate: Add systemd support
  2017-03-23 14:52 [PATCH RESEND] logrotate: Add systemd support Romain Perier
@ 2017-03-23 15:52 ` Romain Perier
  0 siblings, 0 replies; 2+ messages in thread
From: Romain Perier @ 2017-03-23 15:52 UTC (permalink / raw)
  To: liezhi.yang; +Cc: yocto, openembedded-core

Hello,

Please ignore this patch, I will send a v2 with improvements.

Regards,

Romain

Le 23/03/2017 à 15:52, Romain Perier a écrit :
> Currently, this recipe only supports daily scheduling via a cron job.
> This commit adds support for systemd, including systemd service and
> systemd timer. When the corresponding distro feature is enabled the
> systemd timer will be used instead of the cron job.
>
> Signed-off-by: Romain Perier <romain.perier@collabora.com>
> ---
>
> Note: I was not registered on the yocto and oe ML, I subscribed. So
> I resend for this reason (my bad).
>
>  .../logrotate/logrotate/logrotate.service          |  9 +++++++++
>  .../logrotate/logrotate/logrotate.timer            |  7 +++++++
>  meta/recipes-extended/logrotate/logrotate_3.9.1.bb | 22 ++++++++++++++++++++--
>  3 files changed, 36 insertions(+), 2 deletions(-)
>  create mode 100644 meta/recipes-extended/logrotate/logrotate/logrotate.service
>  create mode 100644 meta/recipes-extended/logrotate/logrotate/logrotate.timer
>
> diff --git a/meta/recipes-extended/logrotate/logrotate/logrotate.service b/meta/recipes-extended/logrotate/logrotate/logrotate.service
> new file mode 100644
> index 0000000..3edb8ef
> --- /dev/null
> +++ b/meta/recipes-extended/logrotate/logrotate/logrotate.service
> @@ -0,0 +1,9 @@
> +[Unit]
> +Description=Rotate log files
> +
> +[Service]
> +Type=oneshot
> +ExecStart=/usr/sbin/logrotate /etc/logrotate.conf
> +Nice=19
> +IOSchedulingClass=best-effort
> +IOSchedulingPriority=7
> diff --git a/meta/recipes-extended/logrotate/logrotate/logrotate.timer b/meta/recipes-extended/logrotate/logrotate/logrotate.timer
> new file mode 100644
> index 0000000..a92ba1e
> --- /dev/null
> +++ b/meta/recipes-extended/logrotate/logrotate/logrotate.timer
> @@ -0,0 +1,7 @@
> +[Unit]
> +Description=Daily rotation of log files
> +
> +[Timer]
> +OnCalendar=daily
> +AccuracySec=12h
> +Persistent=true
> diff --git a/meta/recipes-extended/logrotate/logrotate_3.9.1.bb b/meta/recipes-extended/logrotate/logrotate_3.9.1.bb
> index 5f1a601..734d661 100644
> --- a/meta/recipes-extended/logrotate/logrotate_3.9.1.bb
> +++ b/meta/recipes-extended/logrotate/logrotate_3.9.1.bb
> @@ -14,6 +14,8 @@ SRC_URI = "https://fedorahosted.org/releases/l/o/logrotate/logrotate-${PV}.tar.g
>             file://act-as-mv-when-rotate.patch \
>             file://update-the-manual.patch \
>             file://disable-check-different-filesystems.patch \
> +           ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'file://logrotate.service', '', d)} \
> +           ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'file://logrotate.timer', '', d)} \
>              "
>  
>  SRC_URI[md5sum] = "4492b145b6d542e4a2f41e77fa199ab0"
> @@ -47,6 +49,14 @@ EXTRA_OEMAKE = "\
>  # INSTALL=install and BASEDIR=/usr.
>  OS_NAME = "Linux"
>  
> +inherit systemd
> +
> +SYSTEMD_AUTO_ENABLE = "disable"
> +SYSTEMD_SERVICE_${PN} = "\
> +    ${PN}.service \
> +    ${PN}.timer \
> +"
> +
>  do_compile_prepend() {
>      # Make sure the recompile is OK
>      rm -f ${B}/.depend
> @@ -55,9 +65,17 @@ do_compile_prepend() {
>  do_install(){
>      oe_runmake install DESTDIR=${D} PREFIX=${D} MANDIR=${mandir}
>      mkdir -p ${D}${sysconfdir}/logrotate.d
> -    mkdir -p ${D}${sysconfdir}/cron.daily
>      mkdir -p ${D}${localstatedir}/lib
>      install -p -m 644 examples/logrotate-default ${D}${sysconfdir}/logrotate.conf
> -    install -p -m 755 examples/logrotate.cron ${D}${sysconfdir}/cron.daily/logrotate
>      touch ${D}${localstatedir}/lib/logrotate.status
> +
> +    # Install systemd unit files
> +    if [ "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'systemd', '', d)}" = "systemd" ]; then
> +        install -d ${D}/${systemd_system_unitdir}
> +        install -m 0644 ${WORKDIR}/logrotate.service ${D}/${systemd_system_unitdir}/logrotate.service
> +        install -m 0644 ${WORKDIR}/logrotate.timer ${D}/${systemd_system_unitdir}/logrotate.timer
> +    else
> +        mkdir -p ${D}${sysconfdir}/cron.daily
> +        install -p -m 0755 examples/logrotate.cron ${D}${sysconfdir}/cron.daily/logrotate
> +    fi
>  }



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

end of thread, other threads:[~2017-03-23 15:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-23 14:52 [PATCH RESEND] logrotate: Add systemd support Romain Perier
2017-03-23 15:52 ` Romain Perier

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.