首页 > 解决方案 > 如何禁用以破折号“-”开头的服务名称

问题描述

我错误地创建了一个名为-server. 当我尝试使用命令停止或禁用它时,sudo systemctl stop "-server"我收到错误消息,Failed to parse signal string erver.请注意,s由于前面的破折号,字母消失了;我认为systemctl由于破折号将其解释为参数。

如何以不会被误解的方式传递服务名称?

标签: linuxservicesystemctl

解决方案


可能最简单的解决方案是使用以下systemctl命令将服务名称视为非参数--

$ systemd-run --user --unit="-myservice" /bin/sleep infinity
$ systemctl --user is-active -- -myservice.service
active
$ systemctl --user stop -- -myservice.service
$ systemctl --user is-active -- -myservice.service
inactive


推荐阅读