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

Enable systemd service with a parameter

· 52CE 我爱测

I have a systemd service with a paramter. It's working great. However, I cannot start it without a parameter. The parameter would look like systemctl start [email omitted] , where the 1-0 would be parsed by a php script. The php …

问题原文

原帖链接 · DevOpsSauce · CC BY-SA 4.0

I have a systemd service with a paramter. It's working great. However, I cannot start it without a parameter.

The parameter would look like systemctl start [email omitted], where the 1-0 would be parsed by a php script. The php script has a default of 1-0, but I cannot start it with systemctl start my-service@.service. It tells me:

Failed to start my-service@.service: Unit name my-service@.service is missing the instance name.

I successfully enabled it with systemctl enable my-service@.service, but is it going to fail on boot? If so, how can I tell it to start with a default of 1-0 if nothing else is specified?

已采纳解答

原帖链接 · DevOpsSauce · CC BY-SA 4.0

It appears that enabling a service with a default parameter is possible, per this guide. Since it needs to default to 1-0, I just did:

systemctl enable my-service\@1-0.service

It successfully created the symlink:

Created symlink /etc/systemd/system/multi-user.target.wants/[email omitted] → /lib/systemd/system/my-service@.service

Thanks for the downvote btw. Stay classy.

"Fine... I'll do it myself." ~ Thanos

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

资料来源与适用范围

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

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

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