Skip to content

Commit

Permalink
Migrated Cron job to Systemd timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Dikshit committed Mar 10, 2023
1 parent de6f785 commit 597c6a8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
5 changes: 5 additions & 0 deletions amzn-changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Thu Mar 09 2023 Nikhil Dikshit <[email protected]> 2.0-1.amzn2023.0.3
- Migrated Cron job to Systemd timer
- Trigger update-motd.service after cloud-final.service
- Set RemainAfterExit=no on update-motd so that timer can restart it after exit

* Thu Feb 02 2023 Stewart Smith <[email protected]> - 2.0-1.amzn2023.0.2
- Mass rebuild for AL2023

Expand Down
4 changes: 0 additions & 4 deletions cron_update-motd

This file was deleted.

8 changes: 6 additions & 2 deletions update-motd.service
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[Unit]
Description=Dynamically Generate Message Of The Day
After=network-online.target
# running update-motd.service after cloud-final.service, which will be later in the boot process
# this is to avoid running update-motd at the same time with other services such as dnf activities in userdata scripts
After=network-online.target cloud-final.service

[Service]
Type=oneshot
ExecStart=/usr/sbin/update-motd
RemainAfterExit=yes
# update-motd should not be considered active when its processes have exited
# timer should be able to restart update-motd even after exit
RemainAfterExit=no

[Install]
WantedBy=multi-user.target
9 changes: 4 additions & 5 deletions update-motd.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%define _trivial .0
%define _buildid .2
%define _buildid .3
Name: update-motd
Version: 2.0
Release: 1%{?dist}%{?_trivial}%{?_buildid}
Expand All @@ -13,7 +13,7 @@ BuildRequires: systemd-devel
%{?systemd_requires}

Source0: sbin_update-motd
Source1: cron_update-motd
Source1: update-motd.timer
Source2: update-motd.service

%description
Expand All @@ -24,7 +24,7 @@ Based on and compatible with the framework implemented Ubuntu.
rm -rf %{buildroot}
install -d %{buildroot}/etc/update-motd.d
install -D -m 0755 %{SOURCE0} %{buildroot}/usr/sbin/update-motd
install -D -m 0644 %{SOURCE1} %{buildroot}/etc/cron.d/update-motd
install -D -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/update-motd.timer
install -D -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/update-motd.service
# for %ghost
install -d %{buildroot}/var/lib/update-motd
Expand Down Expand Up @@ -62,8 +62,7 @@ fi
%defattr(-,root,root,-)
%dir /etc/update-motd.d
%dir /var/lib/update-motd
%config /etc/cron.d/update-motd
%config %{_unitdir}/update-motd.service
%config %{_unitdir}/update-motd.{service,timer}
/usr/sbin/update-motd
%ghost /var/lib/update-motd/motd

Expand Down
11 changes: 11 additions & 0 deletions update-motd.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Timer for Dynamically Generate Message Of The Day

[Timer]
OnUnitActiveSec=720min
RandomizedDelaySec=720min
FixedRandomDelay=true
Persistent=true

[Install]
WantedBy=timers.target

0 comments on commit 597c6a8

Please sign in to comment.