From 5008da1ec1cf2cf8c15b702c4052e3a49583095d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 25 Mar 2018 20:50:15 +0200 Subject: systemd: do not require absolute paths in ExecStart Absolute paths make everything simple and quick, but sometimes this requirement can be annoying. A good example is calling 'test', which will be located in /usr/bin/ or /bin depending on the distro. The need the provide the full path makes it harder a portable unit file in such cases. This patch uses a fixed search path (DEFAULT_PATH which was already used as the default value of $PATH), and if a non-absolute file name is found, it is immediately resolved to a full path using this search path when the unit is loaded. After that, everything behaves as if an absolute path was specified. In particular, the executable must exist when the unit is loaded. --- man/systemd.service.xml | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'man/systemd.service.xml') diff --git a/man/systemd.service.xml b/man/systemd.service.xml index b68d351dff..e89cfe3f0e 100644 --- a/man/systemd.service.xml +++ b/man/systemd.service.xml @@ -301,8 +301,9 @@ ExecStop= line set. (Services lacking both ExecStart= and ExecStop= are not valid.) - For each of the specified commands, the first argument must be an absolute path to an - executable. Optionally, this filename may be prefixed with a number of special characters: + For each of the specified commands, the first argument must be either an absolute path to an executable + or a simple file name without any slashes. Optionally, this filename may be prefixed with a number of special + characters: Special executable prefixes @@ -1004,11 +1005,9 @@ &, and other elements of shell syntax are not supported. - The command to execute must be an absolute path name. It may - contain spaces, but control characters are not allowed. + The command to execute may contain spaces, but control characters are not allowed. - The command line accepts % specifiers as - described in + The command line accepts % specifiers as described in systemd.unit5. Basic environment variable substitution is supported. Use @@ -1022,10 +1021,20 @@ For this type of expansion, quotes are respected when splitting into words, and afterwards removed. + If the command is not a full (absolute) path, it will be resolved to a full path using a + fixed search path determinted at compilation time. Searched directories include + /usr/local/bin/, /usr/bin/, /bin/ + on systems using split /usr/bin/ and /bin/ + directories, and their sbin/ counterparts on systems using split + bin/ and sbin/. It is thus safe to use just the + executable name in case of executables located in any of the "standard" directories, and an + absolute path must be used in other cases. Using an absolute path is recommended to avoid + ambiguity. + Example: Environment="ONE=one" 'TWO=two two' -ExecStart=/bin/echo $ONE $TWO ${TWO} +ExecStart=echo $ONE $TWO ${TWO} This will execute /bin/echo with four arguments: one, two, @@ -1035,7 +1044,7 @@ ExecStart=/bin/echo $ONE $TWO ${TWO} Environment=ONE='one' "TWO='two two' too" THREE= ExecStart=/bin/echo ${ONE} ${TWO} ${THREE} ExecStart=/bin/echo $ONE $TWO $THREE - This results in echo being + This results in /bin/echo being called twice, the first time with arguments 'one', 'two two' too, , @@ -1061,27 +1070,27 @@ ExecStart=/bin/echo $ONE $TWO $THREE Note that shell command lines are not directly supported. If shell command lines are to be used, they need to be passed explicitly to a shell implementation of some kind. Example: - ExecStart=/bin/sh -c 'dmesg | tac' + ExecStart=sh -c 'dmesg | tac' Example: - ExecStart=/bin/echo one ; /bin/echo "two two" + ExecStart=echo one ; echo "two two" - This will execute /bin/echo two times, + This will execute echo two times, each time with one argument: one and two two, respectively. Because two commands are specified, Type=oneshot must be used. Example: - ExecStart=/bin/echo / >/dev/null & \; \ -/bin/ls + ExecStart=echo / >/dev/null & \; \ +ls - This will execute /bin/echo + This will execute echo with five arguments: /, >/dev/null, &, ;, and - /bin/ls. + ls.
C escapes supported in command lines and environment variables -- cgit v1.2.1 From e12d446b6623cedaf2b92c5e935312f7ade6cfef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 26 Mar 2018 09:51:12 +0200 Subject: systemd-path: allow the default search path to be queried --- man/systemd.service.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'man/systemd.service.xml') diff --git a/man/systemd.service.xml b/man/systemd.service.xml index e89cfe3f0e..55a9c6fbdc 100644 --- a/man/systemd.service.xml +++ b/man/systemd.service.xml @@ -1029,7 +1029,8 @@ bin/ and sbin/. It is thus safe to use just the executable name in case of executables located in any of the "standard" directories, and an absolute path must be used in other cases. Using an absolute path is recommended to avoid - ambiguity. + ambiguity. Hint: this search path may be queried using + systemd-path search-binaries-default. Example: -- cgit v1.2.1