Chinese Yellow Pages | Classifieds | Knowledge | Tax | IME

systemd vs sysVinit cheatsheet

 

Systemd template and instance (@)

from: https://wiki.archlinux.org/index.php/systemd

Note: Some unit names contain an @ sign (e.g. name@string.service): this means that they are instances of a template unit, whose actual file name does not contain the string part (e.g. name@.service). string is called the instance identifier, and is similar to an argument that is passed to the template unit when called with the systemctl command: in the unit file it will substitute the %i specifier.

To be more accurate, before trying to instantiate the name@.suffix template unit, systemd will actually look for a unit with the exact name@string.suffix file name, although by convention such a “clash” happens rarely, i.e. most unit files containing an @ sign are meant to be templates. Also, if a template unit is called without an instance identifier, it will just fail, since the %i specifier cannot be substituted.

SystemD timer ( as cron replacement)

create something.service first, then create timer unit with the same name but with *.timer

e.g:  
to replace cron job:
*/10 * * * * /usr/bin/date >> /tmp/date

we create /etc/systemd/system/date.service first:
[Unit]
Description=Prints date into /tmp/date file
[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c '/usr/bin/date >> /tmp/date'


then a /etc/systemd/system/date.timer:
[Unit]
Description=Run date.service every 10 minutes
Unit=date.service
[Timer] 
OnCalendar=*:0/10 

This config will run date.service every 10 minutes.
systemctl list-timers
systemctl list-timers --all
systemctl start date.timer to enable timer.

Leave a Reply

Your email address will not be published. Required fields are marked *