5

I have a service file, which executes a shell script, and the script needs to be executed after docker is started. Here is what I tried, but the script is started without waiting for the docker.service:

[Unit]
Description=network configuration service 
Requires=docker.service
After=docker.service

[Service]
WorkingDirectory=/etc/systemd/system/
Type=oneshot
ExecStart=/bin/bash netset.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
  • Is your docker.service also part of the boot up? – ferdy Nov 3 '15 at 16:59
  • @ferdy yes, it's enabled, and after rebooting, systemctl status docker.service shows it's running. – Zhenxiao Hao Nov 3 '15 at 17:01
  • You may want to use Wants=docker.server" and remove Requires and After at all. – ferdy Nov 3 '15 at 17:04
  • @ferdy tried that, still didn't wait. – Zhenxiao Hao Nov 3 '15 at 17:09
  • 4
    @ZhenxiaoHao can you post your solution if you figured it out? – bonanza Jan 10 '17 at 11:30
0

This is the service unit configuration file I have that runs after the docker.service is up, and is also re-run whenever docker.service is restarted:

[Unit]
Description=Floating IP
After=docker.service
BindsTo=docker.service
ReloadPropagatedFrom=docker.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/floating-ip.sh
ExecReload=/usr/local/bin/floating-ip.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Documentation of the options used:

The script executed by this service adds an iptables SNAT rule to make Docker containers use the IP address on eth0:1 instead of the default on eth0, i.e. persisting the approach at https://serverfault.com/a/686107.

New contributor
RWD is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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