Take the 2-minute tour ×
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.

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

4 Answers 4

up vote 8 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
1  
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
1  
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 at 2:31

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 
[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=graphical.target

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
1  
Terrific, thanks for you understanding! Feel free to delete our comment exchange, it's no longer relevant. –  slm May 4 '13 at 1:17

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 at 16:13
    
Thank you @x-yuri. I've corrected the link. –  Rudy Matela Oct 16 at 10:33

man systemd.service

man systemd.unit

share|improve this answer
4  
Some details would surely make this a much better answer. As it stands it more of a comment. –  slm Feb 2 at 14:50
2  
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  jasonwryan Feb 2 at 16:23
2  
@slm, that is exactly one of the reasons why I'm find it strange that there is a reputation limit on commenting, but not on answering (OP currently has reputation 1 here). –  vonbrand Feb 3 at 1:19
    
@vonbrand - I agree, seems like it should almost be the other way around. –  slm Feb 3 at 1:58

Your Answer

 
discard

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.