Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing a Nodejs application that the user interacts with via HTTP on localhost. There are practically no parameters and the daemon has virtually no dependencies and it just needs to be up by log-in time.

I would like to follow the idioms on each platform for start-up scripts, and that means Upstart on Ubuntu and systemd on Fedora.

  • Are there any good tutorials for writing systemd system files?
  • Are there any 'best practices' to be aware of?

I have found these resources:

I am mostly looking for an API of sorts as a reference, as well as a basic format to follow.

share|improve this question
> man systemd.service > > man systemd.unit – truezion Feb 2 '14 at 13:30
up vote 14 down vote accepted

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.

share|improve this answer
The man pages will be useful (I wish it was cleaner though), but is there a basic system file tutorial? Like which parts are necessary, which parts are recommended, and which parts are optional. The man pages seem to assume that I'm already an expert in systemd system files, which I am not. – tjameson Jun 21 '11 at 15:54
Not that I am aware of, unfortunately. There is probably an assumption that if you are writing initscripts, you already know how to write initscripts. Look through the Arch scripts and pick one that is similar to what you need: archlinux.org/packages/community/i686/systemd – jasonwryan Jun 21 '11 at 18:28
Thanks! With your help and the blog I found, I was able to get a basic one working. Systemd seems a lot nicer than upstart or the old systemv init daemon. – tjameson Jun 22 '11 at 4:47
@tjameson, that is what man pages are for... – vonbrand Feb 3 '14 at 2:31
Who has time in there lives to START with that. I mean, if you know what you are doing that is a great reference, but holy cow the manual pages are complex. – macmadness86 Apr 6 '15 at 16:51

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 /usr/lib/systemd/system/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"


Step 2:

systemctl enable foo

(similarly you can disable it)

(optional) Step 3: It should start automatically at next reboot into graphical mode (run level 5) but if you want to start it right away:

systemctl start foo
systemctl status foo # optional, just to verify
share|improve this answer
Thanks for posting a quick tutorial and not just linking to offsite man pages! – Toby J Apr 1 '15 at 2:50
@tobyj you're welcome. I'm glad you found out useful. Thanks for the feedback. – necromancer Apr 2 '15 at 5:41
systemctl has a cat command shortcut, for reference. – wurde Jan 11 at 0:04
What is the cat command shortcut? Like a way to create and edit the systemd control files without entering the whole path? – JpaytonWPD Feb 1 at 13:23

The Arch Linux Wiki page about systemd has an interesting section about writing service files. On the same Wiki, there is also a page with lots of examples.

share|improve this answer
Your page with lots of examples link is broken, here is the correct one. – x-yuri Oct 14 '14 at 16:13
Thank you @x-yuri. I've corrected the link. – Rudy Matela Oct 16 '14 at 10:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.