The following example is inspired by this link, which actually does not mention all steps and is listed just to credit the source: http://patrakov.blogspot.com/2011/01/writing-systemd-service-files.html
Step 1: I created this file (note location) which essentially fires a bash process with an extended argument. You could fire your own command which could be different from bash.
[root@y500-fedora ~]# cat /etc/systemd/system/foo.service [Unit] Description=foo [Service] ExecStart=/bin/bash -c "while true; do /bin/inotifywait -qq --event close_write /sys/class/backlight/acpi_video0/brightness; su myusername -c '/bin/xbacklight -display :0 -set $(cat /sys/class/backlight/acpi_video0/brightness)'; done" [Install] WantedBy=multi-user.target
Start the new service:
systemctl enable foo
(similarly you can
(optional) Step 3: It should start automatically at next reboot into multi-user mode (run level 3) but if you want to start it right away:
systemctl start foo systemctl status foo # optional, just to verify
Update: For completeness, I should add that ubuntu bionic seems to have a very thorough man page. RTFM here
I would start with the Systemd manual pages. They represent a comprehensive resource of the system and services.
There is also the freedesktop Systemd FAQs.
The Redhat documentation is a great source.
- CREATING AND MODIFYING SYSTEMD UNIT FILES on RHEL7
- MANAGING SERVICES WITH SYSTEMD | Introduction to systemd