大网数据广告活动
服务器运维问答

systemd instance name (%i) not working in ExecStart

· 52CE 我爱测

For some reason, systemd is not replacing %i or %I with the instance name in ExecStart /systemd/system/service/foo@.service [Unit] Description=Foo service for %I [Service] User=keith ExecStart=/path/to/foo/%i/food ... /path/to/fo…

问题原文

原帖链接 · ki9 · CC BY-SA 3.0

For some reason, systemd is not replacing %i or %I with the instance name in ExecStart


/systemd/system/service/foo@.service

[Unit]
Description=Foo service for %I

[Service]
User=keith
ExecStart=/path/to/foo/%i/food
...

/path/to/foo/bar/food

#/bin/bash

node /path/to/foo/bar/bard.js

Then I run:

$ sudo systemctl daemon-reload
$ sudo systemctl start foo@bar
$ sudo systemctl status foo@bar
● [email omitted] - Foo service for bar
   Loaded: loaded (/etc/systemd/system/foo@.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2016-09-30 19:07:02 EDT; 6s ago
  Process: 18705 ExecStart=/path/to/foo/%i/food (code=exited, status=203/EXEC)
 Main PID: 18705 (code=exited, status=203/EXEC)

Sep 30 19:07:02 kptow systemd[1]: Started Foo service for bar.
Sep 30 19:07:02 kptow systemd[1]: [email omitted]: Main process exited, code=exited, status=203/EXEC
Sep 30 19:07:02 kptow systemd[1]: [email omitted]: Unit entered failed state.
Sep 30 19:07:02 kptow systemd[1]: [email omitted]: Failed with result 'exit-code'.

The %I in the description gets replaced, but the %i in the ExecStart doesn't. I've tried using %i/%I, but neither works.

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 3.0

The first argument to ExecStart= must be an absolute path to an executable. Substitutions are not accepted.

If you're just loading a bash script which then starts Node.js, you can do that explicitly:

ExecStart=/bin/bash /path/to/foo/%i/food

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。