I will show you how to pass arguments using an instance with the systemctl
command.
Create the following Unit definition file.
test
in this case) +@
+ .service
.% i
./etc/systemd/system/[email protected]
[Unit]
Description=TestService
[Service]
ExecStart=/bin/echo %I
systemctl start test@"arg1 arg2"
[root@CENTOS7 ~]# systemctl start test@"arg1 arg2"
[root@CENTOS7 ~]#
Check with journalctl -u test @" arg1 arg2 "
.
[root@CENTOS7 ~]# journalctl -u test@"arg1 arg2"
--Logs begin at day 2019-12-29 17:19:15 JST,end at day 2019-12-29 20:06:21 JST.
December 29 20:06:21 CENTOS7 systemd[1]: Started TestService.
December 29 20:06:21 CENTOS7 echo[1602]: arg1 arg2
% i
instead of% I
in /etc/systemd/system/[email protected]
, the half-width space between ʻarg1 and ʻarg2
will be escaped and ʻarg1 \ x20arg2` Will be.The unit specifiers that are replaced when the unit file is loaded are:
Unit specifier | meaning | Details |
---|---|---|
%n | Full unit name | |
%N | Full unit name (no escape) | %Same as n, but the string is not escaped. |
%p | prefix | In the unit name that became an instance"@"Refer to the character string before the character. For other units, the unit name without the suffix is used. |
%P | Prefix (no escape) | %Same as p, but the string is not escaped. |
%i | Instance name | Of the unit name that became an instance"@"Use the string between the character and the suffix. |
%I | Instance name(No escape) | %Same as i, but the string is not escaped. |
%f | file name(No escape) | Unescaped instance name. |
%c | Unit control group | This group name has/sys/fs/cgroup/systemd/Does not include the prefix. |
%r | Control group parent group path | "%c"The parent cgroup path of is used. |
%R | Route control group path where slices and units are placed | For system instances, "/"become. In the case of a container, use the root control group path of the container. |
%t | Runtime directory | /run or$XDG_RUNTIME_DIR is used. |
%u | User name | マネージャーを実行しているユーザのUser nameが使用される。 Usually root. |
%U | User UID | マネージャーを実行しているUser UIDが使用される。 0 is used for system administrators. |
%h | User's home directory | マネージャーを実行しているUser's home directoryが指定される。 If you are a system administrator,/"root" is used. |
%s | User's shell | The shell used by the service manager. If you are a system administrator,/bin/sh "is used. |
%m | Machine ID | システムのMachine ID。 |
%b | Boot ID | System boot ID. |
%H | hostname | ユニットがロードされた時点でのシステムhostname。 |
%v | Release version of kernel | 「uname -Use the character string that can be obtained from the output of "r". |
that's all
Recommended Posts