systemd: how do I create a new .slice file?

j4nd3r53n asked:

I’m struggling to understand how to set up a new slice on my debian 10 system. I have created a file, system-db.slice by copying system.slice and changing a couple of things:

#  This file is part of systemd.
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

Description=System DB Slice

This doesn’t appear to do anything at all; it doesn’t show up in systemd-cgls, for example. On the other hand, systemctl finds it:

# systemctl status system-db.slice
‚óŹ system-db.slice - System DB Slice
   Loaded: loaded (/etc/systemd/system/system-db.slice; static; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:systemd.special(7)

Clearly there are some things I haven’t done or done wrong. How should I have done this? And where can I learn more about this?

My answer:

The slice is only started when a service that uses the slice is started. You do not start it manually. Rather, you add Slice=my.slice to the unit that you want to be restricted by this slice.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.