【问题标题】:Init.d script to systemd problem with parameters带有参数的systemd问题的init.d脚本
【发布时间】:2018-09-02 12:40:22
【问题描述】:

我正在尝试将我的名为“myService”的 init.d 脚本升级到 systemd。init.d 脚本有 1 个参数决定要做什么,使用以下切换案例:

case "$choice" in 
    "start")
        # starts service logic here
    "stop") 
        # stops service logic here
    "filter") 
        # runs some .sh file from our PC
esac 

为了升级到 systemd,我在 systemd 中创建了myService.service 文件,并在 ExecuteStart 和 ExecuteStop 上的文件属性中设置以执行带有参数 start 或 stop 的 init.d 文件,现在我可以这样做了:systemctl start myService.service ,但是,如果我想调用 filter 选项,我不能这样做 systemctl filter myService.service 因为“过滤器”不是 systemctl 的有效选项。有什么建议可以克服这个问题吗?

【问题讨论】:

    标签: linux systemd


    【解决方案1】:

    此方案不适合systemd 作为服务经理的职责,例如(但不限于):

    • 正在运行的服务(例如启动、停止等)
    • 上述配置(例如运行在哪个系统级别)
    • 提供有关服务状态的信息
    • 声明各种服务之间的依赖关系和处理

    虽然您没有提供有关服务实现的信息,但似乎filter 模式是一个应用程序/服务器特定的操作。而且,没有明确描述停止服务并发出filter时会发生什么。

    因此,请记住关注点的分离,我建议使用 systemd 来控制服务的启动和停止,但使用任何 IPC(D-Bussocketssignals 等)服务用于触发filter 操作。

    【讨论】:

      猜你喜欢
      • 2018-09-18
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多