Instruct to execute an unit after completing another unit successfully

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite
2












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?




#cloud-config
coreos:
units:
- name: "agentinstall.service"
command: "start"
content: |
[Unit]
Description=agent_setup
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/tmp
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

[Install]
WantedBy=multi-user.target
- name: "agentconfigure.service"
command: "start"
content: |
[Unit]
Description=agent_config
After=agentinstall.service

[Service]
Type=simple
User=root
WorkingDirectory=/opt/mesosphere/etc/
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

[Install]
WantedBy=multi-user.target


Thank you.










share|improve this question























  • 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














up vote
3
down vote

favorite
2












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?




#cloud-config
coreos:
units:
- name: "agentinstall.service"
command: "start"
content: |
[Unit]
Description=agent_setup
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/tmp
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

[Install]
WantedBy=multi-user.target
- name: "agentconfigure.service"
command: "start"
content: |
[Unit]
Description=agent_config
After=agentinstall.service

[Service]
Type=simple
User=root
WorkingDirectory=/opt/mesosphere/etc/
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

[Install]
WantedBy=multi-user.target


Thank you.










share|improve this question























  • 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












up vote
3
down vote

favorite
2









up vote
3
down vote

favorite
2






2





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?




#cloud-config
coreos:
units:
- name: "agentinstall.service"
command: "start"
content: |
[Unit]
Description=agent_setup
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/tmp
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

[Install]
WantedBy=multi-user.target
- name: "agentconfigure.service"
command: "start"
content: |
[Unit]
Description=agent_config
After=agentinstall.service

[Service]
Type=simple
User=root
WorkingDirectory=/opt/mesosphere/etc/
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

[Install]
WantedBy=multi-user.target


Thank you.










share|improve this question















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?




#cloud-config
coreos:
units:
- name: "agentinstall.service"
command: "start"
content: |
[Unit]
Description=agent_setup
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/tmp
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

[Install]
WantedBy=multi-user.target
- name: "agentconfigure.service"
command: "start"
content: |
[Unit]
Description=agent_config
After=agentinstall.service

[Service]
Type=simple
User=root
WorkingDirectory=/opt/mesosphere/etc/
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

[Install]
WantedBy=multi-user.target


Thank you.







systemd systemd-timer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 2 '17 at 10:50









JdeBP

29.2k460136




29.2k460136










asked Oct 2 '17 at 7:30









UtpMahesh

161




161











  • 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
















  • 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















Does using the "After" directive not work?
– Raman Sailopal
Oct 2 '17 at 10:06




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




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




Does systemd show the agentinstall service running when it hasn't actually completed the start up?
– Raman Sailopal
Oct 2 '17 at 13:31










2 Answers
2






active

oldest

votes

















up vote
3
down vote













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.






share|improve this answer





























    up vote
    1
    down vote













    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.






    share|improve this answer






















    • 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







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395584%2finstruct-to-execute-an-unit-after-completing-another-unit-successfully%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    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.






    share|improve this answer


























      up vote
      3
      down vote













      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.






      share|improve this answer
























        up vote
        3
        down vote










        up vote
        3
        down vote









        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.






        share|improve this answer














        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 3 '17 at 15:37

























        answered Oct 2 '17 at 13:55









        thecarpy

        2,210824




        2,210824






















            up vote
            1
            down vote













            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.






            share|improve this answer






















            • 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














            up vote
            1
            down vote













            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.






            share|improve this answer






















            • 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












            up vote
            1
            down vote










            up vote
            1
            down vote









            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.






            share|improve this answer














            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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Oct 4 '17 at 10:11

























            answered Oct 3 '17 at 17:07









            sourcejedi

            19.7k42681




            19.7k42681











            • 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
















            • 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















            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




            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

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395584%2finstruct-to-execute-an-unit-after-completing-another-unit-successfully%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay