docs: describe valid unit names in systemd.unit(5)

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-08-30 13:52:33 +02:00
parent 153d597575
commit 13dcc96ffb
2 changed files with 20 additions and 9 deletions

View file

@ -104,16 +104,24 @@
<citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>. <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
</para> </para>
<para>Unit files are loaded from a set of paths determined during <para>Unit files are loaded from a set of paths determined during compilation, described in the next
compilation, described in the next section.</para> section.</para>
<para>Unit files can be parameterized by a single argument called the "instance name". The unit <para>Valid unit names consist of a "name prefix" and a dot and a suffix specifying the unit type. The
is then constructed based on a "template file" which serves as the definition of multiple "unit prefix" must consist of one or more valid characters (ASCII letters, digits, <literal>:</literal>,
services or other units. A template unit must have a single <literal>@</literal> at the end of <literal>-</literal>, <literal>_</literal>, <literal>.</literal>, and <literal>\</literal>). The total
the name (right before the type suffix). The name of the full unit is formed by inserting the length of the unit name including the suffix must not exceed 256 characters. The type suffix must be one
instance name between <literal>@</literal> and the unit type suffix. In the unit file itself, of <literal>.service</literal>, <literal>.socket</literal>, <literal>.device</literal>,
the instance parameter may be referred to using <literal>%i</literal> and other specifiers, see <literal>.mount</literal>, <literal>.automount</literal>, <literal>.swap</literal>,
below.</para> <literal>.target</literal>, <literal>.path</literal>, <literal>.timer</literal>,
<literal>.slice</literal>, or <literal>.scope</literal>.</para>
<para>Units names can be parameterized by a single argument called the "instance name". The unit is then
constructed based on a "template file" which serves as the definition of multiple services or other
units. A template unit must have a single <literal>@</literal> at the end of the name (right before the
type suffix). The name of the full unit is formed by inserting the instance name between
<literal>@</literal> and the unit type suffix. In the unit file itself, the instance parameter may be
referred to using <literal>%i</literal> and other specifiers, see below.</para>
<para>Unit files may contain additional options on top of those <para>Unit files may contain additional options on top of those
listed here. If systemd encounters an unknown option, it will listed here. If systemd encounters an unknown option, it will

View file

@ -50,6 +50,9 @@ static void test_unit_name_is_valid(void) {
assert_se(!unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE)); assert_se(!unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE));
assert_se( unit_name_is_valid("foo@.service", UNIT_NAME_TEMPLATE)); assert_se( unit_name_is_valid("foo@.service", UNIT_NAME_TEMPLATE));
assert_se( unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE)); assert_se( unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
assert_se( unit_name_is_valid(".test.service", UNIT_NAME_PLAIN));
assert_se( unit_name_is_valid(".test@.service", UNIT_NAME_TEMPLATE));
assert_se( unit_name_is_valid("_strange::::.service", UNIT_NAME_ANY));
assert_se(!unit_name_is_valid(".service", UNIT_NAME_ANY)); assert_se(!unit_name_is_valid(".service", UNIT_NAME_ANY));
assert_se(!unit_name_is_valid("", UNIT_NAME_ANY)); assert_se(!unit_name_is_valid("", UNIT_NAME_ANY));