Return to Video

981_Making_your_package_work_with_systemd.ogv

  • 0:00 - 0:05
    [stapelberg]: Hi! So first of all, the type of this lecture
  • 0:05 - 0:07
    is that it's going to be a workshop, just to make the expectations
  • 0:07 - 0:09
    clear, I have a few slides prepared that
  • 0:09 - 0:11
    should give you a general introduction
  • 0:11 - 0:13
    and they will take
  • 0:13 - 0:15
    probably about half of the time we have allocated
  • 0:15 - 0:17
    for this slot, and afterwards
  • 0:17 - 0:19
    we can answer your questions
  • 0:19 - 0:21
    or have some hands-down hacking
  • 0:21 - 0:23
    on actual packages.
  • 0:23 - 0:25
    My name is Michael Stapelberg
  • 0:25 - 0:27
    Just a quick show of hands so that I know my audience --
  • 0:27 - 0:29
    who of you maintains a Debian package
  • 0:29 - 0:31
    in Debian or derivatives?
  • 0:31 - 0:33
    OK, that's almost everybody
  • 0:33 - 0:35
    Perfect.
  • 0:35 - 0:37
    How many of you actually added
  • 0:37 - 0:39
    systemd support to their packages already?
  • 0:39 - 0:41
    OK, a couple.
  • 0:41 - 0:44
    Who of you are looking into doing that?
  • 0:45 - 0:48
    OK, perfect! You are exactly the right audience.
  • 0:48 - 0:51
    Great. So the topics I want to cover with my slides are:
  • 0:51 - 0:51
    First of all, how systemd works for package maintainers
    Great. So the topics I want to cover with my slides are:
  • 0:51 - 0:55
    First of all, how systemd works for package maintainers
  • 0:55 - 0:55
    That means I'm not going to cover all of it
    First of all, how systemd works for package maintainers
  • 0:55 - 0:58
    That means I'm not going to cover all of it
  • 0:58 - 1:02
    And also it's not so much of a user standpoint
  • 1:02 - 1:06
    but just what you need to know to get you started on testing your stuff in systemd.
  • 1:06 - 1:10
    We will then have a look at an example service file
  • 1:10 - 1:13
    where we'll make clear what all the different directives are supposed to mean
  • 1:13 - 1:16
    We will look at the tmpfiles mechanism
  • 1:16 - 1:18
    and at dh-systemd, a debhelper plugin
  • 1:18 - 1:22
    We will consider a few more advanced examples, and then finally we will
  • 1:22 - 1:24
    answer your questions, hopefully.
  • 1:24 - 1:29
    So, non-topics for this presentation are:
  • 1:29 - 1:32
    systemd sucks, let's just use something else instead
  • 1:32 - 1:37
    When will debian ever finally switch the default, and essentially anything that ever came up on debian-devel. I'm not going to talk about that.
  • 1:37 - 1:42
    This is just about how to make it work if you have already accepted that this is something that you want to do.
  • 1:42 - 1:44
    So, how does systemd work?
  • 1:44 - 1:49
    Essentially, where we previously had initscripts, we now have service files.
  • 1:49 - 1:52
    Service files are just a special kind of unit files
  • 1:52 - 1:58
    so the more generic term is unit files and that which corresponds to an initscript is a service file.
  • 1:58 - 2:04
    So previously, you would have /etc/init.d/apache2 as an initscript
  • 2:04 - 2:10
    and the corresponding file would be /lib/systemd/system/apache2.service
  • 2:10 - 2:13
    Now what's important here to notice
  • 2:13 - 2:17
    Is that the base name (apart from the .service suffix)
  • 2:17 - 2:20
    needs to be the same, because what will happen is that
  • 2:20 - 2:23
    systemd, when booting on a machine
  • 2:23 - 2:26
    will look at all the services in /etc/init.d
  • 2:26 - 2:28
    and use them if they are available
  • 2:28 - 2:32
    but if there is also a service file, that will take precedence.
  • 2:32 - 2:36
    So in order to make sure that systemd uses your service file and not
  • 2:36 - 2:40
    your service file plus the old initscript, make sure that the name is correct.
  • 2:40 - 2:43
    Before you ask, yes there are also mechanisms to make sure that
  • 2:43 - 2:47
    when you have a name transition, because you've adopted the upstream name for a service file
  • 2:47 - 2:50
    or something like that, then you can have a compatibility symlink.
  • 2:50 - 2:52
    We can cover that later.
  • 2:52 - 2:56
    And essentially, systemctl does what service did.
  • 2:56 - 2:59
    So if you had service apache2 start
  • 2:59 - 3:02
    Then you would use systemctl start apache2.service
  • 3:02 - 3:07
    In recent versions, you can even skip the .service suffix so it would just be systemctl start apache2
  • 3:08 - 3:13
    The systemctl tool is mostly for the actual users, or for you when testing.
  • 3:13 - 3:19
    and just like you would usually use /etc/init.d/apache2 start as an actual user
  • 3:19 - 3:23
    but "service" inside your maintenance script, we have something for that.
  • 3:24 - 3:29
    Now, what we had in SystemV init were runlevels
  • 3:29 - 3:33
    and they were poorly defined and different from distribution to distribution
  • 3:33 - 3:36
    And what systemd does to replace them is that it has something called a target.
  • 3:36 - 3:41
    A target is precisely the same as a runlevel
  • 3:41 - 3:43
    it just has a much nicer name
  • 3:43 - 3:48
    and the names are standardized between all the different distributions.
  • 3:48 - 3:53
    The most important targets for you are basic.target, multi-user.target and graphical.target
  • 3:53 - 3:57
    Each of them is more specific than the other
  • 3:57 - 4:00
    in that it starts more services for a particular use case
  • 4:00 - 4:03
    So basic.target is what everybody of you will run
  • 4:03 - 4:07
    and then multi-user.target extends basic.target with more stuff
  • 4:07 - 4:12
    and graphical.target brings in all the graphical components like a display manager
  • 4:12 - 4:16
    and stuff that you would normally not use on servers where multi-user.target is what you would want to use.
  • 4:16 - 4:21
    You can look that up if you care later on in the manpage systemd.special.
  • 4:22 - 4:26
    Just as previously, with SystemV init
  • 4:26 - 4:28
    we had symlinks to enable a service
  • 4:28 - 4:31
    and these symlinks were created by update-rc.d
  • 4:31 - 4:34
    we still have symlinks to enable a service
  • 4:34 - 4:36
    now they're just created by systemctl enable
  • 4:37 - 4:42
    Again, systemctl is what you would use as a user, or while testing, etc.
  • 4:42 - 4:45
    And we have a maintainer script equivalent of that.
  • 4:46 - 4:50
    Are there any questions so far? This is really the basic stuff.
  • 4:58 - 5:02
    [question]: What is the reason there are different commands for the user and the maintainer scripts?
  • 5:02 - 5:08
    [stapelberg]: I think will go into this later, but I can just briefly explain it
  • 5:08 - 5:08
    The maintainer scripts also need to work on machines where systemd is not actually installed.
    [stapelberg]: I think will go into this later, but I can just briefly explain it
  • 5:08 - 5:12
    The maintainer scripts also need to work on machines where systemd is not actually installed.
  • 5:12 - 5:14
    So that's why we can't use systemctl.
  • 5:15 - 5:18
    Alright, let's look at an example service file.
  • 5:18 - 5:20
    I just picked vnstat.service
  • 5:20 - 5:27
    which is a tiny daemon that will just store (and plot later on) your network traffic.
  • 5:28 - 5:33
    What you can see here is a very clear, human-readable configuration file
  • 5:33 - 5:36
    And this is the service file. it's called vnstat.service.
  • 5:36 - 5:40
    It starts with a [Unit] section, and you can see
  • 5:40 - 5:44
    just like inifiles, which probably everybody of you is comfortable with
  • 5:44 - 5:48
    or .desktop files, which have the same format, so this is actually a .desktop file.
  • 5:49 - 5:53
    There are sections which are enclosed in square brackets, and then there's key/value pairs
  • 5:53 - 5:56
    separated by an equals sign, so that's really simple.
  • 5:56 - 5:59
    The first section is entirely just for humans.
  • 5:59 - 6:05
    So the description will tell me what kind of service this is, if I'm looking at my system and wondering what is this that's starting up here.
  • 6:06 - 6:10
    The second section is the [Service] section, and this is actually where
  • 6:12 - 6:13
    all the relevant stuff is.
  • 6:13 - 6:18
    What we specify here in the second line is ExecStart, which is
  • 6:18 - 6:22
    the command that systemd will run when trying to start that service.
  • 6:22 - 6:26
    In this case, it's really simple, you just start the vnstatd binary.
  • 6:26 - 6:31
    What you need to notice here though is that systemd does not invoke a shell to start it up,
  • 6:31 - 6:35
    so you need to specify the full path, and you don't have your usual
  • 6:35 - 6:38
    shell stuff in your command line, so just keep that in mind.
  • 6:38 - 6:44
    We also have the ExecReload line, and there could also be an ExecStop line.
  • 6:44 - 6:48
    In the absence of an ExecStop line, systemd will just kill the service
  • 6:48 - 6:53
    And it will do what many many people implemented in initscripts by hand
  • 6:53 - 6:56
    which is to gently try to kill it, and if that doesn't work within a certain timespan
  • 6:56 - 6:59
    then it will try to kill it harder, until it finally succeeds.
  • 7:00 - 7:03
    The ExecReload line is pretty standard
  • 7:03 - 7:09
    the thing is that not all of the services provide a way of reloading in the first place
  • 7:09 - 7:14
    so we need to have such a line to tell systemd what to do on a reload command
  • 7:14 - 7:19
    Some other service (you could probably think of the bind nameserver)
  • 7:19 - 7:23
    have a different way of reloading (so you could call "rndc reload" in that case)
  • 7:23 - 7:28
    but this one is really simple, it just sends SIGHUP to the service, and then it will reload.
  • 7:28 - 7:32
    the $MAINPID is not actually a shell variable or anything
  • 7:32 - 7:37
    it's just a special thing that you can use in unit files and service files in particular.
  • 7:37 - 7:41
    And then we also have the User= line which will specify
  • 7:41 - 7:45
    under which user this program will be started. That's pretty straightforward.
  • 7:46 - 7:48
    The last section is also interesting
  • 7:48 - 7:51
    it's called the [Install] section, and it has a line called
  • 7:51 - 7:54
    WantedBy=multi-user.target
  • 7:54 - 7:57
    And that essentially says that when this service file
  • 7:57 - 7:59
    is enabled on the machine
  • 7:59 - 8:03
    it will be pulled in by multi-user.target, so this specifies
  • 8:03 - 8:06
    which runlevel it runs in, so to say.
  • 8:06 - 8:10
    Are there any questions so far?
  • 8:11 - 8:13
    yes -- microphone?
  • 8:15 - 8:19
    [question]: can there be more than one WantedBy= line?
  • 8:19 - 8:21
    [stapelberg]: Yes, there can be multiple WantedBy= lines.
  • 8:23 - 8:24
    More questions -- over there?
  • 8:28 - 8:30
    [question]: So just to make sure that I understand correctly
  • 8:30 - 8:35
    If systemd tries to restart or reload a service
  • 8:35 - 8:38
    it first executes this reload phrase, and then it execs
  • 8:38 - 8:39
    the start phrase again?
  • 8:39 - 8:43
    [stapelberg]: No, there's two different cases here. One is the reload case
  • 8:43 - 8:45
    and the other one is the restart case.
  • 8:45 - 8:49
    In the reload case, it just executes what's specified here
  • 8:49 - 8:53
    If the service file supports reloading; if it doesn't, then you can't reload it.
  • 8:53 - 8:55
    If you do a restart, it will
  • 8:55 - 8:59
    first execute stop if present, or kill it if not present, and then start it again.
  • 8:59 - 8:59
    [question]: Fine. OK, thank you.
    first execute stop if present, or kill it if not present, and then start it again.
  • 8:59 - 9:01
    [stapelberg]: one more question here?
    [question]: Fine. OK, thank you.
  • 9:01 - 9:02
    [stapelberg]: one more question here?
  • 9:05 - 9:10
    [question]: Is there an equivalent to debian's force-reload,
  • 9:10 - 9:17
    where you care so much about wanting it to reload that you're OK with it falling back to stop and start if necessary?
  • 9:17 - 9:22
    which debian's sysvinit system does support in the usual skeleton file.
  • 9:22 - 9:27
    [stapelberg]: I think there is a try-reload action, but I would have to confirm that. We can do that later.
  • 9:29 - 9:32
    [question]: Is there also something to stop a service?
  • 9:32 - 9:36
    [stapelberg]: Yes, I already mentioned that you can specify ExecStop=, and if you don't, it will just kill it.
  • 9:36 - 9:39
    [question]: Sorry, I didn't hear that.
  • 9:39 - 9:41
    [stapelberg]: one more question here?
  • 9:42 - 9:47
    [question, quoting from a man page]: "tries to reload if possible and falls back to restart"
  • 9:47 - 9:51
    [stapelberg]: He just said there's a "reload-or-restart" command in systemctl that does precisely what you asked for.
  • 9:51 - 9:58
    [question]: Are there other things than start, reload, stop, and ... can you define other things?
  • 9:58 - 10:01
    [stapelberg]: Can you clarify what you mean by that?
  • 10:02 - 10:11
    [question]: For example, status, or I was thinking more about something specific to a certain daemon?
  • 10:11 - 10:15
    For instance, fetchmail can have an "awaken" option
  • 10:15 - 10:19
    it does a sleep of 5 minutes or something, and you can say "check right now"
  • 10:21 - 10:23
    [stapelberg]: What exactly is the question? I still don't get it.
  • 10:23 - 10:26
    [question]: Can you have some exec line in there --
  • 10:26 - 10:31
    [stapelberg]: -- Oh, can we have a custom action, like in initscripts, is that what you mean? No, we can't.
  • 10:31 - 10:35
    There are different ways of coping with that:
  • 10:35 - 10:39
    Most often there's an alternative to what you want to do
  • 10:39 - 10:47
    But I think it's really clean and nice that they standardized on a few verbs, and all of these work with all of the services
  • 10:47 - 10:48
    (except for the reload one, obviously)
  • 10:48 - 10:51
    but you can't have really custom weird stuff.
  • 10:51 - 10:57
    You could ship that in an additional shell script. That's what I would usually use as a first suggestion
  • 10:57 - 11:01
    if there's no specific, no better way of solving the problem. But we can discuss that later on.
  • 11:01 - 11:03
    for specific services that you might have in mind.
  • 11:04 - 11:07
    Any more general questions up until here?
  • 11:10 - 11:18
    [question]: Maybe you answered and I missed it, but about the possibility of querying the status of the service?
  • 11:18 - 11:23
    [stapelberg]: Yes, obviously. As I said, I will show that in the second part.
  • 11:23 - 11:27
    Now, tmpfiles:
  • 11:27 - 11:31
    The tmpfiles mechanism is really useful not only within systemd
  • 11:31 - 11:36
    but also oftentimes when people read about it they think "hey, this could be useful standalone."
  • 11:36 - 11:44
    What it does, is it provides a mechanism to configure creating temporary directories, like runtime directories.
  • 11:44 - 11:50
    As a really simple example, I have here the lighttpd configuration file
  • 11:50 - 11:54
    where we will essentially say "create a directory called /run/lighttpd"
  • 11:54 - 11:59
    with this mode, this user, this group, and no more arguments.
  • 11:59 - 12:06
    There are some arguments you could specify there, for cleaning it up every ten days or some delay like that
  • 12:06 - 12:11
    that's all supported. This mechanism is much more powerful than this very simple example.
  • 12:11 - 12:16
    it can also support not only directories, but also files, pipes, symlinks, etc.
  • 12:16 - 12:22
    I don't want to go into all of the details, but this is the preferred mechanism to create a /run/something
  • 12:22 - 12:29
    and it's much much cleaner than having all these varying mkdir commands
  • 12:29 - 12:34
    that sometimes specify a user and a group and sometimes they don't and then they don't have a mode, etc. etc.
  • 12:34 - 12:38
    So this is what we want to use. Question?
  • 12:41 - 12:47
    [question]: There's no implicit conflict with other things, so I have to take care to do a proper namespace organization?
  • 12:47 - 12:51
    and, for example, call my temporary directory like my service and not
  • 12:51 - 12:55
    choose an arbitrary name which would perhaps clash with another service?
  • 12:55 - 12:59
    [stapelberg]: Sure. I mean obviously you need to watch out for filesystem clashes in debian packages.
  • 12:59 - 13:01
    That's just as it always has been.
  • 13:01 - 13:03
    [question]: So it's the mechanism, you have to provide the policy.
  • 13:03 - 13:05
    [stapelberg]: Yes, obviously.
  • 13:05 - 13:09
    Alright -- service file location:
  • 13:09 - 13:15
    oftentimes, the upstream provider ships a service file, and that's the way it's meant to be.
  • 13:15 - 13:22
    because the upstream should know best how to install the service on a particular machine
  • 13:22 - 13:26
    Now, that doesn't always happen
  • 13:26 - 13:29
    but if it happens please use the upstream service file
  • 13:29 - 13:33
    and if the upstream file is really broken, please work with upstream to fix it
  • 13:33 - 13:35
    If it's broken in some minor detail, you might ask upstream
  • 13:35 - 13:39
    if it's acceptable to change it in the way that it would be better
  • 13:39 - 13:44
    I don't have any specific details; one example that would come to mind is that some
  • 13:44 - 13:50
    upstream service files are actually pretty old -- like they were written in 2009 or something
  • 13:50 - 13:54
    and by now they're, for example, referring to syslog.target as a dependency
  • 13:54 - 13:58
    whereas syslog is autostarted nowadays by socket activation.
  • 13:58 - 14:01
    So that could be removed, and then the service file would be simpler
  • 14:01 - 14:05
    and more idiomatic, and that would be a typical change that you could push upstream
  • 14:05 - 14:09
    I don't say that I expect any of you to know what the idiomatic service files
  • 14:09 - 14:14
    are, and contribute that upstream; I'm just saying that it would be the right thing to do.
  • 14:14 - 14:14
    Question?
  • 14:14 - 14:21
    [question]: So you say just write the debian/packagename.service and .tmpfiles
  • 14:21 - 14:28
    but most debhelpers also accept just debian/service and, just the type of the file
  • 14:28 - 14:35
    without the package prefix if there's only one binary package -- is that supported?
  • 14:35 - 14:39
    [stapelberg]: To be honest, I didn't test it, but i'm using the exact same debhelper plugin code
  • 14:39 - 14:42
    that all the others are using, so I would expect it to be supported.
  • 14:42 - 14:45
    What we also support, even though I didn't actually program it
  • 14:45 - 14:46
    is "package.(and then some actual package name)" if it's only for a specific package in a set of all packages
  • 14:46 - 14:51
    [ed: he means sourcepackgename.binarypackagename.service]
    is "package.(and then some actual package name)" if it's only for a specific package in a set of all packages
  • 14:51 - 14:51
    which is a typical debhelper feature in that sense.
    [ed: he means sourcepackgename.binarypackagename.service]
  • 14:51 - 14:53
    which is a typical debhelper feature in that sense.
  • 14:53 - 14:54
    [question]: Thanks!
  • 14:54 - 14:55
    [stapelberg]: Sure.
    [question]: Thanks!
  • 14:55 - 14:55
    [stapelberg]: Sure.
  • 14:55 - 15:01
    Now, to actually cover that point, if upstream actually doesn't ship a service file and/or a tmpfile
  • 15:01 - 15:06
    then you can just place them in debian/$yourpackagename.service and debian/$yourpackagename.tmpfile and it will be installed.
  • 15:06 - 15:10
    It will be installed by dh_installinit, which might confuse you
  • 15:10 - 15:13
    because dh_installinit is for initscripts and not for servicefiles
  • 15:13 - 15:17
    and in fact, we by now have dh_systemd, so that's weird!
  • 15:17 - 15:17
    The only reason why that is is because of historic reasons.
    and in fact, we by now have dh_systemd, so that's weird!
  • 15:17 - 15:20
    The only reason why that is is because of historic reasons.
  • 15:20 - 15:23
    We first started implementing it in dh_installinit,
  • 15:23 - 15:23
    but then it turned out that it would make the helper very complex and weird
    We first started implementing it in dh_installinit,
  • 15:23 - 15:25
    but then it turned out that it would make the helper very complex and weird
  • 15:25 - 15:26
    and handling upstart and sysv and systemd all at the same time is really not a good idea
    but then it turned out that it would make dhelper very complex and weird
  • 15:26 - 15:30
    and handling upstart and sysv and systemd all at the same time is really not a good idea
  • 15:30 - 15:34
    So we decided to leave it there for the time being, but eventually to migrate it
  • 15:34 - 15:40
    If you use just the dh command it will all just work, you don't have to care
  • 15:40 - 15:45
    In all the other cases, currently policy dictates that you still need to ship an initscript
  • 15:45 - 15:52
    so that's all fine, and as soon as policy gets changed, I promise that we will be in a state where you don't have to care about this either.
  • 15:52 - 15:57
    I already mentioned to please send service files upstream, but I'll just stress it again.
  • 15:57 - 16:01
    Not only if you have an upstream service file and modify it and fix it, please send it upstream
  • 16:01 - 16:05
    but also, if you create a service file, please send it upstream so that upstream can distribute it.
  • 16:05 - 16:10
    Some upstream software might not agree; some are actually very thankful.
  • 16:10 - 16:11
    Question over there
  • 16:12 - 16:17
    [question]: Assuming upstream ships a valid service file, what's the best practice:
  • 16:17 - 16:22
    Is it to call dh_installinit specifying the path in the upstream directory,
  • 16:22 - 16:22
    or copying it into the debian directory before dh_installinit is invoked?
    Is it to call dh_installinit specifying the path in the upstream directory,
  • 16:22 - 16:27
    or copying it into the debian directory before dh_installinit is invoked?
  • 16:27 - 16:35
    [stapelberg]: In case upstream installs it, just let upstream install it. I'm not sure I get the question.
  • 16:35 - 16:41
    [question]: The question is: in case upstream does not install it; they ship it, but they do not install it?
  • 16:41 - 16:47
    [stapelberg]: OK, in case they don't install it, and then what is the second part of your question? just put it in debian/ as I explained.
  • 16:48 - 16:53
    [question]: So you can put it manually in debian/ before dh_installinit is invoked.
  • 16:53 - 16:54
    Or you can invoke dh_installinit with the path from the upstream directory
  • 16:54 - 16:55
    [stapelberg]: Oh, right, yes.
    Or you can invoke dh_installinit with the path from the upstream directory
  • 16:55 - 16:59
    Or you can invoke dh_installinit with the path from the upstream directory
  • 16:59 - 17:03
    So if upstream doesn't install it, but ship it
  • 17:03 - 17:03
    [question]: Yes.
    So if upstream doesn't install it, but ship it
  • 17:03 - 17:04
    [stapelberg]: Yeah, you could either manually copy it before, or just use what you suggest.
    [question]: Yes.
  • 17:04 - 17:10
    [stapelberg]: Yeah, you could either manually copy it before, or just use what you suggest.
  • 17:10 - 17:12
    Any more questions?
  • 17:13 - 17:15
    Great, let's move on.
  • 17:15 - 17:23
    Getting your service enabled: I already mentioned that just as with update-rc.d you need to enable services
  • 17:23 - 17:29
    and the easiest way, if you already have a service file shipped by upstream
  • 17:29 - 17:33
    or if you put your own service file into debian/package.service
  • 17:33 - 17:36
    is you add a build dependency on dh-systemd
  • 17:36 - 17:39
    and then you use the dh command, which you hopefully already use
  • 17:39 - 17:43
    and add the --with=systemd flag
  • 17:43 - 17:46
    and then all automatically happens and it will just work.
  • 17:46 - 17:51
    The maintainer scripts that are generated
  • 17:51 - 17:54
    as part of that package build will contain the appropriate code
  • 17:54 - 18:01
    they will call a binary called deb-systemd-helper instead of systemctl as I mentioned earlier
  • 18:01 - 18:07
    which avoids having a dependency on systemd on all the packages which is probably politically not a good move.
  • 18:09 - 18:17
    If you are not using dh, you can also add the dh_systemd_enable and dh_systemd_start calls directly
  • 18:17 - 18:22
    in the wiki we have instructions, and the link is provided on these slides.
  • 18:22 - 18:26
    To test your package -- oh, a question here?
  • 18:26 - 18:31
    [question]: So you mentioned the deb-systemd-helper maintainer scripts
  • 18:31 - 18:37
    I know the scope of systemd is broader than sysvinit, but
  • 18:37 - 18:41
    in the sysvinit world, policy recommends
  • 18:42 - 18:50
    whether or not you are using sysvinit, including other things like sysvrc or openrc or a few of the other minor ones
  • 18:50 - 18:53
    (and I think also upstart) they recommend
  • 18:53 - 19:00
    using invoke-rc.d and update-rc.d in debian maintainer scripts as a way of
  • 19:00 - 19:04
    both abstracting from the specific system and for
  • 19:04 - 19:09
    handling the case where you're debootstrapping and the daemons are not running because of policy-rc.d
  • 19:09 - 19:13
    so the question is: why this instead of those
  • 19:13 - 19:19
    and if policy-rc.d is configured to not start or stop, will this respect that?
  • 19:19 - 19:26
    [stapelberg]: We have another of these helpers called deb-systemd-invoke which is for the invoke-rc.d part
  • 19:26 - 19:31
    and it will try to respect policy. Unfortunately, policy is really hard
  • 19:31 - 19:35
    It's a really horrible standard -- it's underdocumented and I had a really hard time figuring out how it works
  • 19:35 - 19:38
    so it will support the use cases I could identify
  • 19:38 - 19:41
    and if you have use cases that are broken please talk to me and we can try to fix it
  • 19:41 - 19:52
    Also, to answer the first part of your question, update-rc.d is really hard to have a good solution in there
  • 19:52 - 19:59
    we tried implementing it in there, but it turned out to not work that well, and upstream is not that responsive to our concerns.
  • 19:59 - 20:07
    so we actually chose to implement a separate helper that we have under tight control and can release independently of sysvrc
  • 20:07 - 20:12
    which turned out to be a much better solution because we already refactored it once and iterated on it
  • 20:12 - 20:16
    quite a few times, and by now it's actually in a pretty good state.
  • 20:16 - 20:18
    So that's why.
  • 20:18 - 20:23
    Alright! So, to test your package, which is actually the most interesting part
  • 20:24 - 20:30
    you will just install systemd, and then you can boot with the init=/bin/systemd kernel parameter
  • 20:30 - 20:35
    Installing systemd does not involve breaking sysvinit or anything
  • 20:35 - 20:39
    there's no conflicts in that package, you can still have both of them.
  • 20:39 - 20:41
    If you just install systemd, nothing will happen.
  • 20:41 - 20:45
    If you boot with init=/bin/systemd, you will actually use systemd
  • 20:45 - 20:48
    so that distinction is important. You can always switch back and forth.
  • 20:48 - 20:51
    So testing it is really simple. you just reboot.
  • 20:51 - 20:54
    You could reboot in a vm if you don't like to reboot your main machine.
  • 20:54 - 20:59
    Then what you would typically do is you check that your service starts properly on boot
  • 20:59 - 21:04
    You would probably check the reload action, check stop, start, restart, and that's about it, I would say.
  • 21:04 - 21:11
    because there's really not that much more to it, except if your service makes use of really advanced features and all that stuff.
  • 21:11 - 21:21
    In general, I would say that your users will report bug reports if your service does not work with systemd right now
  • 21:21 - 21:26
    There are plenty of users of systemd and debian that care enough to submit bug reports.
  • 21:26 - 21:30
    So it's not expected of you to test it all the time
  • 21:30 - 21:35
    and convert all your systems and run it all the time; a brief test will be enough.
  • 21:37 - 21:41
    Now to an advanced example:
  • 21:41 - 21:46
    There's actually a few more features that were maybe already mentioned if you listened to the previous talk by Lennart
  • 21:46 - 21:51
    We have a nice service called debian codesearch which I happen to maintain
  • 21:51 - 21:54
    And the service file is actually much more complicated.
  • 21:54 - 21:57
    It not only specifies a user and a group
  • 21:57 - 22:00
    It also has some arguments in here, and you can see that
  • 22:00 - 22:04
    the service file format supports line wrapping, so if your command line is pretty long
  • 22:04 - 22:07
    then it might make sense to wrap it and have it really nice.
  • 22:07 - 22:13
    Also, we have standard output redirected to /dev/null because it's really noisy
  • 22:13 - 22:18
    and mostly used for debugging. so when I feel like debugging, I can just change that to get standard output
  • 22:18 - 22:20
    but in the default case I just want standard error
  • 22:20 - 22:26
    Now also, my service does not actually care to log to syslog, so I say that standard error should go to the journal
  • 22:26 - 22:29
    which will then end up in the syslog.
  • 22:29 - 22:37
    Also, I cannot obviously exclude that there are bugs, but I also cannot sit in front of a computer 24/7 and restart my server if it crashes
  • 22:37 - 22:44
    So what I want is that whenever it fails (that is, it exits with an exit code that is not 0)
  • 22:44 - 22:46
    I want it to just wait a second and then restart it.
  • 22:47 - 22:52
    So far I think in production I only restarted my servers once
  • 22:52 - 22:57
    and then promptly fixed the bug so most of the time it's perfect, but you know: better safe than sorry!
  • 22:57 - 23:02
    The other parts of the unit file are probably clear by now
  • 23:02 - 23:06
    and what you will see in practice is that most of the service files really look
  • 23:06 - 23:10
    kind of the same. It's pretty simple, they're pretty short
  • 23:10 - 23:12
    they all use the same features.
  • 23:12 - 23:16
    One more interesting feature that you should be aware of
  • 23:16 - 23:22
    Who of you -- show of hands -- maintains a package that ships a dbus service?
  • 23:22 - 23:25
    one or two? OK
  • 23:25 - 23:29
    For the others, this is more of an academic interest
  • 23:29 - 23:33
    but systemd can actually care about dbus-activated services
  • 23:33 - 23:38
    so whereas dbus usually would start on its own in older versions
  • 23:38 - 23:40
    nowadays it's better to use systemd for it
  • 23:40 - 23:45
    because then it all ends up in the same hierarchy and it all gets tracked and you get all the benefits and stuff
  • 23:46 - 23:50
    so what you do is you add Type=dbus and you specify the BusName
  • 23:50 - 23:54
    and you don't have an [Install] section -- it's not missing on the slide, it's just not there.
  • 23:54 - 23:59
    and then systemd will activate that service whenever that bus name is actually accessed.
  • 24:03 - 24:08
    This is a more advanced example of the dh_systemd debhelper plugin
  • 24:08 - 24:14
    what we do here is we install a service that should not actually be installed by default.
  • 24:14 - 24:21
    and the way we do this is we override the dh_systemd_enable target and specify the --no-enable flag
  • 24:21 - 24:25
    This should not be a surprise to any of you who has been using debhelper in the past
  • 24:25 - 24:30
    I just wanted to mention it and make sure that you understand what the options are here.
  • 24:30 - 24:33
    -- I will answer that in a second --
  • 24:33 - 24:38
    The second example here is for the second part of the dh_systemd debhelper plugin
  • 24:38 - 24:40
    It's dh_systemd_start
  • 24:40 - 24:45
    and what I specify here is the --restart-after-upgrade flag which will make sure that the package does not get stopped
  • 24:45 - 24:49
    then replaced then started, but will just get replaced and then restarted afterward
  • 24:49 - 24:53
    which is kind of cleaner, but the package needs to support it. Question?
  • 24:53 - 25:00
    [question]: Why do you call the dh_systemd_enable with an option of --no-enable
  • 25:00 - 25:03
    instead of just leaving the target empty?
  • 25:03 - 25:08
    [stapelberg]: That's an excellent question, and the comment above tries to somewhat explain it
  • 25:08 - 25:10
    The thing is that when you purge the package
  • 25:10 - 25:16
    if the user decided to enable it even though you ship it disabled by default
  • 25:16 - 25:18
    then you need to clean up the symlinks
  • 25:18 - 25:21
    So that's what dh_systemd_enable also generates maintainer scripts for
  • 25:22 - 25:24
    So that still needs to run, so we can't just skip it.
  • 25:24 - 25:27
    In the first version we tried, but it didn't work out.
  • 25:27 - 25:29
    More questions?
  • 25:32 - 25:33
    In the back?
  • 25:35 - 25:40
    [question]: You mentioned services triggered by dbus actions
  • 25:40 - 25:41
    [stapelberg]: Yes
  • 25:41 - 25:44
    [question]: Is there a way to disable them even if the service is installed?
  • 25:44 - 25:47
    [stapelberg]: Yes, you can mask any service. I can show you that later.
  • 25:47 - 25:51
    One more question?
  • 25:52 - 25:56
    [question]: So you say --restart-after-upgrade; how does restart -- I guess this is more general, but it's prompted by this
  • 25:56 - 26:00
    how does restart work if the service is not running?
  • 26:02 - 26:04
    [stapelberg]: That's a good question. I would have to really look it up.
  • 26:04 - 26:09
    I think there is a try-restart action
  • 26:09 - 26:13
    that would restart if it's running
  • 26:13 - 26:15
    but not start it if it's not running
  • 26:15 - 26:20
    [question]: For example, in this case you set up the service to
  • 26:20 - 26:23
    remain disabled upon install in this example
  • 26:23 - 26:26
    so if you install the package it is not enabled
  • 26:26 - 26:27
    Then the user takes no action
    so if you install the package it is not enabled
  • 26:27 - 26:29
    Then the user takes no action
  • 26:29 - 26:31
    and then they upgrade their system
  • 26:31 - 26:34
    and a new version of the package is installed, it tries to restart?
  • 26:34 - 26:40
    [stapelberg]: The thing is, as I was saying, there is a restart action in systemctl and there is a try-restart
  • 26:40 - 26:45
    The difference is try-restart will only restart it if it's running, which probably answers your question
  • 26:45 - 26:47
    The caveat is that
  • 26:47 - 26:51
    currently, if you maintain a package that ships
  • 26:51 - 26:58
    a system V initscript and a systemd service file, it will still use invoke-rc.d for the actual starting/restarting etc.
  • 26:58 - 27:04
    And the invoke-rc.d actually has code to divert that to systemd
  • 27:04 - 27:08
    but the problem is it's not flexible enough to use try-restart and the fancy stuff
  • 27:08 - 27:11
    so this might need some actual hand-tweaking or just ignoring it for now.
  • 27:12 - 27:19
    Alright! So before we enter the questions and hands-on part of this workshop
  • 27:19 - 27:24
    I just want to make sure that you're all aware that we will provide help
  • 27:24 - 27:28
    There is a wiki page which is linked here called https://wiki.debian.org/Systemd/Packaging
  • 27:28 - 27:33
    which contains most of the information hopefully, or at least pointers
  • 27:33 - 27:38
    We have an irc channel on irc.debian.org called #debian-systemd
  • 27:38 - 27:40
    where you can just stop by at any time
  • 27:40 - 27:44
    Most of the time there's somebody around who actually knows how to write service files and stuff
  • 27:44 - 27:50
    There is a mailing list that we are all active and we really do mean it
  • 27:50 - 27:54
    Please ask! Also, during debconf, if there is at any time any questions
  • 27:54 - 27:56
    from any of you or from your friends
  • 27:56 - 28:00
    please ask. we're here for answering these sorts of questions.
  • 28:00 - 28:04
    Now just one more quick note: finding documentation
  • 28:04 - 28:07
    There are manpages -- a lot of manpages
  • 28:07 - 28:11
    They are roughly categorized by the sections I previously showed in service files
  • 28:11 - 28:15
    So there's a systemd.service, there's a systemd.exec, etc.
  • 28:15 - 28:22
    There's also an overview on the freedesktop.org web site (http://www.freedesktop.org/wiki/Software/systemd/) where it points to all the documentation
  • 28:22 - 28:27
    The particularly interesting parts of that are the systemd for administrators blog series
  • 28:27 - 28:33
    where Lennart talks about a lot of features that are interesting and how to actually make use of them in your service files
  • 28:33 - 28:37
    And then there's a link for package repositories for the various distributions
  • 28:37 - 28:42
    where you can just look if there already is a service file for that particular package that you maintain
  • 28:42 - 28:44
    even though it doesn't ship one upstream
  • 28:44 - 28:49
    So the best thing in that case would also be to adopt the service file and then also make upstream accept that.
  • 28:49 - 28:59
    Alright! That's the talk part so far. Now I'm ready to answer any questions or look at any packages
  • 29:01 - 29:04
    [question]: What are the plans for backports?
  • 29:04 - 29:10
    I mean if you want to make backports to wheezy, can we use the dh_systemd helper?
  • 29:10 - 29:14
    [stapelberg]: Yes, the dh_systemd helper is available in wheezy backports
  • 29:14 - 29:22
    Be aware that the systemd version in wheezy is version 44, and we're currently trying to get version 204, which is much more recent
  • 29:22 - 29:27
    into debian -- it had a version jump because of udev.
  • 29:27 - 29:31
    So it's not that much more recent, it's just more recent.
  • 29:31 - 29:36
    So there might be issues and it's up to you if you decide to commit to maintaining support
  • 29:36 - 29:42
    for that old systemd version with your service files in wheezy, just so you know.
  • 29:42 - 29:49
    If there is no immediate question, I would just go on to show you a little bit of stuff and we can answer questions as we go
  • 29:49 - 30:01
    [question]: I have to prepend that at the moment I'm not maintaining any package that has to start daemons at poweron
  • 30:01 - 30:04
    So I know nearly nothing about it.
  • 30:04 - 30:10
    But I am a bit confused. Since I understand there are a lot of these kind of systems
  • 30:10 - 30:14
    systemd, sysvinit, and so on
  • 30:14 - 30:21
    As a package maintainer, what do I have to do
  • 30:21 - 30:25
    if I want to support all of them, I have to provide
  • 30:25 - 30:30
    the script or description file that they need for each of them
  • 30:30 - 30:31
    [stapelberg]: -- to answer this, the policy mandates --
    the script or description file that they need for each of them
  • 30:31 - 30:32
    [stapelberg]: -- to answer this, the policy mandates --
  • 30:32 - 30:33
    [question]: For example, just to complete the question, in particular if we consider just sysvinit, it is one that we have
    [stapelberg]: -- to answer this, the policy mandates --
  • 30:33 - 30:39
    [question]: For example, just to complete the question, in particular if we consider just sysvinit, it is one that we have
  • 30:39 - 30:43
    by default, and systemd, which we are discussing now
  • 30:43 - 30:48
    If I want to provide a systemd information file
  • 30:48 - 30:56
    Do I also have to provide a sysvinit scripts
  • 30:56 - 31:02
    or is there some compatibility layer that enables me to write one thing
  • 31:02 - 31:09
    and (at least in common cases) expect some magic to make it work for other systems
  • 31:09 - 31:14
    [stapelberg]: OK, I would be happy to answer that after the talk because that's not really the focus of this talk.
  • 31:14 - 31:18
    So now, let me just show you a few handy things that might be useful
  • 31:18 - 31:22
    I have a terminal here that you hopefully can read in the back
  • 31:22 - 31:27
    Is that OK? Great! So let's just have a look at
  • 31:27 - 31:33
    thinkfan.service and what I was using here is the systemctl command and you can see multiple interesting things
  • 31:33 - 31:36
    First of all, it is active and running, so that's good.
  • 31:36 - 31:40
    It shows that I started it 6 days ago, when I last rebooted my laptop
  • 31:40 - 31:46
    It also shows the main pid, which is 2588, and that's the binary that corresponds to it.
  • 31:46 - 31:50
    For more complex services, there are more binaries in the cgroup hierarchy
  • 31:50 - 31:54
    What is particularly interesting for you is
  • 31:54 - 31:58
    first of all, where the service file actually lives; so make sure you ship it to the correct path.
  • 31:58 - 32:04
    There's also a lintian warning for that, so if you use lintian you should catch that
  • 32:04 - 32:07
    It should go to /lib/systemd/system, as I mentioned
  • 32:07 - 32:13
    It also should be enabled unless, of course, you decided to not enable it by default
  • 32:15 - 32:20
    Now, I can just show you systemctl stop, it will be that
  • 32:20 - 32:26
    [question]: the video projector does not show all of the terminal
  • 32:26 - 32:31
    [stapelberg]: That is a good point. The first two columns are not shown, so let's make it like this
  • 32:31 - 32:33
    Should be much better!
  • 32:33 - 32:37
    Not perfect. Better?
  • 32:37 - 32:44
    [question, unintelligible]
  • 32:44 - 32:46
    [stapelberg]: Yeah, whatever. That's good enough.
  • 32:46 - 32:54
    thinkfan.service -- now it's still enabled. It's still loaded but it's inactive because I stopped it
  • 32:54 - 32:58
    I can start it again
  • 32:58 - 33:00
    check that it's started
  • 33:00 - 33:03
    You can also see that it used this ExecStart line
  • 33:03 - 33:07
    I can also actually show you the service file. There's really no magic in here.
  • 33:07 - 33:14
    There is an ExecReload directive here, so we can test if the reload actually works
  • 33:14 - 33:17
    Which I need to do as root
  • 33:17 - 33:22
    And then in the status output we will see that it tried to reload the service
  • 33:22 - 33:26
    code=exited, status = 0/SUCCESS, so that worked.
  • 33:26 - 33:31
    So those are a few simple things you can check to see if your service actually works
  • 33:31 - 33:37
    10 minutes, yes. Are there any questions now? Microphone?
  • 33:39 - 33:48
    [question]: The example has Type=forking. What are the other values which are valid?
  • 33:49 - 33:54
    [stapelberg]: So that was obviously a suggestion to open the man page and show you that actually it is documented
  • 33:56 - 33:59
    The manpage in question here is systemd.service, as I tried to explain earlier
  • 33:59 - 34:02
    There's multiple Types -- there is simple
  • 34:02 - 34:05
    There's forking, oneshot, dbus, notify or idle
  • 34:05 - 34:08
    The most interesting ones are simple, forking, oneshot, and dbus
  • 34:08 - 34:11
    dbus I already explained -- that's if you have an actual dbus service
  • 34:11 - 34:16
    There's oneshot, which is for stuff like doing one thing and then nothing
  • 34:16 - 34:20
    like, it's not a permanently running service, it's just a simple command like a shell script
  • 34:20 - 34:25
    and then it will stay active, as in "started" afterwards
  • 34:25 - 34:29
    There is forking and there is simple. The difference between simple and forking
  • 34:29 - 34:36
    is that simple will -- the daemon you're starting, if it's a Type=simple one
  • 34:36 - 34:41
    should just continue running in the foreground, whereas a forking one will fork itself into background.
  • 34:41 - 34:44
    The preferred model is using simple because, you know, it's simple.
  • 34:44 - 34:49
    forking has the implicit assumption, and I think this is important to know, that
  • 34:49 - 34:54
    as long as the daemon is still running in the foreground, it's not ready
  • 34:54 - 34:59
    The unit file will be considered started precisely at the moment where the daemon forks.
  • 34:59 - 35:04
    That is not necessarily what your upstream software implements, but that's how it's
  • 35:04 - 35:06
    [question, unintelligible]
  • 35:06 - 35:11
    [stapelberg]: The question was: when it forks, or when the main process exits?
  • 35:11 - 35:15
    Obviously, I think when the main process exits.
  • 35:16 - 35:17
    [question]: It would be really strange in the other case
  • 35:17 - 35:23
    [stapelberg]: That's how it usually works, right? You double-fork and then you exit the main process.
  • 35:23 - 35:25
    More questions?
  • 35:28 - 35:32
    Masking processes -- perfect, let's do that!
  • 35:32 - 35:35
    So I have thinkfan and I now decide
  • 35:35 - 35:39
    That it's really a shame that my fan is not spinning up as much as I would like
  • 35:39 - 35:44
    So what I will just do is I will mask thinkfan.service and it will helpfully
  • 35:44 - 35:50
    print out what it actually did, which is it just created a symlink in /etc/systemd/system/thinkfan.service
  • 35:51 - 35:52
    pointing to /dev/null
  • 35:53 - 35:58
    Essentially, it will try to load that service file but fail, because it can't read /dev/null.
  • 35:58 - 36:01
    So if I now check status
  • 36:01 - 36:04
    on thinkfan.service, it will tell me that it's masked
  • 36:04 - 36:08
    but it's also still running. So if I now do systemctl stop
  • 36:08 - 36:13
    and then status, it's now dead, and it will not be started on my next boot.
  • 36:13 - 36:21
    This is different from enable and disable because it also works for dbus services and it's really like the last resort
  • 36:21 - 36:25
    If you really really don't want this thing to be started, mask it. Question?
  • 36:27 - 36:34
    [question]: In this case, you cannot start it by hand, you have another method implemented in systemd
  • 36:34 - 36:47
    [question]: If I want it to not start at boot, but I want to be able to run it by hand
  • 36:47 - 36:53
    [stapelberg]: Yes, then you obviously disable it because disable just means don't start it at boot, but you can still start and stop and restart and all that stuff
  • 36:53 - 36:57
    masked is really "don't start this at all"
  • 36:57 - 37:03
    So now, because I don't like loud fans, let me just unmask that
  • 37:04 - 37:10
    So it told me that it deleted that symlink, and I can start it again and it will just work.
  • 37:11 - 37:14
    More questions please? Over there.
  • 37:16 - 37:23
    [question]: When it's active, it says "active (running)" or it says "inactive (dead)"
  • 37:23 - 37:30
    Is there any particular meaning that there is a part "active" and a part in parenthesis?
  • 37:30 - 37:34
    [stapelberg]: It could be "active (exited)" and that would be the case for the oneshot services
  • 37:34 - 37:40
    that just fork one command, then exited, but the unit is still considered active because the command succeeded.
  • 37:41 - 37:43
    More questions over here?
  • 37:46 - 37:53
    [question]: Is there any support for -- what happens when a daemon dies, is it restarted, like a few times, or ?
  • 37:53 - 37:56
    [stapelberg]: I actually had this on my slides earlier
  • 37:57 - 38:03
    Yes: more features, here we go. You can specify RestartSec=1 and Restart=on-failure
  • 38:03 - 38:07
    There's more options in that direction to restart stuff when it dies
  • 38:07 - 38:10
    More questions please? Here.
  • 38:11 - 38:14
    [question]: It's about the packaging
  • 38:14 - 38:21
    Is it possible to use dpkg triggers -- instead we just put a file in /lib/systemd
  • 38:21 - 38:23
    And then the dpkg trigger happens
  • 38:23 - 38:28
    It means it will work with other packaging systems like cdbs without modification
  • 38:28 - 38:28
    [stapelberg]: we actually have sent a patch to cdbs and it supports dh_systemd by now.
    It means it will work with other packaging systems like cdbs without modification
  • 38:28 - 38:34
    [stapelberg]: we actually have sent a patch to cdbs and it supports dh_systemd by now.
  • 38:34 - 38:37
    [question]: OK, but why are you not using trigger support?
  • 38:37 - 38:38
    [stapelberg]: Not using what, sorry?
  • 38:38 - 38:44
    [question]: Instead of inserting a debhelper snippet in postinst
  • 38:44 - 38:47
    you could have registered a trigger
  • 38:48 - 38:48
    [stapelberg]: It's more complicated than that because
  • 38:48 - 38:50
    [question]: It will be executed when it detects a file appearing in some allocation
    [stapelberg]: It's more complicated than that because
  • 38:50 - 38:54
    [question]: It will be executed when it detects a file appearing in some allocation
  • 38:54 - 38:57
    [stapelberg]: Yeah, but we don't want to enable all the services by default
  • 38:57 - 39:00
    And then we would need to maintain a whitelist or a blacklist of services
  • 39:00 - 39:02
    and stuff, and it really needs to be more flexible than that
  • 39:02 - 39:04
    OK, more questions?
  • 39:06 - 39:07
    Another one?
  • 39:08 - 39:13
    [question]: This time it's for services that need several instances
  • 39:13 - 39:15
    Like stunnel
  • 39:15 - 39:16
    [stapelberg]: Oh, multiple instances, yes
  • 39:16 - 39:23
    [question]: Yes, multiple instances; usually they come with several configuration files
  • 39:23 - 39:26
    And we want one instance per configuration file
  • 39:26 - 39:30
    And be able to control them separately
  • 39:30 - 39:30
    [stapelberg]: Yes, so there are actually --
  • 39:30 - 39:32
    [question]: It's a bummer[?] to do that with sysV
    [stapelberg]: Yes, so there are actually --
  • 39:32 - 39:34
    [question]: It's a bummer[?] to do that with sysV
  • 39:34 - 39:34
    [stapelberg]: There are good examples here of how that works. There's ifup and there's getty
    [question]: It's a bummer[?] to do that with sysV
  • 39:34 - 39:37
    [stapelberg]: There are good examples here of how that works. There's ifup and there's getty
  • 39:37 - 39:39
    Let me just show you getty
  • 39:39 - 39:43
    which has getty@tty1.service
  • 39:43 - 39:45
    and what's interesting is you can see that
  • 39:45 - 39:47
    the service file path actually does not include that
  • 39:47 - 39:49
    so if you have a look at the service file
  • 39:49 - 39:52
    You can see that it's much more complicated than I would like it to be
  • 39:52 - 39:57
    But the interesting part for us is that there's %I
  • 39:57 - 40:00
    which will be replaced with whatever you specify after the @
  • 40:00 - 40:06
    So you can make your service file contain the @
  • 40:06 - 40:10
    in the filename and then use %I and then start a specific instance of that
  • 40:12 - 40:16
    [question]: And the user is expected to create all the @ files?
  • 40:16 - 40:18
    [stapelberg]: Yes
  • 40:18 - 40:20
    OK! More questions?
  • 40:24 - 40:25
    Here.
  • 40:27 - 40:30
    [question]: How about this socket-based activation?
  • 40:30 - 40:32
    [stapelberg]: Socket activation -- that is a good question!
  • 40:32 - 40:38
    Let me just have a look if I have any socket activation files lying around here
  • 40:38 - 40:42
    I have approx.socket, which seems kind of appropriate for this conference.
  • 40:43 - 40:46
    Socket activation essentially works like this, where you have
  • 40:46 - 40:49
    [Socket] instead of [Service] in your service file
  • 40:50 - 40:51
    In your socket file, sorry
  • 40:52 - 40:55
    You specify a TCP port
  • 40:55 - 40:58
    or a unix socket or whatever it should listen on
  • 40:58 - 41:00
    And then there is Accept=yes
  • 41:00 - 41:03
    where the default is Accept=no
  • 41:03 - 41:07
    The difference is that Accept=yes mimics the inetd-style behavior
  • 41:07 - 41:11
    of just starting one process per connection, which is kind of wasteful
  • 41:11 - 41:14
    and the actual real good socket activation is
  • 41:14 - 41:18
    not having that, but patching the service to
  • 41:18 - 41:21
    when being started, inherit the file descriptor
  • 41:21 - 41:26
    of the socket and then just integrate it in its event loop and handle that.
  • 41:26 - 41:28
    And many services are already patched for that.
  • 41:29 - 41:33
    Some of them are patched, but not in debian, and some of them you would need to patch.
  • 41:33 - 41:35
    But this is really a thing of like an hour or two.
  • 41:35 - 41:37
    I did it for bacula once, for example.
  • 41:38 - 41:40
    OK. Question over here?
  • 41:42 - 41:46
    [question]: So the socket file just includes information about where to listen
  • 41:46 - 41:51
    And if to accept or not, or to start. Is that just in the service file then?
  • 41:51 - 41:56
    [stapelberg]: Yes, the socket file has to match, by name, the service file
  • 41:56 - 42:01
    And because I used Accept=yes, it needs to be approx@.service, not approx.service
  • 42:01 - 42:07
    And then this will in turn just take the standard input from the socket, like inetd does, and start it up.
  • 42:08 - 42:09
    One more question?
  • 42:09 - 42:12
    [question]: Why do I have to add the @?
  • 42:12 - 42:21
    [stapelberg]: Because if you use inetd-style stuff, then for every incoming new connection it will start a separate process.
  • 42:21 - 42:21
    so all these processes show up in your cgroup hierarchy.
    [stapelberg]: Because if you use inetd-style stuff, then for every incoming new connection it will start a separate process.
  • 42:21 - 42:23
    so all these processes show up in your cgroup hierarchy.
  • 42:23 - 42:26
    So that's why the instance is used in this case.
  • 42:26 - 42:33
    Does that also relate to ExecStart=- instead of directly the path?
  • 42:33 - 42:37
    No, in fact, I already looked at this and wondered why it is there
  • 42:37 - 42:42
    I think it should not be there, because the - means that failures should be ignored.
  • 42:42 - 42:46
    I'm not entirely sure why it makes sense to have it here
  • 42:46 - 42:49
    My suspicion would be that if there's a connection and then it goes away
  • 42:49 - 42:53
    then it shouldn't -- I would need to look that up. Sorry, no answer.
  • 42:53 - 42:57
    More questions? Last question, we have one minute left.
  • 42:57 - 42:59
    Last question over there.
  • 43:05 - 43:10
    [question]: Thank you. Where are dependencies defined in this thing?
  • 43:10 - 43:15
    [stapelberg]: Oh yes, that's a good question. Ideally, dependencies are not defined anywhere because they are implicit by socket activation.
  • 43:15 - 43:19
    In case that's not the case, for example, if my
  • 43:19 - 43:24
    -- I think I should probably have it here, let me just have a look real quick --
  • 43:26 - 43:33
    dcs-web.service, it's actually more complicated. No it doesn't have it.
  • 43:33 - 43:40
    So there is, in the [Unit] section, where we also specified the Description, there can be a Before= and After=
  • 43:40 - 43:45
    So in my case, I would start codesearch after postgresql came up
  • 43:45 - 43:48
    and I would just specify After=postgresql.service
  • 43:48 - 43:52
    You can specify multiple services there, you can specify the directive multiple times
  • 43:52 - 43:56
    But usually it should not be required to specify dependencies, which is nice.
  • 43:56 - 43:58
    OK, thank you.
  • 43:58 - 44:01
    OK, time is over. I would like to say, thank you very much for your attention.
  • 44:01 - 44:04
    If you have any questions, please let me know and we can fix it.
  • 44:04 - 44:05
    [talkmeister]: Thank you, Michael.
  • 44:05 - 44:06
    [clapping]
    [talkmeister]: Thank you, Michael.
  • 44:06 - 44:10
    [clapping]
Title:
981_Making_your_package_work_with_systemd.ogv
Video Language:
English
Team:
Debconf
Project:
2013_debconf13

English subtitles

Revisions