【问题标题】:How to disable service name starting with dash symbol "-"如何禁用以破折号“-”开头的服务名称
【发布时间】:2020-09-05 08:51:30
【问题描述】:

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

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

【问题讨论】:

  • 你试过逃避'-'吗?试试“\-server”,也许可以,我只是在这里猜测。
  • 当我使用 "\-server" 时,它被解释为Failed to stop \-server.service: Unit \-server.service not loaded.
  • 试试单引号。例如,sudo systemctl stop '-server'
  • 我尝试过同时使用单引号和双引号。两者的输出是一样的。

标签: linux service systemctl


【解决方案1】:

可能最简单的解决方案是告诉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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-05
    • 2019-01-31
    • 2013-02-04
    • 1970-01-01
    • 2011-01-26
    • 1970-01-01
    • 2011-05-16
    • 1970-01-01
    相关资源
    最近更新 更多