linux关闭systemd服务,linux – 如何按特定顺序停止systemd服务

当特定的systemd服务停止时,如何确保遵循特定的订单?我有几个运行的系统服务/单元,但在各种已安装的分区上使用资源.使用自定义服务安装和卸载这些分区.在自定义安装程序停止之前,需要以特定顺序停止正在运行的服务(例如ProgramA.service& ProgramB.service).

设置启动依赖项非常简单,但我无法弄清楚如何确保在挂载服务停止之前服务已停止.

mountCustomPartitions.service

[Unit]

Description=My Custom Partition Mounting Service

[Service]

Type=oneshot

RemainAfterExit=yes

ExecStart=/usr/bin/mountCustomPartitions.sh mount

ExecStop=/usr/bin/mountCustomPartitions.sh unmount

[Install]

WantedBy=multi-user.target

ProgramA.service

[Unit]

Description=My Generic Program A Service

Wants=mountCustomPartitions.service

After=mountCustomPartitions.service

[Service]

Type=simple

ExecStart=/usr/bin/ProgramA

[Install]

WantedBy=multi-user.target

ProgramB.service

[Unit]

Description=My Generic Program B Service

Requires=ProgramA.service

Wants=mountCustomPartitions.service

After=mountCustomPartitions.service ProgramA.service

[Service]

Type=simple

ExecStart=/usr/bin/ProgramB

[Install]

WantedBy=multi-user.target

在上面的场景中,mountCustomPartitions.service必须在程序服务之前启动,但也必须在它们之后停止.如果mountCustomPartitions.service被显式停止,那么它应该导致其他人也停止(但必须等待它们停止).我还需要确保ProgramB在ProgramA之后启动,但也在ProgramA之前停止.希望这不是太混乱.

我能想到的唯一解决方案是让每个服务都有一个ExecStop行,为特定服务执行systemctl stop [service]命令,该服务必须在停止之前停止.我遇到的问题是我实际上目前有六个服务使用已安装的分区,必须在尝试卸载之前停止.在这六个中,有些需要按特定顺序停止.由于这是在商业产品中使用,我希望有一个更清洁的解决方案.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值