Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
[Unit]
Description=Good morning lazybones!

[Service]
Type=oneshotsimple
ExecStart=/bin/echo "Dear lazybones!, it's a new morning. Love from your system @$(date)" > /var/www/good-morning
Restart=on-failure
RestartSec=30s


Info

The Restart=on-failure and RestartSec=30s aren't really needed here but are handy if we might reasonably expect our ExecStart process to fail (e.g. unclean exit code) and we wanted it to keep trying until it succeeded.

We can this by reloading units in systemd and running our service (can then check that the file was generated):

...

The Persistent option enables the service to trigger if it didn't when it should have previously (e.g because the computer/server was down / off / thrown out the window etc.).

Let's now reload systemd, enable, and enable start the timer:

Code Block
languagebash
sudo systemctl daemon-reload
sudo systemctl enable good-morning.timer
sudo systemctl start good-morning.timer

That's it.  You should now get a nice (rude?) text file created in /var/www every morning at 6.30am.

...