Instruct to execute an unit after completing another unit successfully
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
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
add a comment |Â
up vote
3
down vote
favorite
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
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
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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
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
systemd systemd-timer
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
add a comment |Â
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
add a comment |Â
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.
add a comment |Â
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.
Beaten to it. I was going to suggest the same. You might want to add to this answer that runningsystemctl
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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited Oct 3 '17 at 15:37
answered Oct 2 '17 at 13:55
thecarpy
2,210824
2,210824
add a comment |Â
add a comment |Â
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.
Beaten to it. I was going to suggest the same. You might want to add to this answer that runningsystemctl
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
add a comment |Â
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.
Beaten to it. I was going to suggest the same. You might want to add to this answer that runningsystemctl
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
add a comment |Â
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.
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.
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 runningsystemctl
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
add a comment |Â
Beaten to it. I was going to suggest the same. You might want to add to this answer that runningsystemctl
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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