My systemd service kept timing out because of how long it would take to boot up also, so this fixed it for me:

  1. Edit your systemd file:

    • For modern versions of systemd: Run systemctl edit --full node.service (replace "node" with your service name).
      • This will create a system file at /etc/systemd/system/node.service.d/ that will override the system file at /usr/lib/systemd/system/node.service. This is the proper way to configure your system files. More information about how to use systemctl edit is here.
    • Directly editing system file: The system file for me is at /usr/lib/systemd/system/node.service. Replace "node" with your application name. However, it is not safe to directly edit files in /usr/lib/systemd/ (See comments)
  2. Use TimeoutStartSec, TimeoutStopSec or TimeoutSec (more info here) to specify how long the timeout should be for starting & stopping the process. Afterwards, this is how my systemd file looked:

    [Unit]
    Description=MyProject
    Documentation=man:node(1)
    After=rc-local.service
    
    [Service]
    WorkingDirectory=/home/myproject/GUIServer/Server/
    Environment="NODE_PATH=/usr/lib/node_modules"
    ExecStart=-/usr/bin/node Index.js
    Type=simple
    Restart=always
    KillMode=process
    TimeoutSec=900
    
    [Install]
    WantedBy=multi-user.target
    
    • You can also view the current Timeout status by running any of these (but you'll need to edit your service to make changes! See step 1). Confusingly, the associated properties have a "U" in their name for microseconds. See this Github issue for more information:
      • systemctl show node.service -p TimeoutStartUSec
      • systemctl show node.service -p TimeoutStopUSec
      • systemctl show node.service -p TimeoutUSec
  3. Next you'll need to reload the systemd with systemctl reload node.service

  4. Now try to start your service with systemctl start node.service

  5. If that didn't work, try to reboot systemctl with systemctl reboot

  6. If that didn't work, try using the --no-block option for systemctl like so: systemctl --no-block start node.service. This option is described here: "Do not synchronously wait for the requested operation to finish. If this is not specified, the job will be verified, enqueued and systemctl will wait until the unit's start-up is completed. By passing this argument, it is only verified and enqueued."

    • There is also the option to use systemctl mask instead of systemctl start. For more info see here.

Updates from Comments:

  • TimeoutSec=infinity: Instead of using "infinity" here, put a large amount of time instead, like TimeoutSec=900 (15 min). If the application takes "forever" to exit, then it's possible that it will block a reboot indefinitely. Credit @Alexis Wilke and @JCCyC
  • Instead of editing /usr/lib/systemd/system, try systemctl edit instead or edit /etc/systemd/system to override them instead. You should never edit service files in /usr/lib/. Credit @ryeager and @0xC0000022L

** Update from systemd source docs ** When specified "infinity" as a value to any of these timeout params, the timeout logic is disabled.

JobTimeoutSec=, JobRunningTimeoutSec=,TimeoutStartSec=,  TimeoutAbortSec=

The default is "infinity" (job timeouts disabled), except for device units where JobRunningTimeoutSec= defaults to DefaultTimeoutStartSec=.

Reference: enter link description here

Similarly this logic applies to service level and laid out clearly in URL below. Reference: enter link description here

Answer from Katie on Stack Exchange
Top answer
1 of 4
144

My systemd service kept timing out because of how long it would take to boot up also, so this fixed it for me:

  1. Edit your systemd file:

    • For modern versions of systemd: Run systemctl edit --full node.service (replace "node" with your service name).
      • This will create a system file at /etc/systemd/system/node.service.d/ that will override the system file at /usr/lib/systemd/system/node.service. This is the proper way to configure your system files. More information about how to use systemctl edit is here.
    • Directly editing system file: The system file for me is at /usr/lib/systemd/system/node.service. Replace "node" with your application name. However, it is not safe to directly edit files in /usr/lib/systemd/ (See comments)
  2. Use TimeoutStartSec, TimeoutStopSec or TimeoutSec (more info here) to specify how long the timeout should be for starting & stopping the process. Afterwards, this is how my systemd file looked:

    [Unit]
    Description=MyProject
    Documentation=man:node(1)
    After=rc-local.service
    
    [Service]
    WorkingDirectory=/home/myproject/GUIServer/Server/
    Environment="NODE_PATH=/usr/lib/node_modules"
    ExecStart=-/usr/bin/node Index.js
    Type=simple
    Restart=always
    KillMode=process
    TimeoutSec=900
    
    [Install]
    WantedBy=multi-user.target
    
    • You can also view the current Timeout status by running any of these (but you'll need to edit your service to make changes! See step 1). Confusingly, the associated properties have a "U" in their name for microseconds. See this Github issue for more information:
      • systemctl show node.service -p TimeoutStartUSec
      • systemctl show node.service -p TimeoutStopUSec
      • systemctl show node.service -p TimeoutUSec
  3. Next you'll need to reload the systemd with systemctl reload node.service

  4. Now try to start your service with systemctl start node.service

  5. If that didn't work, try to reboot systemctl with systemctl reboot

  6. If that didn't work, try using the --no-block option for systemctl like so: systemctl --no-block start node.service. This option is described here: "Do not synchronously wait for the requested operation to finish. If this is not specified, the job will be verified, enqueued and systemctl will wait until the unit's start-up is completed. By passing this argument, it is only verified and enqueued."

    • There is also the option to use systemctl mask instead of systemctl start. For more info see here.

Updates from Comments:

  • TimeoutSec=infinity: Instead of using "infinity" here, put a large amount of time instead, like TimeoutSec=900 (15 min). If the application takes "forever" to exit, then it's possible that it will block a reboot indefinitely. Credit @Alexis Wilke and @JCCyC
  • Instead of editing /usr/lib/systemd/system, try systemctl edit instead or edit /etc/systemd/system to override them instead. You should never edit service files in /usr/lib/. Credit @ryeager and @0xC0000022L

** Update from systemd source docs ** When specified "infinity" as a value to any of these timeout params, the timeout logic is disabled.

JobTimeoutSec=, JobRunningTimeoutSec=,TimeoutStartSec=,  TimeoutAbortSec=

The default is "infinity" (job timeouts disabled), except for device units where JobRunningTimeoutSec= defaults to DefaultTimeoutStartSec=.

Reference: enter link description here

Similarly this logic applies to service level and laid out clearly in URL below. Reference: enter link description here

2 of 4
14

Running systemctl show SERVICE_NAME.service -p TimeoutStopUSec I could at least see the timeout set by systemd to my service.

I changed the script to a regular unit file one in order for it work properly.

Discussions

centos7 - How to change the systemd timeout in centos - Stack Overflow
The default start timeout for systemd is 90s. I want to change it to 300s. So I change the DefaultTimeoutStartSec in /etc/systemd/system.conf # vi /etc/systemd/system.conf DefaultTimeoutStartSec=9... More on stackoverflow.com
🌐 stackoverflow.com
Put time limit on systemd-tmpfiles-setup by default
Component systemd-tmpfiles Is your feature request related to a problem? Please describe I have just waited 20 minutes for my computer to boot. Describe the solution you'd like There should be ... More on github.com
🌐 github.com
5
June 11, 2023
how do I configure an end time for systemd timers - Stack Overflow
I'm using CoreOS and SystemD timers to run my reports... I have certain monitoring reports that need to run every 3 hours for the next 12 hours, running on the half hour. That's pretty simple to More on stackoverflow.com
🌐 stackoverflow.com
How to set up a systemd service to retry 5 times on a cycle of 30 seconds - Stack Overflow
I want systemd to start a script and retry a maximum of 5 times, 30s apart. Reading the systemd.service manual and searching the Internet didn't produce any obvious answers. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/archlinux › systemd timeout question
r/archlinux on Reddit: Systemd Timeout Question
March 17, 2023 -

Hey all, I was reading up on the systemd timeout parameters in the system.conf file (/etc/systemd/system.conf) and was curious if anyone has any input as to problems that can arise if we set the #DefaultTimeoutStopSec=90s to something like 5 seconds rather than letting it stay at 90 seconds.

This is something I do from time to time on systems if I get an SDDM timeout when shutting down the PC and never have had a problem but wondered if it could cause an issue other than the journal not logging.

Top answer
1 of 3
4
This timer sets the max time after which systemd will SIGKILL services when a SIGTERM didn't succeed in time. This 90s default value is chosen very liberally, because systemd has to cover any kind of system where it's running on, and Arch doesn't modify upstream configs/defaults. The idea is to give services enough time to complete their termination, which can take some time depending on what needs to be done. Think of cleanup actions, storing user data, etc... On a regular desktop system, you're most likely not running any services which require a long termination time, so these 90s are way too long. You're much more likely to run into issues where the processes of a service didn't terminate because they got stuck (waiting for a resource, or due to a software bug, etc.). AFAIK, Fedora recently reduced the default value to 45s or so, because 90s is much more of an annoyance than it's actually useful for the vast majority of users and systems. If there's a service which actually requires a larger timeout value, then this can be overridden in the service itself, or the user can choose a longer default timeout value on their system themself. Instead of 5s, I'd set it to something like 10s or 15s, just to be sure that it doesn't harm any non-bugged-out services. Five or ten more seconds won't hurt you. https://www.freedesktop.org/software/systemd/man/systemd-system.conf.html#DefaultTimeoutStartSec= https://www.freedesktop.org/software/systemd/man/systemd.service.html#TimeoutStopSec=
2 of 3
3
The problems that can arise is data corruption/issues if you have a process that legitimately requires more time than 5 seconds to properly fix itself. You can override this setting on a per service basis, and in this particular case you should actually fix the issue by opting for sddm-git which has fixes for the long delay shutdown (I'm not sure why they haven't done a release in well over a year but I do hope they wrap something up soon)
🌐
Linux.org
linux.org › home › forums › general linux forums › general linux topics
Why startup timeout for service in systemd has no effect on it. | Linux.org
April 14, 2024 - This is how long the service can take to startup before it times out. Very few services will take 90 seconds to start up. If you're wanting a delay, before a service starts, there are at least two ways to do this. ... [Service] ExecStartPre=/bin/sleep 10 ExecStart=/path/to/your/service or the other way is a little more complicated. systemd-time-wait-sync.service: Follow these steps: This is for Debian/Ubuntu, but Redhat/Fedora is similar.
🌐
GitHub
github.com › systemd › systemd › issues › 31641
Put time limit on systemd-tmpfiles-setup by default · Issue #31641 · systemd/systemd
June 11, 2023 - There should be a limit on how long the job can run during boot. Let's say 3 minutes. ... It doesn't block the user for undetermined amount of time.
Published   Mar 05, 2024
Find elsewhere
Top answer
1 of 5
62

To have a service restart 3 times at 90 second intervals include the following lines in your systemd service file:

[Unit]
StartLimitIntervalSec=400
StartLimitBurst=3
[Service]
Restart=always
RestartSec=90

Before systemd-230 it was called just StartLimitInterval:

[Unit]
StartLimitInterval=400
StartLimitBurst=3
[Service]
Restart=always
RestartSec=90

This worked worked for me for a service that runs a script using Type=idle. Note that StartLimitIntervalSec must be greater than RestartSec * StartLimitBurst otherwise the service will be restarted indefinitely.

It took me some time with a lot of trial and error to work out how systemd uses these options, which suggests that systemd isn't as well documented as one would hope. These options effectively provide the retry cycle time and maximum retries that I was looking for.

References: https://manpages.debian.org/testing/systemd/systemd.unit.5.en.html for Unit section https://manpages.debian.org/testing/systemd/systemd.exec.5.en.html for Service section

2 of 5
25

Some years later and with systemd 232 it dosn't work anymore as described in the question and in the answers from 2016. Option name StartLimitIntervalSec and Sections have changed. Now it has to look like this example:

[Unit]
StartLimitBurst=5
StartLimitIntervalSec=33

[Service]
Restart=always
RestartSec=5
ExecStart=/bin/sleep 6

This will do 5 restarts in 30 sec (5*6) plus one restart in 33 sec. So we have 6 restarts in 33 sec. This exceeds the limit of 5 restarts in 33 sec. So restarts will stop at 5 counts after about 31 sec.

🌐
ArchWiki
wiki.archlinux.org › title › Systemd › Timers
systemd/Timers - ArchWiki
1 month ago - OnCalendar time specifications can be tested in order to verify their validity and to calculate the next time the condition would elapse when used on a timer unit file with the calendar option of the systemd-analyze utility. For example, one can use systemd-analyze calendar weekly or systemd-analyze calendar "Mon,Tue *-*-01..04 12:00:00". Add --iterations=N to ask for more iterations to be printed.
🌐
Reddit
reddit.com › r/linuxquestions › how do i change how long a particular systemd unit has to stop?
r/linuxquestions on Reddit: How do I change how long a particular systemd unit has to stop?
August 23, 2023 -

I have a Debian 12 virtual machine with GNOME desktop. No fancy mods, no weird config, all I have in it is what the installer gave me + Wine Staging + one Windows app. The VM starts up lightning fast, and *sometimes* it shuts down lightning fast too. However, more often than not, it will get hung up while trying to run systemd stop jobs to get the system into a safe-to-shutdown state.

There's three jobs that end up "hanging", however I believe only one of them (ssh-agent.service) is the problem, since once it times out after a minute and thirty seconds, the rest of the system quickly finishes up the shutdown process. However, this means that I have to wait for a minute and thirty seconds (plus a bit) before the VM will shut down.

When the systemd unit in question doesn't get hung up, it finishes its stop job almost instantly and the system shuts down fast. When it does get hung up, I know within about two seconds that it's hung up. Is there a way for me to change the timeout for this particular unit from 90 seconds to 3 seconds? I'm fine with changing files that the package manager might overwrite, since worst case scenario it will overwrite them and then I'll have one slow shutdown before I get it fixed again.

Top answer
1 of 1
1
You can do that in the configuration in /etc/systemd/system.conf Or by putting your custom configuration into a file in /etc/systemd/system.conf.d/ Linux Mint has a custom configuration there, called 50_linuxmint.conf which seems to address this problem. Here's what it says: # To override these values, create your own file in /etc/systemd/system.conf.d/60_custom.conf. # Reload configuration with "sudo systemctl daemon-reload" # Test with "systemctl show" [Manager] # Reduce shutdown timeout from 90s to 10s. # If you rely on important tasks to successfully finish during the shutdown sequence, set the timeout to something greater than 90s. DefaultTimeoutStopSec=10s # Rationale: # This is done for the following reasons: # - 90s is too long for users to wait (they think it's hanging indefinitely, and they eventually just use their power button) # - Cups, minidlna have made this a buggy mess for years now and there's no sign of improvement for the near future # - This is a workaround many people have used in Mint, Ubuntu, Arch, Fedora and many other distributions, although reducing the start # timeout is known to possibly affect the journal, no adverse effects were reported after reducing the stop timeout. # - For our audience (desktop users), this makes a lot of sense. It would be different for a server, or a machine which relies on shutdown # scripts to perform important tasks, but for most people this fixes a very important issue and is unlikely to create new ones.
🌐
Techiescamp
blog.techiescamp.com › systemd-timers
Systemd Timers: A Comprehensive Guide For Beginners
January 17, 2025 - If the restart limit has been reached, it will wait for 10 minutes before triggering another restart. After this period, the restart counter resets, allowing the service to try again. You can use the man command to know more about the timer configuration. ... Let's create a system timer that writes in a file every 2 minutes from Monday to Friday. Important Note: This is a demo example to help understand systemd ...
🌐
Red Hat
access.redhat.com › solutions › 1257953
How to set limits for services in RHEL and systemd - Red Hat Customer Portal
April 28, 2023 - For example, MemoryMax= is a more powerful (and working) replacement for LimitRSS=. Instead create a drop in file in /etc/systemd/system.conf.d/ and use the Default version of the limit:
🌐
Manjaro Linux
forum.manjaro.org › support
Reduce timeout for "stop job is running" systemd - Support - Manjaro Linux Forum
October 26, 2020 - I want to reduce the timeout for the following message when shutting down: “A stop job is running for … (1m 30s)” It is usually set to 90 seconds. I found this: https://unix.stackexchange.com/questions/328317/reducin…
🌐
freedesktop.org
freedesktop.org › software › systemd › man › latest › systemd.exec.html
systemd.exec
When not specified, the label that systemd is running under is used. This directive is ignored if SMACK is disabled. The value may be prefixed by "-", in which case all errors will be ignored. An empty value may be specified to unset previous assignments. This does not affect commands prefixed with "+". This option is only available for system services and is not supported for services running in per-user instances of the service manager. Added in version 218. LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=¶
🌐
Stack Overflow
stackoverflow.com › questions › 71144540 › what-is-the-limit-of-the-restartsec-time-in-systemd
linux - What is the limit of the RestartSec time in systemd? - Stack Overflow
Sign up to request clarification or add additional context in comments. ... Thanks for your answer. Where did you find that I can use "1ms" ? Can you share the link here? 2022-02-16T15:50:42.773Z+00:00 ... Yes of course, in this link I've found an example where a guy just try it: github.com/systemd/systemd/issues/13667 in this one you can read that the CPU range was from 1ms to 1000ms freedesktop.org/software/systemd/man/… I hope I was helpful 2022-02-17T09:32:31.81Z+00:00
🌐
Ravenhub Blog
blog.theravenhub.com › post › ht-limit-service-ressources-systemd
Limit CPU, Memory, and Other Resources for a Service Using systemd - Ravenhub Blog
January 25, 2025 - [Service] # CPU resource controls ...system/myservice.service.d/override.conf and then reload systemd with sudo systemctl daemon-reload to apply the changes....
🌐
GitHub
github.com › systemd › systemd › issues › 14496
By default, systemd-networkd-wait-online.service requires 2 m 14 sec, insteed 120 sec, and write "no limit", insteed 2 m 14 sec) · Issue #14496 · systemd/systemd
October 18, 2019 - By default, systemd-networkd-wait-online.service requires 2 m 14 sec, insteed 120 sec, and write "no limit", insteed 2 m 14 sec)#14496 ... cant-reproduceneeds-reporter-feedback ❓There's an unanswered question, the reporter needs to answerThere's an unanswered question, the reporter needs to answernetwork ... https://bugzilla.suse.com/show_bug.cgi?id=1159872 By default, systemd-networkd-wait-online.service requires the initialization of ALL network interfaces UNLIMITED time (timeout=0).
Author   13ilya-old