I use cloud-config to install and configure DCOS cluster.

Normally agentinstall.service service takes 5 minutes to complete.

Is it possible to instruct to systemd to execute agentconfigure.service only after agentinstall.service completed?

    - name: "agentinstall.service"
      command: "start"
      content: |

        ExecStartPre=/bin/curl -o /tmp/dcos_install.sh  http://bootstapnode-0.dev.myztro.internal:9090/dcos_install.sh
        ExecStartPre=/bin/chmod 755 dcos_install.sh
        ExecStart=/bin/bash dcos_install.sh slave

    - name: "agentconfigure.service"
      command: "start"
      content: |

        ExecStartPre=/bin/echo "MESOS_ATTRIBUTES=cluster:uploader" >> /opt/mesosphere/etc/mesos-slave-common
        ExecStartPre=/bin/rm -f /var/lib/mesos/slave/meta/slaves/latest
        ExecStart=/usr/bin/systemctl restart dcos-mesos-slave


Thank you.

  • Does using the "After" directive not work? – Raman Sailopal Oct 2 '17 at 10:06
  • No , It did not work. I assume it is because After= do not guarantee that ""agentinstall.service"" has completed. – UtpMahesh Oct 2 '17 at 13:20
  • Does systemd show the agentinstall service running when it hasn't actually completed the start up? – Raman Sailopal Oct 2 '17 at 13:31

I am not aware of a way to get this done with systemd, as I think it is only concerned about starting and running of units. As in, you can use After= to force a unit to start only AFTER the specified one has started, or both start in parallel.

Wants= will cause the specified units to be started in parallel (if the wanted units are not yet started/active), not what you want.

Requires= will, if used in conjunction with After= on agentconfigure.service, ensure that agentconfigure.service is started AFTER agentinstall.service is active ("busy"). Now, you could have a loop in agentconfigure.service that waits, say max 5 minutes, and regularly checks for agentinstall.service to complete before it proceeds with its actual work. The only option I see for this.

EDIT: Another option I think is even better ... agentinstall.service starts agentconfigure.service when installation succeeds, then exits.


You want to run after the /bin/bash dcos_install.sh slave command?

Change the service with that command to Type=oneshot. Also then I don't think you need to use ExecStartPre=, just use ExecStart= for everything.

@JdeBP asks me to point out that your echo command is attempting to using shell redirection which will not work.

  • Beaten to it. I was going to suggest the same. You might want to add to this answer that running systemctl within a service is generally a bad idea; that {{ExecStart}} values are not shell script and shell script syntax does not work in them; and that there's probably a need for two oneshots here or maybe some tmpfiles stuff. – JdeBP Oct 4 '17 at 8:12

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.