系统服务依赖性和目标排序

I have a question about systemd services dependencies and ordering. I have a service a.service that wants and must be started before a service b.service. The target multi-user.target wants the service a.service but NOT b.service. How can I be sure b.service is started once the target is reached ?

谢谢您的回答

评论
  • Wood
    Wood 回复

    In your systemd unit file, within the [Unit] directive you can have After=. For example, I have a Node.js script set to run. It needs networking, so the first few lines would look like:

    [Unit]
    Description=Run website as Node.js "daemon"
    After=network.target auditd.service
    

    This means it will only run after network.target and auditd.service. For your case, you could try to put After=a.service in your unit file for b.service.

    Edit: See this answer for more information on After= vs Require=