How to Add Delay to systemd During Booting

One of the things necessary to maintain a VLAN at home or small office is to automate the boot up sequence as much as possible. In case of, say, power outage, you would want the system to be able to boot up on its own, unless you opted Pis and others to turn on manually after a sudden failure.

What we are trying to achieve is rather simple. Let’s say the setup service2 relies on service1 — it needs to be started after the first service is up and running. Run the following command to edit a .service file for systemd:

sudo systemctl edit [service2]

Once the editor opens, there are two ways to tackle the problem, either specify prerequisite for the service, or simply add some delay. I would suggest using both for maintenance purposes:

[Unit]
Requires={your.service1.service}
After={your.service1.service}

[Service]
ExecStartPre=/bin/sleep {time}

To avoid confusions, I’ve used curly brackets for variables in this one. Please be mindful to update and only update the ones inside the {} brackets. {time} takes time in seconds.

Leave a comment