3

I have a system composed of about 15 services. They have no inter-dependencies (i.e. no service require another to start) and they notify systemd when there start-up is finished (i.e. Type=notify).

The problem is that if I start them all at the same time my system is overloaded and processes are killed due to systemd timeout.

What I want to do is "group" my services so they start one after the other is no particular order. Is this possible with systemd service file?

BTW: here is a template of my service file:

[Unit]
Description=Template service file
After=network.target

[Service]
Type=notify

User=1000
Group=1000

# Set the working directory and the binary to start
WorkingDirectory=/home/user/
ExecStart=/path/to/some/process

# The standard input and output are useless (i.e. unused by the process)
StandardInput=null
StandardOutput=null
# Disable the standard error because all logs are already saved in a specific directory
StandardError=null

# Send SIGTERM then SIGKILL after TimeoutStopSec seconds (default: 2)
KillMode=mixed
TimeoutStopSec=2

# Setup a start timeout
TimeoutStartSec=30

# On abnormal (i.e. non 0 exit code or killed by a signal) termination restart the process after RestartSec seconds (default: 5)
Restart=on-failure
RestartSec=5
# Authorise process restart only 5 times maximum in a 120 seconds interval
StartLimitBurst=5
StartLimitInterval=120

# Set watchdog timeout (default: 10)
WatchdogSec=10
NotifyAccess=main

# Set security options
NoNewPrivileges=yes

[Install]
WantedBy=custom.target

Thank you for your help

  • 1
    Use the After= to daisy chain the groupings... – RubberStamp Nov 11 '17 at 4:11
0

You can group the services into targets and add the dependencies using Requires,After and Before. Since you mentioned these services are mutually exclusive and also notify back to systemd, you may need to only add a After for each of the services based on the order you want them to run.

If you want to fully utilize your system, then you may consider running some services parallel so that the CPU bandwidth is fully utilized.

You can read on the systemd keywords here

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.