Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start systemd service after specific service? [closed]

People also ask

How do I delay start of systemd services?

Delay the start of the systemd service at boot. Inspect service that you want to delay at boot. redis-server. service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.

What is ExecStop systemd?

The ExecStop setting is optional and is used to communicate with the service for a clean termination. The process specified by ExecStop will run in case the service crashes.

What is ExecStart?

ExecStart= Commands with their arguments that are executed when this service is started. The value is split into zero or more command lines according to the rules described below (see section "Command Lines" below). Unless Type= is oneshot , exactly one command must be given.


In the .service file under the [Unit] section:

[Unit]
Description=My Website
After=syslog.target network.target mongodb.service

The important part is the mongodb.service

The manpage describes it however due to formatting it's not as clear on first sight

systemd.unit - well formatted

systemd.unit - not so well formatted


After= dependency is only effective when service including After= and service included by After= are both scheduled to start as part of your boot up.

Ex:

a.service
[Unit]
After=b.service

This way, if both a.service and b.service are enabled, then systemd will order b.service after a.service.

If I am not misunderstanding, what you are asking is how to start b.service when a.service starts even though b.service is not enabled.

The directive for this is Wants= or Requires= under [Unit].

website.service
[Unit]
Wants=mongodb.service
After=mongodb.service

The difference between Wants= and Requires= is that with Requires=, a failure to start b.service will cause the startup of a.service to fail, whereas with Wants=, a.service will start even if b.service fails. This is explained in detail on the man page of .unit.