Systemd tutorial

Systemd usually requires two files:

  1. service file
  2. timer file

Service files

Here you provide the details you’d use to

Service is usually made up of 3 sections:

  1. Unit
  2. Service
  3. Install
    • Usually prefer multi-user.target for your installation

One example is as follows:

[Unit]
Description=Foo

[Service]
ExecStart=/usr/sbin/foo-daemon

[Install]
WantedBy=multi-user.target

Here’s what your regular Service section would look like:

User=<YOUR_LINUX_ACCOUNT>
Group=<YOUR_LINUX_GROUP>
WorkingDirectory=<PROJECT_FOLDER>
Type=forking
KillMode=process
Restart=always
ExecStart=<COMMAND_TO_START>
ExecStop=<COMMAND_TO_STOP>

Timers

Timer files contain information about a timer controlled and supervised by systemd, for timer-based activation. This is possibly a better replacement for cron jobs. However, the changes are a bit different.

To set up a timer, you need the following options:

They all help you set up your timers relative to different starting points.

Some other options you could use are:

Here’s one simple sample for setting a timer

[Timer]
AccuracySec=1us
Persistent=false
OnBootSec=80
OnCalendar=*:0/20
Unit=myjob.service

[Install]
WantedBy=timers.target

Some references:

https://wiki.archlinux.org/index.php/Systemd/Timers https://www.certdepot.net/rhel7-use-systemd-timers/

comments powered by Disqus