对于 systemd 模板服务,状态输出不会在 ExecStart 中展开 %i

对于 systemd 模板服务,状态输出不会在 ExecStart 中展开 %i

服务脚本正确启动了名称中扩展了 %i 的 bash 脚本,但是当我询问状态时,%i 没有扩展。以下是脚本:

#cat /etc/systemd/system/[email protected]

# The test service unit template file
#
# version=$Header

[Unit]
Description=test %I instance

[Service]
Type=forking
KillMode=process
ExecStart=/bin/bash /tmp/test_service_script_%i 

#cat /tmp/test_service_script_fred

#!/bin/bash

sleep 300&
echo `date`Running $0 > $0.log

运行这个就OK了

#systemctl start test@fred
#cat /tmp/test_service_script_fred.log

Thu 12 Oct 14:42:01 BST 2023Running /tmp/test_service_script_fred

到目前为止,一切都很好,但是

#systemctl status test@fred[email protected] - test fred instance
    Loaded: loaded (/etc/systemd/system/[email protected]; static; vendor preset: disabled)
    Active: active (running) since Thu 2023-10-12 14:42:01 BST; 6s ago
    Process: 10442 ExecStart=/bin/bash /tmp/test_service_script_%i (code=exited, status=0/SUCCESS)
    CGroup: /system.slice/system-test.slice/[email protected]
           ├─ 9798 sleep 300
           ├─10247 sleep 300
           └─10443 sleep 300

注意,以“Process:”开头的行具有未展开的 %i

是否应该扩展它,以便我们可以看到它运行的内容?

相关内容