RHCSAv10 · RHEL 10

Exercises

Exercise: build a systemd service

updated 2026-10-19 by seed

Tasks

  1. Create /usr/local/bin/ticker.sh writing a timestamp to /var/log/ticker.log every 5 s.
  2. Create ticker.service, running as nobody, restarted automatically on failure.
  3. Enable it at boot and start it now.
  4. Prove it with journalctl and with the file content.

Verify

systemctl is-enabled ticker.service     # enabled
systemctl is-active  ticker.service     # active
journalctl -u ticker -n 5 --no-pager
tail -3 /var/log/ticker.log

Solution

sudo tee /usr/local/bin/ticker.sh >/dev/null <<'EOF'
#!/bin/bash
while true; do date -Is >> /var/log/ticker.log; sleep 5; done
EOF
sudo chmod 755 /usr/local/bin/ticker.sh
sudo tee /etc/systemd/system/ticker.service >/dev/null <<'EOF'
[Unit]
Description=Ticker
[Service]
User=nobody
ExecStart=/usr/local/bin/ticker.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
sudo touch /var/log/ticker.log && sudo chown nobody /var/log/ticker.log
sudo restorecon -v /etc/systemd/system/ticker.service
sudo systemctl daemon-reload && sudo systemctl enable --now ticker.service